数据库升级流程
Pg数据库小版本升级只需要升级程序
1、上传安装包
[root@WEB setup]# ls -ltr
total 11097172
-rwxrwxr-x. 1 postgres postgres 29294939 Mar 19 21:18 postgresql-18.1.tar.gz
-rw-r--r-- 1 root root 11304716288 Aug 7 09:02 OracleLinux-R10-U2-x86_64-dvd.iso
-rw-r--r-- 1 postgres postgres 29477735 Aug 7 09:05 postgresql-18.4.tar.gz
drwxr-xr-x. 7 postgres postgres 4096 Aug 7 18:23 postgresql-18.1
2、解压
[root@WEB setup]# chown postgres:postgres postgresql-18.4.tar.gz
[root@WEB setup]# su - postgres
Last login: Fri Aug 7 19:29:30 CST 2026 on pts/0
[postgres@WEB ~]$ cd /pg18/setup/
[postgres@WEB setup]$ tar -xvf postgresql-18.4.tar.gz
3、去原版本软件目录获取编译选项
[postgres@WEB ~]$ cd /pg18/setup/postgresql-18.1/src/bin/pg_config/
[postgres@WEB pg_config]$ ./pg_config --configure
'--prefix=/pg18/soft' '--with-openssl' '--with-pgport=5432' '--with-tcl' '--with-perl' '--with-python' '--with-libxml' '--with-libxslt' '--with-uuid=e2fs' '--with-pam' '--with-ldap'
[postgres@WEB pg_config]$
4、前往18.4软件目录下重新configure
[postgres@WEB pg_config]$ cd /pg18/setup/postgresql-18.4/
[postgres@WEB postgresql-18.4]$ ./configure --prefix=/pg18/soft --with-openssl --with-pgport=5432 --with-tcl --with-perl --with-python --with-libxml --with-libxslt --with-uuid=e2fs --with-pam --with-ldap
5、make
[postgres@WEB postgresql-18.4]$ gmake world -j 6
6、关闭数据库
[postgres@WEB postgresql-18.4]$ exit
logout
[root@WEB setup]# systemctl stop postgresql.service
7、备份18.1软件目录
[root@WEB setup]# cd /pg18/
[root@WEB pg18]# tar -zcf pg18_1.tar.gz soft/
[root@WEB pg18]# ls -ltr
total 15192
drwxr-xr-x. 6 postgres postgres 56 Aug 7 18:21 soft
drwx------. 19 postgres postgres 4096 Aug 7 22:18 data
drwxrwxr-x. 4 postgres postgres 112 Aug 7 22:21 setup
-rw-r--r-- 1 root root 15549568 Aug 7 22:21 pg18_1.tar.gz
8、安装18.4软件
[root@WEB pg18]# su - postgres
Last login: Fri Aug 7 22:10:02 CST 2026 on pts/0
[postgres@WEB ~]$ cd /pg18/setup/postgresql-18.4/
[postgres@WEB postgresql-18.4]$ gmake install-world
9、启动数据库并检查
[postgres@WEB postgresql-18.4]$ exit
logout
[root@WEB pg18]# systemctl start postgresql.service
[root@WEB pg18]# systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Loaded: loaded (/etc/systemd/system/postgresql.service; enabled; preset: 5:185mdisabled)
Active: active (running) since Fri 2026-08-07 22:25:53 CST; 5s ago
Invocation: 467acbb705254b0fbddaad86488a41e7
Process: 16378 ExecStart=/pg18/soft/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
Main PID: 16380 (postgres)
Tasks: 9 (limit: 47697)
Memory: 26.6M (peak: 27.5M)
CPU: 51ms
CGroup: /system.slice/postgresql.service
├─16380 /pg18/soft/bin/postgres -D /pg18/data -p 5432
├─16381 "postgres: io worker 0"
├─16382 "postgres: io worker 1"
├─16383 "postgres: io worker 2"
├─16384 "postgres: checkpointer "
├─16385 "postgres: background writer "
├─16387 "postgres: walwriter "
├─16388 "postgres: autovacuum launcher "
└─16389 "postgres: logical replication launcher "
Aug 07 22:25:53 WEB systemd[1]: Starting postgresql.service - PostgreSQL database server...
Aug 07 22:25:53 WEB pg_ctl[16380]: 2026-08-07 22:25:53.089 CST [16380] LOG: starting PostgreSQL 18.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7), 64-bit
Aug 07 22:25:53 WEB pg_ctl[16380]: 2026-08-07 22:25:53.089 CST [16380] LOG: listening on IPv6 address "::1", port 5432
Aug 07 22:25:53 WEB pg_ctl[16380]: 2026-08-07 22:25:53.089 CST [16380] LOG: listening on IPv4 address "127.0.0.1", port 5432
Aug 07 22:25:53 WEB pg_ctl[16380]: 2026-08-07 22:25:53.091 CST [16380] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
Aug 07 22:25:53 WEB pg_ctl[16386]: 2026-08-07 22:25:53.094 CST [16386] LOG: database system was shut down at 2026-08-07 22:18:37 CST
Aug 07 22:25:53 WEB pg_ctl[16380]: 2026-08-07 22:25:53.097 CST [16380] LOG: database system is ready to accept connections
Aug 07 22:25:53 WEB systemd[1]: Started postgresql.service - PostgreSQL database server.
[root@WEB pg18]# su - postgres
Last login: Fri Aug 7 22:23:13 CST 2026 on pts/0
[postgres@WEB ~]$ psql
psql (18.4)
Type "help" for help.
postgres=# select version();
version
----------------------------------------------------------------------------------------------------------
PostgreSQL 18.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7), 64-bit
(1 row)
postgres=#
数据库已经升级到18.4版本
|