↑ 關注“少安事務所”公眾號,歡迎?收藏,不錯過精彩內容~
★本文寫于 2023-09-29
PostgreSQL 16 Released
9/14, PostgreSQL 16 正式發布。從發布公告^1 和 Release Notes^2 可以看到 PG16 包含了諸多新特性和增強改進。
-
性能提升,查詢計劃支持并行 FULL
和RIGHT
關聯。 ^3 -
邏輯復制,支持從 standby 服務器進行復制,支持訂閱者并行應用大事務,新增預定義角色 pg_create_subscription
。 ^4 -
開發體驗,增加了 SQL/JSON 構造函數 ( JSON_ARRAY()
,JSON_ARRAYAGG()
)和恒等函數 (IS JSON
)。 ^5 -
監控增強,增加 pg_stat_io
視圖,以支持監控 I/O 統計數據。 ^6
CentOS 7 上 RPM 安裝 PG16 (EOL)
一般情況下,在 CentOS 7 系統上安裝 PostgreSQL 只需要兩條 yum/dnf 命令即可。
sudo?yum?install?-y?https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo?yum?install?-y?postgresql16-server
但是從 PostgreSQL 16 開始,這種安裝方式在 CentOS 7 上已經被停用,所以執行上面兩條命令會看到下面的輸出。
No?package?postgresql16-server?available.
Error:?Nothing?to?do
從 yum 倉庫^7 也只能找到 rhel 8/9 的 postgresql16 rpm 包,并沒有 rhel 7。
其實相關信息 9 月初已在官方網站上發布了公告^8,或許只是注意到的人并不多。
★EOL announcement for RHEL 7
PostgreSQL RPM repo stopped adding new packages to the PostgreSQL RPM repo as of Aug 2023, including PostgreSQL 16.
We will maintain older major releases until each major release is EOLed by PostgreSQL project. Please visit here for latest release dates for each major release.
If you have any questions, please either email to pgsql-pkg-yum@lists.postgresql.org, or create a ticket at our redmine.
那么,仍在使用 CentOS 7 的環境如何安裝、升級 PostgreSQL 16 呢?
Docker 運行 PG16(容易)
PostgreSQL 的官方 Docker 鏡像由 the PostgreSQL Docker Community ^9 維護,提供了 4 個 PG16 的鏡像,分別基于 Debian bullseye / Debian Bookworm / alpine3.17 / alpine3.18 。
演示步驟如下:
-
主機的操作系統為 CentOS 7。
$?hostnamectl
???Static?hostname:?centos7.shawnyan.cn
...
??Operating?System:?CentOS?Linux?7?(Core)
???????CPE?OS?Name:?cpe:/o:centos:centos:7
????????????Kernel:?Linux?3.10.0-1160.92.1.el7.x86_64
??????Architecture:?x86-64
-
拉取 PG16 的 Docker 鏡像。
[shawnyan@centos7?~]$?docker?pull?postgres:16
16:?Pulling?from?library/postgres
a803e7c4b030:?Pull?complete
5cf7cbd17f32:?Pull?complete
ddc24c6f1e18:?Pull?complete
2b0f4d94850a:?Pull?complete
fccb5b7554d1:?Pull?complete
1dd940c0e742:?Pull?complete
f641e2497276:?Pull?complete
9c05395a8e66:?Pull?complete
285e24d225ac:?Pull?complete
3faa43a5d9fc:?Pull?complete
482fc7a6b0f4:?Pull?complete
29ca5fe1b2a4:?Pull?complete
d3012096b6ce:?Pull?complete
Digest:?sha256:379b7a1223b394106cc20d18a5177ed77738003416057e8898cde10e6b7a082a
Status:?Downloaded?newer?image?for?postgres:16
docker.io/library/postgres:16
[shawnyan@centos7?~]$?docker?images?postgres
REPOSITORY???TAG???????IMAGE?ID???????CREATED??????SIZE
postgres?????16????????ec7f99c50d3c???8?days?ago???418MB
-
啟動 PG16 容器。
[shawnyan@centos7?~]$?docker?run?--name?pg16?-e?POSTGRES_HOST_AUTH_METHOD=trust?-d?postgres:16
e3bb74e44107d349f8a2c4a0f9ac9cb3aa4ac26e66bb930069b37c563cc815dd
[shawnyan@centos7?~]$?docker?ps
CONTAINER?ID???IMAGE????????????????COMMAND??????????????????CREATED?????????STATUS????????PORTS???????????????????????????????????????NAMES
e3bb74e44107???postgres:16??????????"docker-entrypoint.s…"???2?seconds?ago???Up?1?second???5432/tcp????????????????????????????????????pg16
這里需要注意的是,需要指定超管用戶的密碼,或者允許所有連接沒有密碼登陸,否則容器會啟動失敗。
[shawnyan@centos7?~]$?docker?logs?pg16
Error:?Database?is?uninitialized?and?superuser?password?is?not?specified.
???????You?must?specify?POSTGRES_PASSWORD?to?a?non-empty?value?for?the
???????superuser.?For?example,?"-e?POSTGRES_PASSWORD=password"?on?"docker?run".
???????You?may?also?use?"POSTGRES_HOST_AUTH_METHOD=trust"?to?allow?all
???????connections?without?a?password.?This?is?*not*?recommended.
???????See?PostgreSQL?documentation?about?"trust":
???????https://www.postgresql.org/docs/current/auth-trust.html
-
連接 PG16。
通過 psql 連接 PG16,并查看版本信息。
[shawnyan@centos7?~]$?docker?exec?-it?pg16?psql?-U?postgres
psql?(16.0?(Debian?16.0-1.pgdg120+1))
Type?"help"?for?help.
postgres=#?select?version();
???????????????????????????????????????????????????????version
---------------------------------------------------------------------------------------------------------------------
?PostgreSQL?16.0?(Debian?16.0-1.pgdg120+1)?on?x86_64-pc-linux-gnu,?compiled?by?gcc?(Debian?12.2.0-14)?12.2.0,?64-bit
(1?row)
postgres=#?select?'Hi,?PG16~';
??column?
-----------
?Hi,?PG16~
(1?row)
在 CentOS 7 上編譯 PG16 源碼(進階)
PG16 在 CentOS 7 上的源碼編譯步驟與 PG15 類似 。
-
下載 PG16 的源碼,并進行編譯、安裝。
wget?https://mirrors.neusoft.edu.cn/postgresql/source/v16.0/postgresql-16.0.tar.gz
tar?zxf?postgresql-16.0.tar.gz
cd?postgresql-16.0/
./configure?--prefix=/opt/postgresql?--with-extra-version="-ShawnYan"
make?-j?$(nproc)?world
make?install-world
-
初始化 PG16。
$?initdb?--pgdata="$PGDATA"
The?files?belonging?to?this?database?system?will?be?owned?by?user?"postgres".
This?user?must?also?own?the?server?process.
The?database?cluster?will?be?initialized?with?locale?"en_US.UTF-8".
The?default?database?encoding?has?accordingly?been?set?to?"UTF8".
The?default?text?search?configuration?will?be?set?to?"english".
Data?page?checksums?are?disabled.
fixing?permissions?on?existing?directory?/data/pg16/data?...?ok
creating?subdirectories?...?ok
selecting?dynamic?shared?memory?implementation?...?posix
selecting?default?max_connections?...?100
selecting?default?shared_buffers?...?128MB
selecting?default?time?zone?...?Asia/Tokyo
creating?configuration?files?...?ok
running?bootstrap?script?...?ok
performing?post-bootstrap?initialization?...?ok
syncing?data?to?disk?...?ok
initdb:?warning:?enabling?"trust"?authentication?for?local?connections
initdb:?hint:?You?can?change?this?by?editing?pg_hba.conf?or?using?the?option?-A,?or?--auth-local?and?--auth-host,?the?next?time?you?run?initdb.
Success.?You?can?now?start?the?database?server?using:
????pg_ctl?-D?/data/pg16/data?-l?logfile?start
-
啟動 PG16。
$?pg_ctl?-D?/data/pg16/data?-l?logfile?start
waiting?for?server?to?start....?done
server?started
-
查看版本信息。
$?psql
psql?(16.0-ShawnYan)
Type?"help"?for?help.
postgres=#?select?version();
?????????????????????????????????????????????????????version
------------------------------------------------------------------------------------------------------------------
?PostgreSQL?16.0-ShawnYan?on?x86_64-pc-linux-gnu,?compiled?by?gcc?(GCC)?4.8.5?20150623?(Red?Hat?4.8.5-44),?64-bit
(1?row)
到此,PG16 已在 CentOS 7 上安裝完成。
總結
CentOS 7 的時代即將結束,將來如何選擇操作系統,是選用 Redhat、Rocky Linux、Ubuntu,還是云廠商的 Linux ?
或許,在考慮升級 PG 版本的同時,也是時候該考慮一下 OS 的版本了。
🌻 往期精彩 ▼
-
從 PG 技術峰會南京站汲取的那些干貨 -
PG 擴展推薦:pgpasswd & PG 密碼長度 -
即將告別PG 12,建議升級到PG 16.3版本 -
PG Style! 盤點幾個常用的 Postgres 環境變量
-- / END / --

如果這篇文章為你帶來了靈感或啟發,就請幫忙點『贊』or『在看』or『轉發』吧,感謝!(??????)
本文由 mdnice 多平臺發布