LoginSignup
33
34

More than 5 years have passed since last update.

Amazon LinuxからPostgreSQL(RDS)へ接続する

Last updated at Posted at 2018-07-31

なんで書いた?

EC2(Amazon Linux)をクライアントとしてRDS(PostgreSQL)に
接続したかったのですが、EC2にPostgreSQLをインストールする
記事にたどり着くことが多かったので書いてみました。

どんな環境?

EC2(Amazon Linux AMI release 2018.03)
RDS(PostgreSQL 9.6.9)

ざっくり言うと?

yumでpostgresqlのclientモジュールをインストールすれば接続できます。
(分かれば簡単だけど、調べ始めた時はクライアント用のモジュールが無い感じだったので困惑しました)

やり方は?

モジュールの確認

yum list | grep postgre

クライアントモジュールのインストール

yum install postgresql96.x86_64

インストールしたモジュールの確認

psql -V

PostgreSQLへ接続

psql -h <RDSのエンドポイント> -U <DBのユーザ名> -d <DB名>

(例)psql -h xxxxx.yyyyy.ap-northeast-1.rds.amazonaws.com -U hogeuser -d hogedb

PostgreSQLでの操作による確認

SELECT version();

※バージョン表示のSQLで動作確認

PostgreSQLの接続を切断

\q

結論に至るまでに調べたこと

yum search postgresqlを実行するとpostgresql96.x86_64がクライアントプログラムであることがわかります。

postgresql96.x86_64 : PostgreSQL client programs

yum info postgresql96.x86_64でも同じことがわかります。

33
34
1

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
33
34