跳过正文

Postgres升级至18

·212 字·1 分钟

说明
#

Postgres 18 有个变动需要注意,会影响到升级方法。

默认启用Checksum
#

Databases initialized with PostgreSQL 18 initdb now have page checksums enabled by default. This can affect upgrades from non-checksum enabled clusters, which would require you to create a new PostgreSQL 18 cluster with the –no-data-checksums option when using pg_upgrade.

之前安装的默认没有开启,需要手动开启data_checksums

jarvis@nextcloud:~$ docker stop db
db
jarvis@nextcloud:~$ docker rm db
db
jarvis@nextcloud:~$ docker run --rm -it --entrypoint=/bin/bash -v nextcloud_db_17:/var/lib/postgresql/data postgres:17.6
root@3ed56fb63280:/# su postgres
postgres@3ed56fb63280:/$ pg_checksums --enable -D /var/lib/postgresql/data
Checksum operation completed
Files scanned:   2751
Blocks scanned:  168058
Files written:  2266
Blocks written: 168054
pg_checksums: syncing data directory
pg_checksums: updating control file
Checksums enabled in cluster




jarvis@nextcloud:~$ docker exec -it db bash
root@01cf25a9e12c:/# su postgres
postgres@01cf25a9e12c:/$ psql
psql (17.6 (Debian 17.6-1.pgdg13+1))
Type "help" for help.

postgres=# SHOW data_checksums;
 data_checksums
----------------
 on
(1 row)

Docker文件路径有变动
#

PGDATA

Important Change: the PGDATA environment variable of the image was changed to be version specific in PostgreSQL 18 and above⁠. For 18 it is /var/lib/postgresql/18/docker. Later versions will replace 18 with their respective major version (e.g., /var/lib/postgresql/19/docker for PostgreSQL 19.x). The defined VOLUME was changed in 18 and above to /var/lib/postgresql. Mounts and volumes should be targeted at the updated location. This will allow users upgrading between PostgreSQL major releases to use the faster --link when running pg_upgrade and mounting /var/lib/postgresql.