AWS EC2からAurora(PostgreSQL)に接続する方法

環境
AWS EC2
AWS Aurora(PostgreSQL)

概要
1.EC2にSSH接続をしてAurora(PostgreSQL)に接続します。
2.インスタンスがデータを処理します。

操作手順
1.Tera TermのSSHでEC2に接続します。

2.Aurora(PostgreSQL)に接続するためのpsql(PostgreSQL)をインストールします。
インストール済みかの確認は以下のコマンドを実行します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yum list installed | grep postgresql
yum list installed | grep postgresql
yum list installed | grep postgresql

インストールは以下のコマンドを実行します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo yum -y install postgresql
sudo yum -y install postgresql
sudo yum -y install postgresql

3.Aurora(PostgreSQL)の接続情報を取得します。
AWSのマネジメントコンソールからRDSの画面に入ります。
「データベース」をクリックし、一覧の作成したライターインスタンス(test-database-1-instance-1)のリンクをクリックし、「接続とセキュリティ」タブにある「エンドポイント」の値をコピーします。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
例 database-1-instance-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com
例 database-1-instance-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com
例 database-1-instance-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com

4.Aurora(PostgreSQL)への接続のコマンドを入力します。
psql -h エンドポイント -u ユーザ名 -p

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
psql -h database-1-instance-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com -U postgres -d testaa
psql -h database-1-instance-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com -U postgres -d testaa
psql -h database-1-instance-1.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com -U postgres -d testaa

5.PostgreSQLへログインします。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Password for user postgres:
psql (9.2.24, server 11.9)
WARNING: psql version 9.2, server version 11.0.
Some psql features might not work.
SSL connection (cipher: ECDHE-RSA-AES128-SHA, bits: 128)
Type "help" for help.
testaa=>
Password for user postgres: psql (9.2.24, server 11.9) WARNING: psql version 9.2, server version 11.0. Some psql features might not work. SSL connection (cipher: ECDHE-RSA-AES128-SHA, bits: 128) Type "help" for help. testaa=>
Password for user postgres:
psql (9.2.24, server 11.9)
WARNING: psql version 9.2, server version 11.0.
Some psql features might not work.
SSL connection (cipher: ECDHE-RSA-AES128-SHA, bits: 128)
Type "help" for help.

testaa=>

6.Auroraのバージョンを確認(コマンド)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
testaa=> select aurora_version();
testaa=> show server_version;
testaa=> select aurora_version(); testaa=> show server_version;
testaa=> select aurora_version();

testaa=> show server_version;

 

 

AWS

Posted by arkgame