この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
AWSを愛する皆さま、こんにちは。 最近ジムに通い始めたコンサルティング部の西野(@xiye_gen)です。
Amazon Linux 2にPostgreSQL 9.3をインストールする機会があったので、その手順を記します。AWS公式から提供されていないパッケージであるため設定に一手間が必要です。
おことわり
AWSはAmazon Linux 2向けのPostgreSQL 9.3パッケージを提供していないため、本手順においてはRed Hat Enterprise Linux 7のリポジトリからインストールを実施しております。 したがって、重要なワークロードに対して本手順を適用する場合、事前の十分な検証を推奨いたします。 また、実際の適用は自己の責任においてご実施ください。
yumレポジトリの追加
PostgreSQL RPM Repositories URLの確認
Accessing to the PostgreSQL RPM Repositories こちらのページから対象バージョンのURLを確認します。 今回はRed Hat Enterprise Linux 7(x86_64)用のPostgreSQL 9.3をインストールするので、URLは下記のものです。
https://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-7-x86_64/pgdg-redhat93-9.3-3.noarch.rpm
リポジトリのインストール
確認したURLをもとにリポジトリをインストールします。
$ sudo yum localinstall https://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-7-x86_64/pgdg-redhat93-9.3-3.noarch.rpm
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
pgdg-redhat93-9.3-3.noarch.rpm | 5.4 kB 00:00:00
/var/tmp/yum-root-2A8tfd/pgdg-redhat93-9.3-3.noarch.rpm を調べています: pgdg-redhat93-9.3-3.noarch
/var/tmp/yum-root-2A8tfd/pgdg-redhat93-9.3-3.noarch.rpm をインストール済みとして設定しています
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ pgdg-redhat93.noarch 0:9.3-3 を インストール
--> 依存性解決を終了しました。
amzn2-core/2/x86_64 | 2.4 kB 00:00:00
依存性を解決しました
================================================================================================================================================================================================================================================================================
Package アーキテクチャー バージョン リポジトリー 容量
================================================================================================================================================================================================================================================================================
インストール中:
pgdg-redhat93 noarch 9.3-3 /pgdg-redhat93-9.3-3.noarch 2.2 k
トランザクションの要約
================================================================================================================================================================================================================================================================================
インストール 1 パッケージ
合計容量: 2.2 k
インストール容量: 2.2 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : pgdg-redhat93-9.3-3.noarch 1/1
検証中 : pgdg-redhat93-9.3-3.noarch 1/1
インストール:
pgdg-redhat93.noarch 0:9.3-3
完了しました!
インストールされたファイルは下記のコマンドで確認できます。
$ rpm -ql pgdg-redhat93.noarch
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-93
/etc/yum.repos.d/pgdg-93-redhat.repo
[重要] repoファイルの修正
下記の通り、baseurl
行の@releasever
を7
に書き換えます。
/etc/yum.repos.d/pgdg-93-redhat.repo
[pgdg93]
name=PostgreSQL 9.3 $releasever - $basearch
-baseurl=https://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-$releasever-$basearch
+baseurl=https://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-7-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-93
[pgdg93-source]
name=PostgreSQL 9.3 $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/9.3/redhat/rhel-$releasever-$basearch
baseurl=https://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-93
インストール
yum install
$ sudo yum install postgresql93
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
amzn2-core | 2.4 kB 00:00:00
amzn2extra-docker | 1.3 kB 00:00:00
pgdg93 | 4.1 kB 00:00:00
(1/2): pgdg93/x86_64/primary_db | 173 kB 00:00:01
(2/2): pgdg93/x86_64/group_gz | 248 B 00:00:01
14 packages excluded due to repository priority protections
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ postgresql93.x86_64 0:9.3.25-1PGDG.rhel7 を インストール
--> 依存性の処理をしています: postgresql93-libs = 9.3.25-1PGDG.rhel7 のパッケージ: postgresql93-9.3.25-1PGDG.rhel7.x86_64
--> 依存性の処理をしています: libpq.so.5()(64bit) のパッケージ: postgresql93-9.3.25-1PGDG.rhel7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ postgresql93-libs.x86_64 0:9.3.25-1PGDG.rhel7 を インストール
--> 依存性解決を終了しました。
依存性を解決しました
================================================================================================================================================================================================================================================================================
Package アーキテクチャー バージョン リポジトリー 容量
================================================================================================================================================================================================================================================================================
インストール中:
postgresql93 x86_64 9.3.25-1PGDG.rhel7 pgdg93 1.0 M
依存性関連でのインストールをします:
postgresql93-libs x86_64 9.3.25-1PGDG.rhel7 pgdg93 207 k
トランザクションの要約
================================================================================================================================================================================================================================================================================
インストール 1 パッケージ (+1 個の依存関係のパッケージ)
総ダウンロード容量: 1.2 M
インストール容量: 6.0 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): postgresql93-libs-9.3.25-1PGDG.rhel7.x86_64.rpm | 207 kB 00:00:01
(2/2): postgresql93-9.3.25-1PGDG.rhel7.x86_64.rpm | 1.0 MB 00:00:02
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
合計 543 kB/s | 1.2 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : postgresql93-libs-9.3.25-1PGDG.rhel7.x86_64 1/2
インストール中 : postgresql93-9.3.25-1PGDG.rhel7.x86_64 2/2
検証中 : postgresql93-libs-9.3.25-1PGDG.rhel7.x86_64 1/2
検証中 : postgresql93-9.3.25-1PGDG.rhel7.x86_64 2/2
インストール:
postgresql93.x86_64 0:9.3.25-1PGDG.rhel7
依存性関連をインストールしました:
postgresql93-libs.x86_64 0:9.3.25-1PGDG.rhel7
完了しました!
確認
$ psql --version
psql (PostgreSQL) 9.3.25
※今回の検証ではクライアントのみをインストールしておりますが、同様の方法でサーバー等もインストール可能です。
終わりに
このブログがほんの少しでも世界を良くできれば嬉しいです。 コンサルティング部の西野(@xiye_gen)がお送りしました。