Django + Postgres:尝试转储和恢复数据库,但看到ERROR:所有序列表都不存在关系“* _id_seq”

问题描述 投票:1回答:1

我试图将数据库从虚拟机(docker-machine)移动到azure上的数据库服务器。我首先使用以下命令将数据库转储到本地文件:

pg_dump -h <virtual-machine-ip> -U <username> postgres > dump.sql

然后我尝试在新服务器上恢复它:

psql -h <database-server-ip> -U <username> -d <new_database_name> -f dump.sql

这会产生很多错误(例如下面的例子):

SET
SET
SET
SET
SET
SET
SET
SET
COMMENT
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
psql:dump.sql:66: ERROR:  syntax error at or near "AS"
LINE 2:     AS integer
            ^
psql:dump.sql:69: ERROR:  relation "auth_group_id_seq" does not exist
psql:dump.sql:75: ERROR:  relation "auth_group_id_seq" does not exist
CREATE TABLE
ALTER TABLE
psql:dump.sql:101: ERROR:  syntax error at or near "AS"
LINE 2:     AS integer
            ^
psql:dump.sql:104: ERROR:  relation "auth_group_permissions_id_seq" does not exist
psql:dump.sql:110: ERROR:  relation "auth_group_permissions_id_seq" does not exist
CREATE TABLE
ALTER TABLE
psql:dump.sql:137: ERROR:  syntax error at or near "AS"
LINE 2:     AS integer
            ^
psql:dump.sql:140: ERROR:  relation "auth_permission_id_seq" does not exist
psql:dump.sql:146: ERROR:  relation "auth_permission_id_seq" does not exist
CREATE TABLE
ALTER TABLE
psql:dump.sql:175: ERROR:  syntax error at or near "AS"
LINE 2:     AS integer
            ^
psql:dump.sql:178: ERROR:  relation "clients_client_id_seq" does not exist
psql:dump.sql:184: ERROR:  relation "clients_client_id_seq" does not exist
CREATE TABLE
ALTER TABLE
psql:dump.sql:214: ERROR:  syntax error at or near "AS"
LINE 2:     AS integer

我试过在pg_dump上阅读文档,但无论我做什么,我都得到相同的结果......

知道这里发生了什么吗?我是否错过了一些本应包含在dump命令中的选项?

非常感谢你!

django postgresql
1个回答
2
投票

正如Valdemar所说,AS整数是在10.x中引入的,并不是向后兼容的。如果您能够通过命令行界面(pg_dump)重新生成转储,以下是我建议的步骤:

  • 使用-Fp(或--format = plain)以纯文本格式转储数据库
  • 编辑生成的文件以删除AS整数语句
  • 在目标数据库中导入更改的文件

TL; DR

pg_dump -h <virtual-machine-ip> -U <username> -Fp postgres > dump.sql
sed 's/AS integer//' dump.sql > altered_dump.sql
psql -h <database-server-ip> -U <username> -d <new_database_name> -f altered_dump.sql
© www.soinside.com 2019 - 2024. All rights reserved.