2016-11-22 76 views
0

我想导入一个.sql数据库转储到我的postgres 9.6.1。我已经尝试了命令行以及Postico GUI,但是在导入时会出现大量错误(如数千行错误)。Postgres SQL转储许多语法和权限错误导入

SQL转储来自运行postgres 9.4.5的同事,并且SQL看起来有效。 4.2.1(基于苹果公司

在x86_64-苹果达尔文的PostgreSQL 9.6.1,通过 的i686-苹果darwin11-LLVM-GCC-4.2(GCC)编译:

我的Postgres版本。 构建5658)(LLVM构建2336.11.00),64位

我已经试过以下进口:

psql -U postgres dbname < ~/Desktop/dbname_local_db_20161122.sql

然后登录并试图:

psql -U postgres dbname

dbname=# \i ~/Desktop/dbname_local_db_20161122.sql

错误:(还有比这样更多)就像我说的

Password for user postgres: 
SET 
SET 
SET 
SET 
SET 
SET 
CREATE EXTENSION 
COMMENT 
ERROR: schema "public" does not exist 
ERROR: extension "citext" does not exist 
ERROR: schema "public" does not exist 
ERROR: extension "pg_trgm" does not exist 
SET 
ERROR: function "add_session_metric" already exists with same argument types 
ERROR: role "myrole" does not exist 
ERROR: function "session_metrics_partition_creation" already exists with same argument types 
ERROR: role "myrole" does not exist 
ERROR: function "session_metrics_partition_function" already exists with same argument types 
ERROR: role "myrole" does not exist 
SET 
SET 
ERROR: permission denied to create "pg_catalog.messages" 
DETAIL: System catalog modifications are currently disallowed. 
ERROR: relation "messages" does not exist 
ERROR: permission denied to create "pg_catalog.Message_id_seq" 
DETAIL: System catalog modifications are currently disallowed. 
ERROR: relation "Message_id_seq" does not exist 
ERROR: relation "Message_id_seq" does not exist 
ERROR: permission denied to create "pg_catalog.sessions_users" 

invalid command \N 
invalid command \N 
invalid command \N 
invalid command \N 
invalid command \N 
invalid command \. 
ERROR: syntax error at or near "2" 
LINE 1: 2 hello 3 1 2015-11-12 09:25:14.646-07 2015-11-12 09:25:14.64... 
ERROR: syntax error at or near "1" 
LINE 1: 1 
     ^
ERROR: relation "external_session_info_sessions" does not exist 
invalid command \. 
ERROR: syntax error at or near "2528" 
LINE 1: 2528 1 
     ^
invalid command \. 
ERROR: relation "feedback_id_seq" does not exist 
LINE 1: SELECT pg_catalog.setval('feedback_id_seq', 1, false); 

,SQL文件长相有效。我检查了从9.4.59.6.1的兼容性问题,但没有看到任何问题。

我确实看到PERMISSION DENIED但我运行命令为具有超级用户权限的用户postgres

enter image description here

回答

0

首先,推荐的方法是使用pg_dump从更高的(目标)数据库版本创建转储,因为该版本的pg_dump知道自从发生不兼容的更改并且可以创建将正确恢复的转储。

如果您将转储恢复到已具有相同名称的对象的数据库中,则某些错误是正常的;通常这是一个迹象表明实际上应该使用pg_dump -C创建转储以包含CREATE DATABASE声明。

但是,您的SQL脚本似乎严重混乱,我怀疑它是一个9.4.5数据库的未经修改的转储。

pg_dump将永远不会转储pg_catalog中的任何对象。此架构只能包含未包含在转储中的系统对象(它们由CREATE DATABASE创建),并且如您所见,即使超级用户也不能在该架构中创建对象(除非allow_system_table_modson,它真的不应该) t be)。