LoginSignup
1
0

More than 1 year has passed since last update.

【備忘】Cloud9にpsql(クライアント)を入れる

Last updated at Posted at 2021-10-05

Cloud9からEC2に入れたpostgresqlサーバに接続したい

postgresqlサーバを作った:【初心者】【備忘】EC2にposgresql12.3をインストール
ので、Cloud9からpsqlクライアントで接続出来るようにしたい。

結構ハマりました

Cloud9もEC2なので、postgresqlサーバを作った話しと同じ流れ
と思いきや…
うちのAWS環境ではEC2とCloud9でOSのバージョンが違っていました。

サービス OS ベースになるOS
Cloud9 Amazon Linux RHEL6系
EC2 Amazon Linux 2 RHEL7系

参考:Amazon Linux は何系のディストリビューションに該当するのか

  • Cloud9のOSバージョン確認
# cat /etc/system-release
Amazon Linux AMI release 2018.03
  • EC2のOSバージョン確認
# cat /etc/system-release
Amazon Linux release 2 (Karoo)

repoインストール

Amazon Linux 1はRHEL6ベースらしいのでここからのrepoファイルをインストールする

https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/
pgdg-redhat-repo-latest.noarch.rpm

repoファイルのダウンロード。

Cloud9のrootユーザで作業

$ sudo su -
# wget --no-check-certificate https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
--2021-10-05 07:15:01--  https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Resolving download.postgresql.org (download.postgresql.org)... 217.196.149.55, 72.32.157.246, 147.75.85.69, ...
Connecting to download.postgresql.org (download.postgresql.org)|217.196.149.55|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6636 (6.5K) [application/x-redhat-package-manager]
Saving to: ‘pgdg-redhat-repo-latest.noarch.rpm’

pgdg-redhat-repo-late 100%[=========================>]   6.48K  --.-KB/s    in 0s      

2021-10-05 07:15:02 (913 MB/s) - ‘pgdg-redhat-repo-latest.noarch.rpm’ saved [6636/6636]

repoファイルのインストール

↑でダウンロードしたrpmをインストールする
/etc/redhat-releaseファイルへの依存関係を無視してインストールするため--nodepsオプションを付けてインストール

# rpm -Uvh --nodeps ./pgdg-redhat-repo-latest.noarch.rpm 
warning: ./pgdg-redhat-repo-latest.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:pgdg-redhat-repo-42.0-11         ################################# [100%]

この状態でrepolist見るとOSのバージョンがPostgreSQL 12 for RHEL/CentOS latest - x86_64になっててインストールで失敗する

# yum repolist
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                        | 2.1 kB  00:00:00     
amzn-updates                                                     | 3.8 kB  00:00:00     
https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-latest-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article 

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.

https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-latest-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
repo id                   repo name                                               status
amzn-main/latest          amzn-main-Base                                           5,934
amzn-updates/latest       amzn-updates-Base                                        6,428
epel/x86_64               Extra Packages for Enterprise Linux 6 - x86_64          12,581
hashicorp/latest/x86_64   Hashicorp Stable - x86_64                                  321
pgdg-common/latest/x86_64 PostgreSQL common RPMs for RHEL/CentOS latest - x86_64     326
pgdg10/latest/x86_64      PostgreSQL 10 for RHEL/CentOS latest - x86_64              980
pgdg11/latest/x86_64      PostgreSQL 11 for RHEL/CentOS latest - x86_64            1,080
pgdg12/latest/x86_64      PostgreSQL 12 for RHEL/CentOS latest - x86_64              659
pgdg95/latest/x86_64      PostgreSQL 9.5 for RHEL/CentOS latest - x86_64               0
pgdg96/latest/x86_64      PostgreSQL 9.6 for RHEL/CentOS latest - x86_64             942
repolist: 29,251

repo編集

このままだとyum installが上手くいかないので、yum.repos.dのファイルを編集する
$releaseverという変数にRHELやCentOSのバージョン数(7とか8)が入るらしいけど、EC2のAmazon Linuxだとsystem-releaseという文字列が入ってyum installが上手くいかない。
参考:【CentOS7】yum の $releasever、$basearch と $infra を知る方法
置換する6はRHEL/CentOSのバージョン6という意味かな。6向けのバイナリを使えというパスになる。

