Database

RHEL5 上的 Postgresql pgdump 腳本:“失敗:fe_sendauth:沒有提供密碼的數據庫”

  • June 13, 2013

我想要完成的是讓 pg_dump 腳本作為 cron 作業執行。現在我只是想通過在命令行自己呼叫它來執行腳本。我搜尋了 postgresql 郵件列表並遵循了 postgresql 文件,但沒有成功找到解決方案。我也看過 StackOverflow,但在閱讀了 StackOverflow 上的類似文章後,似乎此類問題應該出現在這個網站上。

系統規格:

RHEL5

PostgreSQL 9.0.3

這就是我所做的:

腳本位於此處~/database_backup/pg_dump_script

我從目錄執行它

./pg_dump_script.sh

腳本如下所示:

/home/myusername/lappstack-1.2-5/postgresql/bin/pg_dump --host=localhost 
--port 5433 --username "myusername" --no-password  --format plain --inserts 
--column-inserts --verbose
--file "/home/username/database_backup/$(%m.%d.%y_%1.%M%P).sql"
--table "schema.table_name" --table "schema.table_name1" "db_name"

這個腳本當然是經過修改的,而不是實際的,但讓您了解我在做什麼。我試過其他建議的主機名:127.0.0.1、10.32.123.22(當然不是真實的IP地址)。埠是正確的。5433 是 pg_hba.conf 中的內容

我收到的錯誤:

./pg_dump_script.sh
" failed: fe_sendauth: no password supplieddatabase "
pg_dump.bin: *** aborted because of error
./pg_dump_script.sh: line 2: fg: no job control
./pg_dump_script.sh: line 2: --file: command not found
./pg_dump_script.sh: line 3: --table: command not found
./pg_dump_script.sh: line 4: --table: command not found
./pg_dump_script.sh: line 5: --table: command not found
./pg_dump_script.sh: line 6: --table: command not found
./pg_dump_script.sh: line 7: --table: command not found
./pg_dump_script.sh: line 8: --table: command not found
./pg_dump_script.sh: line 9: --table: command not found
./pg_dump_script.sh: line 10: --table: command not found
./pg_dump_script.sh: line 11: --table: command not found
./pg_dump_script.sh: line 12: --table: command not found
./pg_dump_script.sh: line 13: --table: command not found
./pg_dump_script.sh: line 14: --table: command not found
./pg_dump_script.sh: line 15: --table: command not found
./pg_dump_script.sh: line 16: --table: command not found
./pg_dump_script.sh: line 17: --table: command not found
./pg_dump_script.sh: line 18: --table: command not found
./pg_dump_script.sh: line 19: --table: command not found
./pg_dump_script.sh: line 20: --table: command not found
./pg_dump_script.sh: line 21: --table: command not found
./pg_dump_script.sh: line 22: --table: command not found
./pg_dump_script.sh: line 23: --table: command not found
./pg_dump_script.sh: line 24: --table: command not found
./pg_dump_script.sh: line 25: --table: command not found
./pg_dump_script.sh: line 26: --table: command not found
./pg_dump_script.sh: line 27: --table: command not found
./pg_dump_script.sh: line 28: --table: command not found
./pg_dump_script.sh: line 29: --table: command not found
./pg_dump_script.sh: line 30: --table: command not found
./pg_dump_script.sh: line 31: --table: command not found
./pg_dump_script.sh: line 32: --table: command not found
./pg_dump_script.sh: line 33: --table: command not found
./pg_dump_script.sh: line 34: --table: command not found
./pg_dump_script.sh: line 35: --table: command not found
./pg_dump_script.sh: line 36: --table: command not found
./pg_dump_script.sh: line 37: --table: command not found
./pg_dump_script.sh: line 38: --table: command not found
./pg_dump_script.sh: line 39: --table: command not found
./pg_dump_script.sh: line 40: --table: command not found
./pg_dump_script.sh: line 41: --table: command not found
./pg_dump_script.sh: line 42: --table: command not found
./pg_dump_script.sh: line 43: --table: command not found
./pg_dump_script.sh: line 44: --table: command not found

其他需要配置的文件

我的 ~ 目錄中有一個.pgpass。遵循此約定:

http://www.postgresql.org/docs/9.0/static/libpq-pgpass.html

我也確保我做到了chmod 0600 ~/.pgpass

我可以pg_dump在我的 Windows 機器上使用 PgAdmin3 執行。所以我認為這不是連接問題。我也可以在psql不提供密碼的情況下執行,所以這應該意味著pgpass工作正常嗎?

讓我知道是否需要更多資訊!

更新

我一直在使用每個人的建議,並且已經到了一次調試一個參數的地步。

這就是我所擁有的:

/home/username/lappstack-1.2-5/postgresql/bin/pg_dump --host=127.0.0.1 --port=5433 --username=myusername mydb_name

這將給出錯誤:

$ ./pg_dump_script.sh
Password:
" does not exist  database "my_dbnamenection to database "mydb_name

^ 它沒有正確輸出錯誤。這不是拼寫錯誤。我只是用“mydb_name”替換了實際的數據庫名稱。

我讓它提示輸入密碼,它確實如此,然後我輸入我的密碼。我很欣賞這些評論。他們肯定會在故障排除過程中提供幫助,並將在未來節省我的時間!

問題是有 DOS 輸入。我正在使用膩子,顯然 DOS 編碼正在進入腳本。我所做的是在腳本上執行 dos2unix。在看到它更像是一個腳本問題而不是數據庫管理後,我在 stackoverflow 上發布了這個問題。這是問題和解決方案的 URL。真正的功勞歸功於 chepner & mbratch。多謝你們!

https://stackoverflow.com/questions/16857726/linux-bash-script-doesnt-run-correctly-but-when-run-at-the-command-line-everyt?noredirect=1#comment24313493_16857726

根據您的錯誤消息,您應該嘗試使用反斜杠\


/home/myusername/lappstack-1.2-5/postgresql/bin/pg_dump --host=localhost \
--port 5433 --username "myusername" --no-password  --format plain --inserts \
--column-inserts --verbose \
--file "/home/username/database_backup/$(%m.%d.%y_%1.%M%P).sql" \
--table "schema.table_name" --table "schema.table_name1" "db_name"

引用自:https://serverfault.com/questions/511780