PostgreSQLを入れる
- 2022年4月20日
( 2022/01 実施 )
作成した ec2に、 PostgreSQL を入れてみる。
タイトルがなぜか大文字になる。
1.yum からインストールできるか見てみる。
$ sudo yum list | grep postgres
・・・
postgresql-server.aarch64 9.2.24-6.amzn2 amzn2-core
・・・
古い。
2.新しいもの(13を入れようと思う)を入れる為、レポジトリを入れる。
インスタンスはarmで、amazon linux2 はcentos 7 系らしいので、そのレポジトリをいれる。
$ sudo rpm -ivh https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-aarch64/pgdg-redhat-repo-latest.noarch.rpm
Retrieving https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-aarch64/pgdg-redhat-repo-latest.noarch.rpm
warning: /var/tmp/rpm-tmp.NjbT4I: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
error: Failed dependencies:
/etc/redhat-release is needed by pgdg-redhat-repo-42.0-23.noarch
上記の様なエラーが出てインストールできない。GPG署名のチェックがダメらしい。
なので、ダウンロードする先も正しい事だし、署名チェックを無視する様にしていれる。
$ sudo rpm -ivh --nodeps https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-aarch64/pgdg-redhat-repo-latest.noarch.rpm
Retrieving https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-aarch64/pgdg-redhat-repo-latest.noarch.rpm
warning: /var/tmp/rpm-tmp.DDhUAw: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:pgdg-redhat-repo-42.0-23 ################################# [100%]
$ sudo yum list installed | grep pgdg
pgdg-redhat-repo.noarch 42.0-23 installed
入った。
3.もう1回インストールできるものを確認してみる。
$ sudo yum list | grep postgresql13
https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-2-aarch64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
One of the configured repositories failed (PostgreSQL common RPMs for RHEL/CentOS 2 - aarch64),
・・・・
failure: repodata/repomd.xml from pgdg-common: [Errno 256] No more mirrors to try.
https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-2-aarch64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
エラーが出る。レポジトリの情報を確認してみる。$ cat /etc/yum.repos.d/pgdg-redhat-all.repo
#######################################################
# PGDG Red Hat Enterprise Linux / CentOS repositories #
#######################################################
# PGDG Red Hat Enterprise Linux / CentOS stable common repository for all PostgreSQL versions
[pgdg-common]
name=PostgreSQL common RPMs for RHEL/CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
repo_gpgcheck = 1
# PGDG Red Hat Enterprise Linux / CentOS stable repositories:
[pgdg14]
name=PostgreSQL 14 for RHEL/CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/14/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
repo_gpgcheck = 1
[pgdg13]
name=PostgreSQL 13 for RHEL/CentOS $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
repo_gpgcheck = 1
・・・・
$releasever、$basearch が実行環境に合わせて置換されるらしいが、amazon linux2 は、centos7 系らしいけど、エラーを見てみると、
https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-2-aarch64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
な感じになっているので、$basearch はいい感じに置換されているが、$releasever が2に置換されているので、存在しないurlになってるので、$releaseverを7にしてしまう。
$ sudo sed -i 's/\$releasever/7/g' /etc/yum.repos.d/pgdg-redhat-all.repo
それで、やると、
$ sudo yum list | grep postgresql13
Importing GPG key 0x442DF0F8:
Userid : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
Package : pgdg-redhat-repo-42.0-23.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-7-aarch64/repodata/repomd.xml: [Errno -1] Gpg Keys not imported, cannot verify repomd.xml for repo pgdg-common
Trying other mirror.
One of the configured repositories failed (PostgreSQL common RPMs for RHEL/CentOS 7 - aarch64),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3.Run the command with the repository temporarily disabled
yum --disablerepo=pgdg-common ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable pgdg-common
or
subscription-manager repos --disable=pgdg-common
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=pgdg-common.skip_if_unavailable=true
failure: repodata/repomd.xml from pgdg-common: [Errno 256] No more mirrors to try.
https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-7-aarch64/repodata/repomd.xml: [Errno -1] Gpg Keys not imported, cannot verify repomd.xml for repo pgdg-common
今度は repo_gpgcheck がダメらしいので、正しいかどうかはわからないけど、無効にする。
本当はやった方がいいのだろう。
$ sudo sed -i 's/repo_gpgcheck = 1/repo_gpgcheck = 0/g' /etc/yum.repos.d/pgdg-redhat-all.repo
そうすると、
$ sudo yum list | grep postgresql13
postgresql13.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-contrib.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-devel.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-docs.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-libs.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-llvmjit.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-odbc.aarch64 13.02.0000-1PGDG.rhel7 pgdg13
postgresql13-plperl.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-plpython3.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-pltcl.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-server.aarch64 13.5-1PGDG.rhel7 pgdg13
postgresql13-test.aarch64 13.5-1PGDG.rhel7 pgdg13
という感じになるので、インストールできそう。
pgdg-common (クラスター関連のパッケージらしい)やいらないバージョンのものは、必要ないし、yum update のとき邪魔なので、pgdg-redhat-all.repoから削除してしまってもいいと思う。
4.インストール
$ sudo yum install -y postgresql13 postgresql13-server
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core | 3.7 kB 00:00:00
8 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package postgresql13.aarch64 0:13.5-1PGDG.rhel7 will be installed
--> Processing Dependency: postgresql13-libs(aarch-64) = 13.5-1PGDG.rhel7 for package: postgresql13-13.5-1PGDG.rhel7.aarch64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql13-13.5-1PGDG.rhel7.aarch64
---> Package postgresql13-server.aarch64 0:13.5-1PGDG.rhel7 will be installed
--> Running transaction check
---> Package postgresql13-libs.aarch64 0:13.5-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================
Package Arch Version Repository Size
=====================================================
Installing:
postgresql13 aarch64 13.5-1PGDG.rhel7 pgdg13 1.4 M
postgresql13-server aarch64 13.5-1PGDG.rhel7 pgdg13 5.2 M
Installing for dependencies:
postgresql13-libs aarch64 13.5-1PGDG.rhel7 pgdg13 367 k
Transaction Summary
=====================================================
Install 2 Packages (+1 Dependent package)
Total download size: 6.9 M
Installed size: 33 M
Downloading packages:
warning: /var/cache/yum/aarch64/2/pgdg13/packages/postgresql13-13.5-1PGDG.rhel7.aarch64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Public key for postgresql13-13.5-1PGDG.rhel7.aarch64.rpm is not installed
(1/3): postgresql13-13.5-1PGDG.rhel7.aarch64.rpm | 1.4 MB 00:00:00
(2/3): postgresql13-server-13.5-1PGDG.rhel7.aarch64.rpm | 5.2 MB 00:00:00
(3/3): postgresql13-libs-13.5-1PGDG.rhel7.aarch64.rpm | 367 kB 00:00:01
-------------------------------------------------------------------------------------------
Total 6.2 MB/s | 6.9 MB 00:00:01
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Importing GPG key 0x442DF0F8:
Userid : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
Package : pgdg-redhat-repo-42.0-23.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
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-23.noarch has missing requires of /etc/redhat-release
Installing : postgresql13-libs-13.5-1PGDG.rhel7.aarch64 1/3
Installing : postgresql13-13.5-1PGDG.rhel7.aarch64 2/3
Installing : postgresql13-server-13.5-1PGDG.rhel7.aarch64 3/3
Verifying : postgresql13-server-13.5-1PGDG.rhel7.aarch64 1/3
Verifying : postgresql13-13.5-1PGDG.rhel7.aarch64 2/3
Verifying : postgresql13-libs-13.5-1PGDG.rhel7.aarch64 3/3
Installed:
postgresql13.aarch64 0:13.5-1PGDG.rhel7 postgresql13-server.aarch64 0:13.5-1PGDG.rhel7
Dependency Installed:
postgresql13-libs.aarch64 0:13.5-1PGDG.rhel7
Complete!
$ sudo yum list installed | grep postgresql13
postgresql13.aarch64 13.5-1PGDG.rhel7 @pgdg13
postgresql13-libs.aarch64 13.5-1PGDG.rhel7 @pgdg13
postgresql13-server.aarch64 13.5-1PGDG.rhel7 @pgdg13
5.DB初期化$ PGSETUP_INITDB_OPTIONS='--encoding=UTF-8 --locale=C' sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK
6.サービス登録
自動起動する様にサービスに登録。$ sudo systemctl enable --now postgresql-13
起動しているのを確認。$ sudo systemctl status postgresql-13
インストール完了