おつかれさまです。Dです。
PostgreSQLを全く触ったことが無かったんですが、業務上必要になり色々と調べたので
せっかくなのでブログで徐々に書き連ねていこうの続きです。
内容
今回は実際にPostgreSQLをインストールしていこうと思います。
検証環境はAlamLinux8.7です。
-----------------------------------------
# cat /etc/redhat-release
AlmaLinux release 8.7 (Stone Smilodon)
-----------------------------------------
Almalinux8系では、AppStreamのリポジトリから欲しいバージョンを有効化してインストールします。
まずは、どのバージョンが選択出来るか確認していきます。
-----------------------------------------
# dnf module list postgresql
Last metadata expiration check: 1:56:19 ago on Thu 06 Apr 2023 03:28:52 PM JST.
AlmaLinux 8 - AppStream
Name Stream Profiles Summary
postgresql 9.6 [x] client, server [d] PostgreSQL server and client module
postgresql 10 [d][x] client, server [d] PostgreSQL server and client module
postgresql 12 [x] client, server [d] PostgreSQL server and client module
postgresql 13 [x] client, server [d] PostgreSQL server and client module
-----------------------------------------
今回は選べるバージョンの中で一番新しい13を有効化します。
-----------------------------------------
# dnf module enable postgresql:13 -y
Last metadata expiration check: 1:59:27 ago on Thu 06 Apr 2023 03:28:52 PM JST.
Dependencies resolved.
=============================================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================================
Enabling module streams:
postgresql 13
Transaction Summary
=============================================================================================================================================
Complete!
-----------------------------------------
有効化したら実際にインストールしていきます。
------------------------------------------------------------
# dnf install -y postgresql postgresql-server
Last metadata expiration check: 1:59:55 ago on Thu 06 Apr 2023 03:28:52 PM JST.
Package postgresql-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 is already installed.
Package postgresql-server-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 is already installed.
Dependencies resolved.
=============================================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================================
Upgrading:
postgresql x86_64 13.10-1.module_el8.7.0+3498+cb1ef3c6 appstream 1.5 M
postgresql-server x86_64 13.10-1.module_el8.7.0+3498+cb1ef3c6 appstream 5.6 M
Transaction Summary
=============================================================================================================================================
Upgrade 2 Packages
Total download size: 7.1 M
Downloading Packages:
(1/2): postgresql-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64.rpm 13 MB/s | 1.5 MB 00:00
(2/2): postgresql-server-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64.rpm 19 MB/s | 5.6 MB 00:00
---------------------------------------------------------------------------------------------------------------------------------------------
Total 24 MB/s | 7.1 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: postgresql-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64 1/1
Upgrading : postgresql-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64 1/4
Running scriptlet: postgresql-server-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64 2/4
Upgrading : postgresql-server-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64 2/4
Running scriptlet: postgresql-server-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64 2/4
Running scriptlet: postgresql-server-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 3/4
Cleanup : postgresql-server-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 3/4
Running scriptlet: postgresql-server-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 3/4
Cleanup : postgresql-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 4/4
Running scriptlet: postgresql-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 4/4
Verifying : postgresql-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64 1/4
Verifying : postgresql-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 2/4
Verifying : postgresql-server-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64 3/4
Verifying : postgresql-server-10.23-1.module_el8.7.0+3379+54d21c26.x86_64 4/4
Upgraded:
postgresql-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64 postgresql-server-13.10-1.module_el8.7.0+3498+cb1ef3c6.x86_64
Complete!
------------------------------------------------------------
DBを初期化しておく。
------------------------------------------------------------
# /usr/bin/postgresql-setup initdb
WARNING: using obsoleted argument syntax, try --help
WARNING: arguments transformed to: postgresql-setup --initdb --unit postgresql
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
------------------------------------------------------------
自動起動設定とサービス再起動を実施する。
------------------------------------------------------------
# systemctl enable postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
# systemctl start postgresql
# systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2023-04-06 17:46:05 JST; 5s ago
Process: 14722 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
Main PID: 14725 (postmaster)
Tasks: 8 (limit: 11362)
Memory: 17.0M
CGroup: /system.slice/postgresql.service
tq14725 /usr/bin/postmaster -D /var/lib/pgsql/data
tq14726 postgres: logger
tq14728 postgres: checkpointer
tq14729 postgres: background writer
tq14730 postgres: walwriter
tq14731 postgres: autovacuum launcher
tq14732 postgres: stats collector
mq14733 postgres: logical replication launcher
Apr 06 17:46:05 *** systemd[1]: Starting PostgreSQL database server...
Apr 06 17:46:05 *** postmaster[14725]: 2023-04-06 17:46:05.756 JST [14725] LOG: redirecting log output to logging collect>
Apr 06 17:46:05 *** postmaster[14725]: 2023-04-06 17:46:05.756 JST [14725] HINT: Future log output will appear in directo>
Apr 06 17:46:05 *** systemd[1]: Started PostgreSQL database server.
------------------------------------------------------------
設定ファイル群は以下のディレクトリに配置されています。
--------------------------------------------------------------------------
# ls -la /var/lib/pgsql/data/
total 68
drwx------ 20 postgres postgres 4096 Apr 6 17:46 .
drwx------ 5 postgres postgres 135 Apr 6 17:43 ..
drwx------ 5 postgres postgres 41 Apr 6 17:43 base
-rw------- 1 postgres postgres 30 Apr 6 17:46 current_logfiles
drwx------ 2 postgres postgres 4096 Apr 6 17:43 global
drwx------ 2 postgres postgres 32 Apr 6 17:46 log
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_commit_ts
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_dynshmem
-rw------- 1 postgres postgres 4516 Apr 6 17:43 pg_hba.conf
-rw------- 1 postgres postgres 1636 Apr 6 17:43 pg_ident.conf
drwx------ 4 postgres postgres 68 Apr 6 17:51 pg_logical
drwx------ 4 postgres postgres 36 Apr 6 17:43 pg_multixact
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_notify
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_replslot
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_serial
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_snapshots
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_stat
drwx------ 2 postgres postgres 25 Apr 6 17:52 pg_stat_tmp
drwx------ 2 postgres postgres 18 Apr 6 17:43 pg_subtrans
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_tblspc
drwx------ 2 postgres postgres 6 Apr 6 17:43 pg_twophase
-rw------- 1 postgres postgres 3 Apr 6 17:43 PG_VERSION
drwx------ 3 postgres postgres 60 Apr 6 17:43 pg_wal
drwx------ 2 postgres postgres 18 Apr 6 17:43 pg_xact
-rw------- 1 postgres postgres 88 Apr 6 17:43 postgresql.auto.conf
-rw------- 1 postgres postgres 28088 Apr 6 17:43 postgresql.conf
-rw------- 1 postgres postgres 45 Apr 6 17:46 postmaster.opts
-rw------- 1 postgres postgres 101 Apr 6 17:46 postmaster.pid
--------------------------------------------------------------------------
【まとめ】
今回はLinuxサーバーにPostgreSQLをインストールして起動まで出来ました。
次回は、実際に設定ファイルを編集して接続が出来るように試していきたいと思います。