尝试恢复具有约束的表格时,PG_Restore会引发错误
我尝试将桌子从生产环境转换为开发环境。但是,在倾倒和还原该表时,使用以下命令:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有看到倾倒/还原特定表。您正在倾倒/还原整个数据库。
如果您想重新创建生产数据库作为开发数据库,则可以:
-C
- CLEAN
Willdrop drop db_name
通过连接到数据库postgres
进行drop/create db_name
,然后连接到db_name
从头开始。这是清理流行并以一致状态开始的最佳方法。
更新
使用
pg_dump
命令更新您的问题,因此您正在做什么。如果您想查看特定表是否具有依赖关系,则在原始数据库中使用
psql
和do\ d the_table
以查看依赖性涉及的依赖项是。如果您告诉pg_dump
要倾倒单个表,它将仅转储该表。它不会遵循依赖关系并将其丢弃。这取决于您。调查使用模式管理工具进行更改/迁移。我使用 sqitch 为此。
I am not seeing dumping/restoring a particular table. You are dumping/restoring the entire database.
If you want recreate the production database as a dev one then do:
The
-C
with--clean
willDROP DATABASE db_name
and then rebuild it from scratch by connecting to the databasepostgres
to do theDROP/CREATE db_name
and then connect todb_name
to load the rest of the objects.This is the best way to clean out cruft and start at a consistent state.
UPDATE
Update your question with the
pg_dump
command so it is evident what you are doing.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 tellpg_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.Look into using a schema management tool to do your changes/migrations. I use Sqitch for this.
您在开发数据库上有一个表,该表具有依赖性的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.