尝试恢复具有约束的表格时,PG_Restore会引发错误

发布于 2025-02-06 18:44:48 字数 564 浏览 0 评论 0原文

我尝试将桌子从生产环境转换为开发环境。但是,在倾倒和还原该表时,使用以下命令:

pg_restore -no所有者-NO-ACL-CLEAN - -CLEAN - if-exists -d database dump_file.dump

我得到错误指出除非使用级联之类的东西(即丢弃所有取决于该表的表),否则我无法丢下该表。有没有办法确定要丢弃的表?在pg_dump命令中,是否有一种方法可以转储我要转储和所有相关表的命令?

这是提出的错误:

pg_restore:处理TOC时: pg_restore:摘自TOC条目4066; 2606 30526约束表1 pkey用户 pg_restore:错误:无法执行查询:错误:无法在表public.table上删除约束pkey,因为其他对象取决于它 详细信息:public.dag上的约束id_fkey取决于index public.pkey table public.dag上的约束id_fkey取决于index public.pkey 提示:使用滴...级联也掉落依赖的对象...

I try dumping tables from a production environment to a dev one. However, when dumping and restoring this table, using the following command:

pg_restore --no-owner --no-acl --clean --if-exists -d database dump_file.dump

I get an error stating that I can't drop that table unless I use something like CASCADE (i.e. dropping all other tables that depend on that one). Is there a way to determine the tables to be dropped? is there a way of maybe state in the pg_dump command to dump the table I'm looking to dump and all related tables ?

Here's the error raised:

pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 4066; 2606 30526 CONSTRAINT table1 pkey user
pg_restore: error: could not execute query: ERROR: cannot drop constraint pkey on table public.table1 because other objects depend on it
DETAIL: constraint id_fkey on table public.dag depends on index public.pkey
constraint id_fkey on table public.dag depends on index public.pkey
HINT: Use DROP ... CASCADE to drop the dependent objects too...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为你拒绝所有暧昧 2025-02-13 18:44:48
  1. 我没有看到倾倒/还原特定表。您正在倾倒/还原整个数据库。

  2. 如果您想重新创建生产数据库作为开发数据库,​​则可以:

pg_restore -C --no-owner --no-acl --clean --if-exists -d postgres dump_file.dump

-C - CLEAN Will drop drop db_name通过连接到数据库postgres进行drop/create db_name,然后连接到db_name从头开始。

这是清理流行并以一致状态开始的最佳方法。

更新

  1. 使用pg_dump命令更新您的问题,因此您正在做什么。

  2. 如果您想查看特定表是否具有依赖关系,则在原始数据库中使用psql和do \ d the_table以查看依赖性涉及的依赖项是。如果您告诉pg_dump要倾倒单个表,它将仅转储该表。它不会遵循依赖关系并将其丢弃。这取决于您。

  3. 调查使用模式管理工具进行更改/迁移。我使用 sqitch 为此。

  1. I am not seeing dumping/restoring a particular table. You are dumping/restoring the entire database.

  2. If you want recreate the production database as a dev one then do:

pg_restore -C --no-owner --no-acl --clean --if-exists -d postgres dump_file.dump

The -C with --clean will DROP DATABASE db_name and then rebuild it from scratch by connecting to the database postgres to do the DROP/CREATE db_name and then connect to db_name to load the rest of the objects.

This is the best way to clean out cruft and start at a consistent state.

UPDATE

  1. Update your question with the pg_dump command so it is evident what you are doing.

  2. If you want to see whether a particular table has dependencies, in the original database use psql and do \d the_table to see what the dependencies to and from the table are. If you tell pg_dump to dump a single table it will dump just that table. It will not follow dependencies and dump those also. That is up to you to do.

  3. Look into using a schema management tool to do your changes/migrations. I use Sqitch for this.

離殇 2025-02-13 18:44:48

您在开发数据库上有一个表,该表具有依赖性的pkey,因此在还原之前无法删除。这是正确的行为。

You have a table on the dev database that has a pkey that is dependent and therefore can not be dropped before the restore. This is proper behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文