本文主要講在連接時的替代作用(win7環境下):
當默認值並不十分恰當時,我們可以通過設置環境變量來節省一些輸入,比如將PGDATABASE, PGHOST, PGPORT或者 PGUSER設置為恰當的值。(對於其他環境變量,詳見Section 31.14。)
1 設置環境變量
2 在終端中輸入D:\Program Files (x86)\HighGo\Database\1.3\bin>psql –help
即可看到現在user默認值更改為lhh。
直接輸psql(不用-U指定用戶),則默認的user就是lhh。
用一個 ~/.pgpass 文件來避免每次登陸都要輸入密碼的問題,這也很方便。請參閱Section 31.15 獲取更多相關信息。
pgdass.conf目錄:C:\Users\Jasmine\AppData\Roaming\postgresql\pgpass.conf
pgdass.conf 參數行格式:hostname:port:database:username:password
設置完畢后,連接響應用戶、數據庫……時就不需要輸入密碼立刻:
指定連接參數的另一種方法是用一個conninfo字符串或URI,用來代替一個數據庫名。這種機制使你對連接有非常廣泛的控制權。
pg9.1及之前就有這種方法:
用法: $ psql "service=myservice sslmode=require"
例子:
[postgres@localhost bin]$ ./psql "host=127.0.0.1 port=5432 dbname=postgres user=postgres"
psql (9.2beta4)
password:
Type "help" for help.
pg9.2中新添加的方法:
用法:$ psql postgresql://dbmaster:5433/mydb?sslmode=require
例子:
[postgres@localhost bin]$ ./psql postgresql://127.0.0.1:5432/postgres
psql (9.2beta4)
password:
Type "help" for help.