psql 帶上密碼


命令行如何帶上密碼?

可以參考stackoverflow里這個回答:
postgresql-scripting-psql-execution-with-password

里面寫道:

"The obvious way is via the password prompt
Instead of that, you can...
provide the password in a pgpass file or through the PGPASSWORD environment variable."

最顯而易見的方法是通過控制台提醒你來輸入密碼,
除此之外你還可以:

  1. 把密碼放在pgpass文件
  2. 把密碼放在PGPASSWORD環境變量里

具體怎么配置pgpass文件和PGPASSWORD環境變量可以參考下面兩篇官方文檔。

使用PGPASSWORD環境變量

Command-line There is no option to provide the password as a command line argument because that information is often available to all users, and therefore insecure. However, in Linux/Unix environments you can provide an environment variable for a single command like this:
PGPASSWORD=yourpass psql ...psql -h 192.168.1.8 -p 5432 -U lg -d mydb -c "select * from myschema.table"

命令行:psql命令行沒有提供密碼參數,因為這樣的話密碼很可能會被所有用戶知道,這樣不安全。但是在Linux/Unix環境中你可以像下面這個命令一樣,搞個環境變量即可:
PGPASSWORD=yourpass psql -h 192.168.1.8 -p 5432 -U lg -d mydb -c "select * from myschema.table"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM