pg_dump 忽略表顺序?
我最近一直在使用 PostgreSQL,并且无法理解如何备份和恢复单个表。
我使用 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...
看起来转储文件不包含自动递增列的序列。我如何让它包含它?
I have been playing around with PostgreSQL lately, and am having trouble understanding how to backup and restore a single table.
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:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅按表转储 - 将仅转储表。除了表之外,您还需要单独转储序列。
如果您不知道您的序列,您可以在 psql 中使用
\d yourtable
列出它。您将在序列所在的行中看到如下所示的内容:nextval('yourtable_id_seq'::regclass')
然后从命令行中,
pgdump -t yourtable_id_seq
< a href="http://www.postgresql.org/docs/9.0/static/app-pgdump.html" rel="noreferrer">http://www.postgresql.org/docs/9.0/static/app- pgdump.html
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 yourtable
in psql. You will see something in the row your sequence is on that looks like :nextval('yourtable_id_seq'::regclass')
Then from the command line,
pgdump -t yourtable_id_seq
http://www.postgresql.org/docs/9.0/static/app-pgdump.html