認証方式をパスワード方式に変更
$ su - # cd /var/lib/pgsql/9.2/data/ # cp pg_hba.conf pg_hba.conf.ORG # vi pg_hba.conf # "local" is for Unix domain socket connections only #local all all peer local all all md5 # IPv4 local connections: #host all all 127.0.0.1/32 ident host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 ident # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer #host replication postgres 127.0.0.1/32 ident #host replication postgres ::1/128 ident host all all 10.0.0.0/8 md5
ネットワーク経由のアクセスを許可
# vi postgresql.conf listen_addresses = '*' # what IP address(es) to listen on; #listen_addresses = 'localhost' # what IP address(es) to listen on; port = 5432 # (change requires restart) #port = 5432 # (change requires restart) # /etc/init.d/postgresql-9.2 restart
ユーザとDBを作成
$ su - postgres $ createuser -d -U postgres -P testuser 新しいロールのためのパスワード:testuser! もう一度入力してください:testuser! $ createdb -O testuser -U testuser testdb
接続テスト
$ psql -U testuser -h ec2-999-999-999-999.ap-northeast-1.compute.amazonaws.com testdb Password for user testuser: testuser! psql (9.2.3) Type "help" for help. testdb=>