在CentOS 8上安装PostgreSQL 12(通过AppStream)
首先
使用Application Stream(AppStream)在CentOS8上安装PostgreSQL 12。
参考:计划很快发布相关文章。
参考:RHEL8的软件包构成-BaseOS和Application Stream-赤帽工程师博客。
支援
如果使用本方法进行安装,根据《Red Hat Enterprise Linux 8 Application Streams Life Cycle – Red Hat Customer Portal》,预计2025-02至2029-05将是EOL。
之后可能不会对报告的漏洞和问题进行修复。
另外,由于CentOS Linux 8将在2021-12到达EOL,所以为了继续接收更新,需要迁移到其他发行版,包括CentOS Stream 8。
日志
CentOS Linux release 8.1.1911 (Core)
# yum module list postgresql
無法設置locale,預設為C.UTF-8
上次元數據到期檢查:在2020年2月11日星期二01:24:28之前0:00:13。
CentOS-8 – AppStream
名稱 流 配置 摘要
postgresql 9.6 client, server [d] PostgreSQL伺服器和客戶端模塊
postgresql 10 [d] client, server [d] PostgreSQL伺服器和客戶端模塊
postgresql 12 client, server PostgreSQL伺服器和客戶端模塊
提示:[d]efault,[e]nabled,[x]disabled,[i]nstalled
# yum install -y @postgresql:12/server
… 略
# mkdir /usr/local/pgsql
# chown postgres:postgres /usr/local/pgsql
# ls -la /usr/local/pgsql
總計 16
drwxr-xr-x. 2 postgres postgres 4096 2月 11 01:37 .
drwxr-xr-x. 1 root root 4096 2月 11 01:37 ..
# su – postgres
$ initdb –no-local -D /usr/local/pgsql/data
… 略
成功。您現在可以使用以下命令啟動數據庫服務器:
pg_ctl -D /usr/local/pgsql/data -l logfile start
postgresql啟動/停止(沒有安裝版)
$ pg_ctl -D /usr/local/pgsql/data -l logfile start
等待服務器啟動…. 完成
服務器已啟動
$ pg_ctl -D /usr/local/pgsql/data -l logfile status
pg_ctl: 服務器正在運行 (PID: 410)
/usr/bin/postgres “-D” “/usr/local/pgsql/data”
$ pg_ctl -D /usr/local/pgsql/data -l logfile stop
等待服務器關閉…. 完成
服務器已停止
$ pg_ctl -D /usr/local/pgsql/data -l logfile status
pg_ctl: 沒有正在運行的服務器
安装
# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
# yum module list postgresql
Last metadata expiration check: 0:05:33 ago on Tue 11 Feb 2020 02:09:01 AM UTC.
CentOS-8 - AppStream
Name Stream Profiles Summary
postgresql 9.6 client, server [d] PostgreSQL server and client module
postgresql 10 [d] client, server [d] PostgreSQL server and client module
postgresql 12 client, server PostgreSQL server and client module
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
# yum update -y
# yum install -y @postgresql:12/server
... 略
# /usr/bin/postgresql-setup --initdb
... 略
启动/停止postgresql
# systemctl start postgresql
# systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2020-02-11 02:10:29 UTC; 3s ago
Process: 421 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
Main PID: 423 (postmaster)
Tasks: 8 (limit: 8964)
Memory: 17.0M
CGroup: /docker/69b522087b2db5e428dca4eb4b77549a111fde99a7f80b83563dbec354d85bfb/docker/69b522087b2db5e428>
tq423 /usr/bin/postmaster -D /var/lib/pgsql/data
tq424 postgres: logger
tq426 postgres: checkpointer
tq427 postgres: background writer
tq428 postgres: walwriter
tq429 postgres: autovacuum launcher
tq430 postgres: stats collector
mq431 postgres: logical replication launcher
Feb 11 02:10:29 69b522087b2d systemd[1]: Starting PostgreSQL database server...
Feb 11 02:10:29 69b522087b2d systemd[1]: Started PostgreSQL database server.
# systemctl stop postgresql
# systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Feb 11 02:10:29 69b522087b2d systemd[1]: Starting PostgreSQL database server...
Feb 11 02:10:29 69b522087b2d systemd[1]: Started PostgreSQL database server.
Feb 11 02:11:08 69b522087b2d systemd[1]: Stopping PostgreSQL database server...
Feb 11 02:11:08 69b522087b2d systemd[1]: Stopped PostgreSQL database server.
设置/取消自动启动PostgreSQL
# systemctl enable postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
# systemctl list-unit-files --type=service |grep postgresql
postgresql.service enabled
postgresql@.service disabled
# systemctl disable postgresql
Removed /etc/systemd/system/multi-user.target.wants/postgresql.service.
# systemctl list-unit-files --type=service |grep postgresql
postgresql.service disabled
postgresql@.service disabled
各种确认
# which postgres
/usr/bin/postgres
# which psql
/usr/bin/psql
# psql --version
psql (PostgreSQL) 12.1