0

Today I accidentally restored a pg_dumpall file to the database that that dumpall was generated from. This restore has caused a ton of duplicates of certain ID's and such.

This is a complex production database and it hasn't corrupted the entire database but its really affecting the ability to change things on the site that uses it. Now I know I could just cut my losses and reset the database to the original pg_dumpall (it was as recent as last night) but that would mean that a full day's work/posting on the site that uses the database would be lost.

Is there anything I can do to remedy this situation?

4

1 回答 1

1

没有主键,这很难。使用主键,这不可能发生。你能做的最好的事情是,恕我直言:

  1. 重命名所有模式(例如schema-> bad_schema
  2. 重新导入昨晚的转储(当然不删除数据库)
  3. 为所有新表添加 PK 约束(这需要手动工作!)
  4. for all schemas.tables:添加行 from bad_schema.tableXXXtoschema.tableXXX 如果它们还不存在(这可能需要(非唯一)索引bad_schema.XXX,对应于预期的 FK)
  5. (可选)将序列调整为相应列中的现有最大值(值)。

如果您不了解上述内容(或者工作量太大),请承担您的损失,并安装昨天的备份。您可以先重命名损坏的数据库(或重命名模式),然后再尝试从中提取新记录。


摘要:确实意识到每个(部分)解决方案都以某种方式需要主键。没有PK的表是脆弱的,毫无意义的。

于 2016-06-09T20:32:22.233 回答