簡體   English   中英

Postgres 教程:pg_restore:[archiver] 輸入文件似乎不是有效的存檔

[英]Postgres Tutorial: pg_restore: [archiver] input file does not appear to be a valid archive

我正在學習Postgres DVD 教程,並且在導入他們的示例數據庫時遇到了問題。

運行pg_restore -U postgres -d dvdrental ~[filepath]/dvd-database.tar.gz給了我pg_restore: [archiver] input file does not appear to be a valid archive

到目前為止,我的流程如下:

  1. 下載dvdrental.zip文件
  2. 使用tar czf dvd-database.tar.gz dvdrental.zip將其解壓縮到 .tar (我也嘗試先將 zip 解壓縮到文件夾中,結果相同,並刪除 .gz)
  3. 如上所述運行pg_restore -U postgres -d dvdrental ~[filepath]/dvd-database.tar

我目前正在使用 Postgres 9.5,這可能會導致問題。 尋找一個答案,指出我在這個過程中哪里出錯了,或者如何將 Postgres 數據庫的存檔更新到 9.5。

根據上面的評論,解決方案很簡單。

無需按照教程說明中的建議將 dvdrental.zip 文件解壓縮為未壓縮的 .tar。 如果指向提取數據庫轉儲的目錄pg_restore將起作用

pg_restore -U <username> -d dvdrental <your/path/to/extracted/dir>/dvdrental

我的問題是,在安裝 postgresql 時,我為超級用戶選擇了不同的名稱(例如root ,而不是postgres )。 並且dvdrental/restore.sql文件使用postgres角色。 因此,要解決此問題,您需要創建另一個名為postgres超級用戶。

createuser --superuser postgres

然后創建角色服務器(PosgreSQL) postgres和DB dvdrental與角色postgres 在你可以成功地從提取的文件夾中恢復數據庫之后

經過幾個小時對我有用的是以下命令。 由於 PgAdmin 4 很難使用。

/Library/PostgreSQL/10/bin/pg_restore -U postgres -p 5433  -d dvdrental /pg-db/dvdrental/

只需將 zip 解壓縮到一個文件夾中,然后在我的 Mac 操作系統中使用這些選項執行pg_restore命令,其中/pg-db/dvdrental/是 zip 解壓縮的目錄。

使用 pgAdmin 4 會更容易。

通過 pgAdmin 將 tar 文件恢復到數據庫時,您將收到此錯誤。 我們通常會卡在這一點上而忘記檢查架構。

忽略錯誤。 數據已經加載並恢復。

如果您在Docker上運行 postgres,請確保傳遞主機名和端口,

pg_restore -U postgres -h localhost -p 5432 -d dvdrental ./Downloads/dvdrental

在這里,./ ./Downloads/dvdrental dvdrental 是從 dvdrental.zip 中提取的文件夾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM