2017-05-11 85 views
1

大師 我需要備份和恢復一個PostgreSQL數據庫。 我的操作系統版本是Ubuntu的14.04 64位,而PostgreSQL是:如何備份和恢復一個PostgreSQL數據庫?

gid: ~/works $ pg_config --version 
PostgreSQL 9.3.15 

我用pg_dump的備份數據庫:

gid: ~/works $ pg_dump -U db_name_user -F t db_name > db_name.tar 

我嘗試使用pg_restore的恢復數據庫並獲取失敗:

gid: ~/works $ pg_restore -U db_name_user -F t -d db_name db_name.tar 

pg_restore: [archiver (db)] Error while PROCESSING TOC: 
pg_restore: [archiver (db)] Error from TOC entry 3621; 0 0 COMMENT EXTENSION plpgsql 
pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of extension plpgsql 
Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; 

pg_restore: WARNING: no privileges could be revoked for "public" 
pg_restore: WARNING: no privileges could be revoked for "public" 
pg_restore: WARNING: no privileges were granted for "public" 
pg_restore: WARNING: no privileges were granted for "public" 
WARNING: errors ignored on restore: 1 

我不知道這是什麼意思? 如何備份和恢復PostgreSQL數據庫?

非常感謝。

------------------------ update 1 -------------------- ----

即使我補充說:「--no所有者」選項時的pg_dump和pg_restore的,我還是得到了同樣的錯誤消息:

gid:~/works $ pg_restore -U db_name_user -O -Ft -d db_name db_name.tar 
pg_restore: [archiver (db)] Error while PROCESSING TOC: 
pg_restore: [archiver (db)] Error from TOC entry 3621; 0 0 COMMENT EXTENSION plpgsql 
pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of extension plpgsql 
    Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; 

pg_restore: WARNING: no privileges could be revoked for "public" 
pg_restore: WARNING: no privileges could be revoked for "public" 
pg_restore: WARNING: no privileges were granted for "public" 
pg_restore: WARNING: no privileges were granted for "public" 
WARNING: errors ignored on restore: 1 
+1

您可以放心地忽略此錯誤。缺乏對plpgsql的評論不會影響你的代碼。如果你想以超級用戶的身份運行pg_restore,你不應該看到這樣的警告 –

回答

0

您可以發表評論的語言忽略錯誤 - 它不會影響你的代碼。 也可以考慮不使用所有者來避免這種警告。但請記住,所有者將成爲您在pg_restore上連接的用戶,而不是原來的用戶。請閱讀文檔: https://www.postgresql.org/docs/current/static/app-pgrestore.html

-O

--no-owner Do not output commands to set ownership of objects to match the original database. By default, pg_restore issues ALTER OWNER or SET SESSION AUTHORIZATION statements to set ownership of created schema elements. These statements will fail unless the initial connection to the database is made by a superuser (or the same user that owns all of the objects in the script). With -O, any user name can be used for the initial connection, and this user will own all the created objects.

+1

你好, 感謝您的信息。 我用pg_dump和pg_restore測試了你的選項「--no-owner」,但是我仍然得到了相同的錯誤: gid:〜/ works $ pg_restore -U db_name_user -O -Ft -d db_name db_name.tar pg_restore: [存檔器(db)]處理目錄時出錯: pg_restore:[存檔器(db)]來自TOC條目3621的錯誤; 0 0 COMMENT EXTENSION plpgsql pg_restore:[archiver(db)]無法執行查詢:ERROR:必須是擴展的所有者plpgsql 命令是:COMMENT ON EXTENSION plpgsql是'PL/pgSQL過程語言'; – zhengfish

+0

當然 - 不用客氣 –