postgresql pg_dump 忽略表序列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4609972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:28:48  来源:igfitidea点击:

pg_dump ignoring table sequence?

postgresqlpg-dumppg-restore

提问by demersus

I have been playing around with PostgreSQL lately, and am having trouble understanding how to backup and restore a single table.

我最近一直在玩 PostgreSQL,但在理解如何备份和恢复单个表时遇到了麻烦。

I used pgadmin3 to backup a single table in my database, in order to copy it to a different server. When I try to do a pg_restore on the file, I get error messages saying that the sequence does not exist:

我使用 pgadmin3 备份数据库中的单个表,以便将其复制到不同的服务器。当我尝试对文件执行 pg_restore 时,我收到错误消息,指出该序列不存在:

pg_restore: [archiver (db)] could not execute query: ERROR:  relation "businesses_id_seq" does not exist
    Command was: 
CREATE TABLE businesses (
    id integer DEFAULT nextval('businesses_id_seq'::regclass) NOT NULL,
    name character varyin...

It looks like the dump file did not include the sequence for my auto incrementing column. How do I get it to include that?

看起来转储文件不包含我的自动递增列的序列。我如何让它包含它?

回答by nate c

dumping by table only - will dump only the table. You need to dump the sequence separately in addition to the table.

仅按表转储 - 将仅转储表。除了表之外,您还需要单独转储序列。

If you dont know your sequence you can list it with \d yourtablein psql. You will see something in the row your sequence is on that looks like : nextval('yourtable_id_seq'::regclass')

如果你不知道你的序列,你可以\d yourtable在 psql 中列出它。您将在序列所在的行中看到如下所示的内容:nextval('yourtable_id_seq'::regclass')

Then from the command line, pgdump -t yourtable_id_seq

然后从命令行, pgdump -t yourtable_id_seq

http://www.postgresql.org/docs/9.0/static/app-pgdump.html

http://www.postgresql.org/docs/9.0/static/app-pgdump.html