postgres sql dump import

时间:2016-11-22 17:01:08

标签: postgresql import

我正在尝试将.sql数据库转储导入到我的postgres 9.6.1中。我在命令行以及Postico GUI上尝试过但在导入时遇到了大量错误(如数千行错误)。

SQL转储来自运行postgres 9.4.5的同事,SQL看起来有效。

我的Postgres版本:

  

在x86_64-apple-darwin上的PostgreSQL 9.6.1,由。编译   i686-apple-darwin11-llvm-gcc-4.2(GCC)4.2.1(基于Apple Inc.)   build 5658)(LLVM build 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

1 个答案:

答案 0 :(得分:0)

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

如果将转储还原到已包含具有相同名称的对象的数据库,则某些错误是正常的;通常这表示实际上应该使用pg_dump -C创建转储以包含CREATE DATABASE语句。

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

pg_dump永远不会转储pg_catalog中的任何对象。此模式只能包含未包含在转储中的系统对象(它们由CREATE DATABASE创建),如您所见,即使超级用户也不能在该模式中创建对象(除非allow_system_table_modson,它实际上不应该是。)