![](/img/trans.png)
[英]pg_restore: [archiver] input file does not appear to be a valid archive error in PostgreSQL using Pgadmin 4
[英]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
。
到目前為止,我的流程如下:
tar czf dvd-database.tar.gz dvdrental.zip
將其解壓縮到 .tar (我也嘗試先將 zip 解壓縮到文件夾中,結果相同,並刪除 .gz)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.