# sed --in-place -e "s/\$releasever/6/g" /etc/yum.repos.d/pgdg-redhat-all.repo

バージョン6になってる

# yum repolist
Loaded plugins: priorities, update-motd, upgrade-helper
1277 packages excluded due to repository priority protections
repo id                  repo name                                          status
amzn-main/latest         amzn-main-Base                                            5,934
amzn-updates/latest      amzn-updates-Base                                         6,428
epel/x86_64              Extra Packages for Enterprise Linux 6 - x86_64     11,514+1,067
hashicorp/latest/x86_64  Hashicorp Stable - x86_64                                   321
pgdg-common/x86_64       PostgreSQL common RPMs for RHEL/CentOS 6 - x86_64         324+2
pgdg10/x86_64            PostgreSQL 10 for RHEL/CentOS 6 - x86_64                    980
pgdg11/x86_64            PostgreSQL 11 for RHEL/CentOS 6 - x86_64                  1,080
pgdg12/x86_64            PostgreSQL 12 for RHEL/CentOS 6 - x86_64                    659
pgdg95/x86_64            PostgreSQL 9.5 for RHEL/CentOS 6 - x86_64                317+88
pgdg96/x86_64            PostgreSQL 9.6 for RHEL/CentOS 6 - x86_64               822+120
repolist: 28,379
  • yum installでエラーでハマる。 systemdが無いとエラーになるが、RHEL6ベースのAmazon Linux 1ではそりゃ無いよ。
  • どうも調べたらPostgresql9までしかRHEL6ベースには入らないっぽい

リポジトリにpsqlクライアントのバージョン9が入ってるか確認

# yum search postgresql9|grep client
postgresql92.x86_64 : PostgreSQL client programs
                       : clients
                         : clients
postgresql93.x86_64 : PostgreSQL client programs
                       : clients
                         : clients
postgresql94.x86_64 : PostgreSQL client programs
                       : clients
                         : clients
postgresql95.x86_64 : PostgreSQL client programs
                       : clients
                         : clients
postgresql95-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql96.x86_64 : PostgreSQL client programs
                       : clients
                         : clients
postgresql96-tcl.x86_64 : A Tcl client library for PostgreSQL

postgresql9の最新版をインストール

# yum install postgresql96.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
1277 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package postgresql96.x86_64 0:9.6.22-1.85.amzn1 will be installed
--> Processing Dependency: postgresql96-libs(x86-64) = 9.6.22-1.85.amzn1 for package: postgresql96-9.6.22-1.85.amzn1.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql96-9.6.22-1.85.amzn1.x86_64
--> Running transaction check
---> Package postgresql96-libs.x86_64 0:9.6.22-1.85.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
 Package                 Arch         Version                  Repository          Size
========================================================================================
Installing:
 postgresql96            x86_64       9.6.22-1.85.amzn1        amzn-updates       4.3 M
Installing for dependencies:
 postgresql96-libs       x86_64       9.6.22-1.85.amzn1        amzn-updates       290 k

Transaction Summary
========================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 4.6 M
Installed size: 17 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): postgresql96-libs-9.6.22-1.85.amzn1.x86_64.rpm            | 290 kB  00:00:00     
(2/2): postgresql96-9.6.22-1.85.amzn1.x86_64.rpm                 | 4.3 MB  00:00:00     
----------------------------------------------------------------------------------------
Total                                                       22 MB/s | 4.6 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
pgdg-redhat-repo-42.0-11.noarch has missing requires of /etc/redhat-release
  Installing : postgresql96-libs-9.6.22-1.85.amzn1.x86_64                           1/2 
  Installing : postgresql96-9.6.22-1.85.amzn1.x86_64                                2/2 
  Verifying  : postgresql96-libs-9.6.22-1.85.amzn1.x86_64                           1/2 
  Verifying  : postgresql96-9.6.22-1.85.amzn1.x86_64                                2/2 

Installed:
  postgresql96.x86_64 0:9.6.22-1.85.amzn1                                               

Dependency Installed:
  postgresql96-libs.x86_64 0:9.6.22-1.85.amzn1                                          

Complete!
  • インストール確認
# psql -V
psql (PostgreSQL) 9.6.22
1
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
1
0