[英]postgres, psql and a bat file
我正在轉轉,所以需要一些幫助。
我希望能夠通過bat文件對作為計划任務的數據庫運行.sql。 但是,當我手動運行bat文件時,系統提示您輸入密碼。 我輸入密碼,然后被告知...。
"psql: FATAL: password authentication failed for user "(my windows login)"
'-h' is not recognised as an internal or external command,
operable program or batch file.
此刻,我的蝙蝠讀到...
@echo off
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe"
-h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause
首先,我需要添加什么命令來填充密碼請求
我如何處理其余的語句以使其加載.sql
謝謝
通過將此行添加到配置文件( pg_hba.conf
),可以告訴postgres允許本地連接而無需身份驗證
local <database> <user> trust
http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html
所有需要放入批處理文件中的一行(似乎您有兩行):
@echo off
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe" -h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause
為了避免出現密碼提示,請在調用psql之前設置環境變量PGPASSWORD:
@echo off
setlocal
set PGPASSWORD=my_very_secret_password
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe" -h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause
endlocal
可以使用setlocal / endlocal命令來確保在執行批處理文件后清除該變量。
為了避免在批處理文件中使用明文密碼,您可以創建一個包含密碼的pgpass.conf文件。 有關詳細信息,請參見手冊: http : //www.postgresql.org/docs/current/static/libpq-pgpass.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.