2016-11-22 241 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)。