有时会出现错误转储/还原PostgreSQL

有时会出现错误转储/还原PostgreSQL,postgresql,pg-dump,pg-restore,Postgresql,Pg Dump,Pg Restore,有时在执行数据库转储和恢复时,会出现以下错误 pg_restore: [archiver (db)] Error during TOC PROCESSING: pg_restore: [archiver (db)] Error in the item TOC 3569; 2606 4196743 CONSTRAINT uc_xtb_ruleset_key elinex pg_restore: [archiver (db)] could not execute query: ERROR: crea

有时在执行数据库转储和恢复时,会出现以下错误

pg_restore: [archiver (db)] Error during TOC PROCESSING:
pg_restore: [archiver (db)] Error in the item TOC 3569; 2606 4196743 CONSTRAINT uc_xtb_ruleset_key elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "uc_xtb_ruleset_key" failed
DETAILS: The key (name) = (FEL.DATI_RIEPILOGO) is duplicated.
    The command was: ALTER TABLE ONLY xtb_rulesets
    ADD CONSTRAINT uc_xtb_ruleset_key UNIQUE (name); pg_restore: [archiver (db)] Error in the item TOC 3425; 2606 4196747 CONSTRAINT uq_currency_iso elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "uq_currency_iso" failed
DETAILS: The key (iso_code) = (SBD) is duplicated.
    The command was: ALTER TABLE ONLY xtb_currencies
    ADD CONSTRAINT uq_currency_iso UNIQUE (iso_code); pg_restore: [archiver (db)] Error in the item TOC 3418; 2606 4196751 CONSTRAINT xtb_countries_pkey elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "xtb_countries_pkey" failed
DETAILS: The key (uic_code) = (075) is duplicated.
    The command was: ALTER TABLE ONLY xtb_countries
    ADD CONSTRAINT xtb_countries_pkey PRIMARY KEY (uic_code); pg_restore: [archiver (db)] Error in the item TOC 3420; 2606 4196753 CONSTRAINT xtb_cultures_pkey elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "xtb_cultures_pkey" failed
DETAILS: The key (culture_id) = (IT) is duplicated.
    The command was: ALTER TABLE ONLY xtb_cultures
    ADD CONSTRAINT xtb_cultures_pkey PRIMARY KEY (culture_id); pg_restore: [archiver (db)] Error in the entry TOC 3427; 2606 4196755 CONSTRAINT xtb_currencies_pkey elinex
pg_restore: [archiver (db)] could not execute query: ERROR: creation of the unique index "xtb_currencies_pkey" failed
DETAILS: The key (uic_code) = (206) is duplicated.
    The command was: ALTER TABLE ONLY xtb_currencies
    ADD CONSTRAINT xtb_currencies_pkey PRIMARY KEY (uic_code); pg_restore: [archiver (db)] Error in item TOC 3447; 2606 4196773 CONSTRAINT xtb_email_resources_pkey elinex
[.....]
pg_restore: [archiver (db)] could not execute query: ERROR: there is no unique constraint that matches the keys given for the referenced table "xtb_cultures"
    The command was: ALTER TABLE ONLY xtb_profiles
    ADD CONSTRAINT fk_profile_to_culture FOREIGN KEY (culture_id) REFERENCES xtb_cultures (cult ...
pg_restore: [archiver (db)] Error in the item TOC 3709; 2606 4196955 FK CONSTRAINT fk_users_to_culture elinex
pg_restore: [archiver (db)] could not execute query: ERROR: there is no unique constraint that matches the keys given for the referenced table "xtb_cultures"
    The command was: ALTER TABLE ONLY xtb_users
    ADD CONSTRAINT fk_users_to_culture FOREIGN KEY (culture_id) REFERENCES xtb_cultures (culture_i ...
pg_restore: [archiver (db)] Error in the item TOC 3680; 2606 4197020 FK CONSTRAINT fk_xtb_f_role_2_role elinex
pg_restore: [archiver (db)] could not execute query: ERROR: there is no unique constraint that matches the keys given for the referenced table "xtb_roles"
    The command was: ALTER TABLE ONLY xtb_function_roles
    ADD CONSTRAINT fk_xtb_f_role_2_role FOREIGN KEY (role_id) REFERENCES xtb_roles (role _...
pg_restore: [archiver (db)] Error in the item TOC 3679; 2606 4197030 FK CONSTRAINT fk_xtb_file_ty_2_folder elinex
pg_restore: [archiver (db)] could not execute query: ERROR: there is no unique constraint that matches the keys indicated for the referenced table "xtb_folders"
    The command was: ALTER TABLE ONLY xtb_file_types
    ADD CONSTRAINT fk_xtb_file_ty_2_folder FOREIGN KEY (folder_id) REFERENCES xtb_folders (fo ...
[...]
    WARNING: error ignored during recovery: 24
我从postgreSQL 9.5.6进行转储,并在postgreSQL 9.6.11上恢复转储

[xxxxx@xxxx ~]$ pg_dump -V
pg_dump (PostgreSQL) 9.5.6

[xxxx@xxxx ~]# pg_restore -V
pg_restore (PostgreSQL) 9.6.11
下面执行转储命令和恢复命令

倾倒

恢复

pg_restore --clean --if-exists --no-owner -h localhost -p 5432 -d DATABASE_NAME -U user DATABASE_DUMP.dmp

您能帮我吗?

很可能原始数据库已损坏。要验证这一点,请尝试在原始数据库上重新索引这些索引之一


要解决此问题,请删除表中的重复行,然后
REINDEX

是否将数据还原到空数据库中?是的,我删除并重新创建数据库,然后在新数据库中还原转储。我重新索引了所有受错误影响的索引,但错误仍然存在于相同的索引中。难以置信。将
启用索引扫描
启用位图扫描
启用索引扫描
设置为
关闭
,并检查原始数据库中是否存在这些重复键。另一种解释是,您还原到的数据库中已有数据。
pg_restore --clean --if-exists --no-owner -h localhost -p 5432 -d DATABASE_NAME -U user DATABASE_DUMP.dmp