Thread: Problems with restoring data (using pg_restore)

Problems with restoring data (using pg_restore)

From
Christian Andersen
Date:
Hi guys,

I have a script exporting a series of schemas from one database (test) to another database (production). I´ve noticed
thatsome of the tables are not correctly updated resulting in old datas in the productiondb.  I´ve looked in the
logfilesand noticed the following: 

CMD: E:\spatialsuite\app\postgres\8.4.6\pgsql\bin\pg_re store -c -h localhost -p 5432 -U k175 -d k175
E:\spatialsuite\sites\webgis\import\db\k175_test.rk_grundkort.dmp 
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3344; 2606 1411043 CONSTRAINT husnr_pk k175_test
pg_restore: [archiver (db)] could not execute query: ERROR: constraint "husnr_pk" of relation "husnr" does not exist
Command was: ALTER TABLE ONLY rk_grundkort.husnr DROP CONSTRAINT husnr_pk;
pg_restore: [archiver (db)] Error from TOC entry 2975; 1259 1411038 TABLE husnr k175_test
pg_restore: [archiver (db)] could not execute query: ERROR: cannot drop table husnr because other objects depend on it
DETAIL: view husnr_view depends on table husnr
HINT: Use DROP ... CASCADE to drop the dependent objects too.
Command was: DROP TABLE rk_grundkort.husnr;
pg_restore: [archiver (db)] Error from TOC entry 10; 2615 25698 SCHEMA rk_grundkort k175_test
pg_restore: [archiver (db)] could not execute query: ERROR: cannot drop schema rk_grundkort because other objects
dependon it 
DETAIL: table husnr depends on schema rk_grundkort
view husnr_view depends on schema rk_grundkort
HINT: Use DROP ... CASCADE to drop the dependent objects too.
Command was: DROP SCHEMA rk_grundkort;
pg_restore: [archiver (db)] could not execute query: ERROR: schema "rk_grundkort" already exists
Command was: CREATE SCHEMA rk_grundkort;
pg_restore: [archiver (db)] Error from TOC entry 2975; 1259 1411038 TABLE husnr k175_test
pg_restore: [archiver (db)] could not execute query: ERROR: relation "husnr" already exists
Command was: CREATE TABLE husnr (
ogc_fid integer NOT NULL,
wkb_geometry public.geometry,
adr_id character(11),
komnr int...
pg_restore: [archiver (db)] Error from TOC entry 3355; 0 1411038 TABLE DATA husnr k175_test
pg_restore: [archiver (db)] COPY failed: ERROR: duplicate key value violates unique constraint "husnr_pkey"
CONTEXT: COPY husnr, line 1: "1    0101000020E8640000295C8F0277E0254191ED7C27178F5741    1750702333 175    Rødovre
Kommune..." 
pg_restore: [archiver (db)] Error from TOC entry 3344; 2606 1411043 CONSTRAINT husnr_pk k175_test
pg_restore: [archiver (db)] could not execute query: ERROR: multiple primary keys for table "husnr" are not allowed
Command was: ALTER TABLE ONLY husnr
ADD CONSTRAINT husnr_pk PRIMARY KEY (ogc_fid);
WARNING: errors ignored on restore: 7

The pg_dump command is:

pg_dump -h localhost -p 5432 -U k175_test -Ft -v -c -x -O -n rk_grundkort -f
E:\spatialsuite\sites\test-webgis\export2webgis\db\k175_test.rk_grundkort.dmpk175_test 

I´ve an idea that the problem could be related to the "-n" option.

Could someone guide me in the right direction on how to solve this problem?

Thanks

Christian