我试图将数据库从虚拟机(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命令中的选项?
非常感谢你!
正如Valdemar所说,AS整数是在10.x中引入的,并不是向后兼容的。如果您能够通过命令行界面(pg_dump)重新生成转储,以下是我建议的步骤:
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