LoginSignup
0
1

More than 3 years have passed since last update.

[備忘録]PostgreSQLでデータベースに接続する際のパスワードを省略する方法

Last updated at Posted at 2019-09-02

環境

PostgreSQL 11.5

概要

PostgreSQLでデータベースに接続する際のパスワードは省略できる。
WindowsとUnixで方法が異なるため、それぞれの方法を記述する。

Windows

%APPDATA%\postgresql\配下に pgpass.conf というテキストファイルを作成する。
pgpass.conf 内の記述書式は以下の通り

hostname:port:database:username:password

次のように複数のデータベースをまとめて記述できる。

#hostname:port:database:username:password

localhost:5432:postgres:postgres:password
localhost:5432:sample_app_development:yakiniku:111111
localhost:5432:sample_app_test:yakiniku:111111

先頭に#がつくとその行はコメントになる。

Unix

環境変数のPGPASSFILEで設定されているファイル(デフォルトは~/.pgpass)にWindows環境と同じ書式の内容を記述する。
以下のコマンドでファイルの権限を600に変更する。

chmod 0600 ~/.pgpass

参考

PostgreSQL 9.4.5文書 31.15. パスワードファイル

0
1
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
0
1