pg_dump ignoring table sequence?

核能气质少年 提交于 2019-12-21 03:43:09

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/4609972/pg-dump-ignoring-table-sequence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!