pg_dump 忽略表顺序?

发布于 2024-10-10 06:01:58 字数 443 浏览 6 评论 0原文

我最近一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和影子一齐双人舞 2024-10-17 06:01:58

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

如果您不知道您的序列,您可以在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文