数据库进行升级,是一个再正常不过的功能,比如功能的需要,遇到BUG,安全漏洞等等,具体升级包含子版本升级,主版本升级。如果用过ORACLE的朋友,一定知道,在ORACLE中,如果要实现大版本的升级,比如从11g,升级到19c,一般使用的dbua来完成,并且标准的升级,一定会有数据库停机时间,小版本的升级,如19.3,升级到19.24 ,使用OPATCH 工具来完成,一样需要停数据库。
那对于PG,一样也存在升级,如果是小版本升级,比如12.0 升级到12.19 ,直接使用二进制文件替换即可,如果是大版本升级,一般使用 pg_upgrade来完成,当然,如果时间允许,也可以使用pg_dumpall也行。只是时间要长一些。
关于PG_UPGRADE的使用,可以参见官方文档:PostgreSQL: Documentation: 16: pg_upgrade
部分截图如下:



PG_UPGRADE 的用法:
pg_upgrade -b oldbindir [-B newbindir] -d oldconfigdir -D newconfigdir [option...]
目前pg_upgrade 支持从 9.2.x 到目前最新的版本,甚至BETA版本。
下面我们以一个升级案例来说明:
目录
1.升级环境
源版本:pg 12.0
PGHOME=/u01/app/postgres/product/12.0/dbhome_1
PGDATA=/u01/app/postgres/product/pgdata_12
PORT=5432
目标版本:pg 16.3
PGHOME=/u01/app/postgres/product/16.3/dbhome_1
PGDATA=/u01/app/postgres/product/pgdata
PORT=5432
操作系统:OpenEuler 24.03
sztechdb=# select * from version();
version
-----------------------------------------------------------------------------------------------------------
PostgreSQL 12.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 12.3.1 (openEuler 12.3.1-30.oe2403), 64-bit
(1 row)








2.源码安装新版本16.3
这个步骤,可以参见前面的文档:https://blog.youkuaiyun.com/cqsztech/article/details/140748640
如果源端有额外的插件,需要安装
这里安装,只需要到 initdb即可,不需要打开
postgres@openeuler2403 bin]$ ./initdb --pgdata=/u01/app/postgres/pgdata -U postgres
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 "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
fixing permissions on existing directory /u01/app/postgres/pgdata ... 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/Shanghai
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 /u01/app/postgres/pgdata -l logfile start

3.关闭源和目标数据库
把源和目标数据库都关闭。
[postgres@openeuler2403 pgdata_12]$ pg_ctl stop
waiting for server to shut down.... done
&

最低0.47元/天 解锁文章
2651

被折叠的 条评论
为什么被折叠?



