0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RDSへのpsqlコマンドでの接続

Last updated at Posted at 2016-11-13

0. ローカル端末での作業

0.1. 変数の設定

変数の設定
FILE_SSH_KEY='<キーペアの秘密鍵ファイルのパス>'
EC2_PUBLIC_IP='<EC2インスタンスのIPアドレス>'

0.2. .pgpassの転送

コマンド(Local)
scp -i ${FILE_SSH_KEY} ~/.pgpass ec2-user@${EC2_PUBLIC_IP}:
結果(例)
.pgpass                                       100%  111     0.1KB/s   00:00    

1. EC2へのログイン

コマンド
ssh -i ${FILE_SSH_KEY} ec2-user@${EC2_PUBLIC_IP}

2. 変数の設定

変数の設定(例)
RDS_INSTANCE_ENDPOINT=<RDSのエンドポイント>
RDS_USER_NAME='pgadmin'
RDS_DB_NAME="handson$(date +%Y%m%d)"

3. 接続

コマンド
psql \
        --host=${RDS_INSTANCE_ENDPOINT} \
        --username=${RDS_USER_NAME} \
        --dbname=${RDS_DB_NAME}
結果
      psql (9.5.5, server 9.5.4)
      SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
      Type "help" for help.

      handson20161113=>

3. DBコマンドのテスト実行

DBコマンドのテスト実行をしてみます。

SQL
select version();
結果(例)

                                                       version
      ----------------------------------------------------------------------------------------------------------
        PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16), 64-bit
       (1 row)

4. DBへの接続を切断

DBへの接続を切断します。

コマンド
\q

完了

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?