16

我最近一直在玩 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...

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

4

1 回答 1

24

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

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

然后从命令行,pgdump -t yourtable_id_seq

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

于 2011-01-06T02:19:06.103 回答