【发布时间】:2018-02-19 16:01:31
【问题描述】:
我正在尝试将数据库从虚拟机 (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 上的文档,但无论我做什么,我都会得到相同的结果...
知道这里发生了什么吗?我是否错过了一些应该包含在转储命令中的选项?
非常感谢!
【问题讨论】:
-
两个问题。 (1) 您遇到的第一个错误是什么? (2) 这在本地版本的数据库上是否有效?
-
(1) 我用输出的开头更新了问题,(2) 你是什么意思?
-
在引用序列的错误之前有一个语法错误。您的 PostgreSQL 的 docker 版本与 Azure 上的版本之间可能存在一些差异。可能是docker版本更新。显而易见的下一步是确认您可以在本地转储和恢复。如果这样可行,那么您需要找出 Azure 安装不喜欢的转储文件中第 66 行或附近的内容。
-
我明白了。我会尝试在本地转储和恢复,看看它是否有效
-
是以下语句导致错误:
CREATE SEQUENCE auth_group_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
标签: django postgresql