LoginSignup
2
3

More than 5 years have passed since last update.

psqlのデフォルト接続先を変更する

Posted at

psqlでホスト名など何も入力しなかった場合、デフォルトではlocalhostに接続しに行きますが、ローカルではなくAmazon RDSなど外部のデータベースサーバーに接続する場合に毎回 psql hogedb -h example.com -U hoge などとするのは苦行ですね。

echo 'export PGHOST=yourhostname' >> ~/.bashrc
echo 'export PGPORT=5432' >> ~/.bashrc
echo 'export PGDATABASE=yourdatabasename' >> ~/.bashrc
echo 'export PGUSER=yourusername' >> ~/.bashrc

source ~/.bashrc

yourなんちゃらの部分は適宜変えて下さい。

参考

環境変数で設定できるのは聞いたことあったんですが、長らくドキュメントを見つけられませんでした。psqlでなくlibpqの中に書いてあるとは思わなんだ…

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3