PostgreSQL使用pg_upgrade 从13升级到14
pg_upgrade 工具可以支持 PostgreSQL 跨版本的就地升级,不需要执行导出和导入操作。pg_upgrade 可以支持 PostgreSQL 8.4.X 到最新版本的升级,包括快照版本和测试版本。
pg_upgrade 提供了升级前的兼容性检查(-c 或者 —check 选项)功能,可以发现插件、数据类型不兼容等问题。如果指定了—link 选项,新版本服务可以直接使用原有的数据库文件而不需要执行复制,通常可以在几分钟内完成升级操作。
本次文档主要记录的是版本13.5到14.1的升级演示
01 PG 13环境检查
1、环境变量检查
[postgres@lyp ~]$ cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export PGHOME=/opt/pgsql13.5
export PGDATA=/home/postgres/pgdata
export PGUSER=postgres
export PGPORT=5433
export PATH=$HOME/bin:$PGHOME/bin:$PATH
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
[postgres@lyp ~]$
2、数据库版本检查
[postgres@lyp ~]$ psql
psql (13.5)
Type "help" for help.
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 13.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)
postgres=#
3、模拟数据
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------------+-------+----------
public | emp | table | postgres
(1 rows)
postgres=# select count(*) from emp;
count
---------
1100000
(1 row)
postgres=#
02 PG 14环境安装
1、解压安装包
[root@lyp ~]# tar -zxvf postgresql-14.1.tar.gz
[root@lyp ~]# ll postgresql-14.1
total 756
-rw-r--r--. 1 1107 1107 490 Nov 9 05:58 aclocal.m4
drwxrwxrwx. 2 1107 1107 4096 Nov 9 06:10 config
-rwxr-xr-x. 1 1107 1107 580807 Nov 9 05:58 configure
-rw-r--r--. 1 1107 1107 83288 Nov 9 05:58 configure.ac
drwxrwxrwx. 58 1107 1107 4096 Nov 9 06:10 contrib
-rw-r--r--. 1 1107 1107 1192 Nov 9 05:58 COPYRIGHT
drwxrwxrwx. 3 1107 1107 87 Nov 9 06:10 doc
-rw-r--r--. 1 1107 1107 4259 Nov 9 05:58 GNUmakefile.in
-rw-r--r--. 1 1107 1107 277 Nov 9 05:58 HISTORY
-rw-r--r--. 1 1107 1107 63953 Nov 9 06:11 INSTALL
-rw-r--r--. 1 1107 1107 1665 Nov 9 05:58 Makefile
-rw-r--r--. 1 1107 1107 1213 Nov 9 05:58 README
drwxrwxrwx. 16 1107 1107 4096 Nov 9 06:11 src
[root@lyp ~]#
[root@lyp ~]# mv postgresql-14.1 /opt/pgsql14.1
[root@lyp ~]#
2、编译安装
[root@lyp ~]# cd /opt/pgsql14.1/
[root@lyp pgsql14.1]# ./configure --prefix=/opt/pgsql14.1
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
......
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
[root@lyp pgsql14.1]#
[root@lyp pgsql14.1]# gmake world
gmake -C ./src/backend generated-headers
gmake[1]: Entering directory `/opt/pgsql14.1/src/backend'
......
gmake[2]: Leaving directory &