LoginSignup
37
42

More than 5 years have passed since last update.

postgresqlを他ホストからもつなげるようにする

Posted at

postgresqlはデフォルトでは自ホストからしか繋げないようになっています。そのためVagrantで仮想マシンをつくりその中につくったpostgresqlにクライアントアプリからアクセスするためには設定が必要になります。

1. postgresq.confファイルの修正

#postgresql.confを編集
listen_addresses = '*' ←コメントを解除し、''内を * に修正
port 5432 ←コメントを解除し、ポート番号を変更する

postgresql.confを再起動

# /etc/rc.d/init.d/postgresql restart

2. ポートを開く

ポート5432を開くためにiptablesを編集。

#iptablesに追加
-A INPUT -p tcp --dport 5432 -j ACCEPT

iptablesを再起動。

# /etc/rc.d/init.d/iptables restart

3. 接続できるクライアントを設定する

pg_hba.confファイルを編集。
「trust」は無条件でデータベース接続を許可するため、セキュリティを考慮する場合は、「trust」を「password」などにする。

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

pg_hba.confを再起動

# /etc/rc.d/init.d/postgresql restart

参考:
* 基本:http://rina.jpn.ph/~rance/linux/postgresql/connect.html
* 一部:http://nobuneko.com/blog/archives/2010/03/postgresqlpsql_fatal_ident_aut_1.html

37
42
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
37
42