PostgreSQL大版本升级pg(2)


#多实例的停止数据服务(升级前需要停止数据库服务)
Darren2:postgres:/usr/local/pgsql:>/usr/local/pgsql/pgsql9.5.9/bin/pg_ctl stop -m fast -D /usr/local/pgsql/pgsql9.5.9/data
Darren2:postgres:/usr/local/pgsql:>/usr/local/pgsql/pgsql9.6.5/bin/pg_ctl stop -m fast -D /usr/local/pgsql/pgsql9.6.5/data


pg_upgrade参数解析
-b, --old-bindir=BINDIR      old cluster executable directory
-B, --new-bindir=BINDIR      new cluster executable directory
-d, --old-datadir=DATADIR    old cluster data directory
-D, --new-datadir=DATADIR    new cluster data directory
-p, --old-port=PORT          old cluster port number (default 50432)
-P, --new-port=PORT          new cluster port number (default 50432)
-c, --check                  check clusters only, don't change any data
-j, --jobs                    number of simultaneous processes or threads to use
-k, --link                    link instead of copying files to new cluster
-r, --retain                  retain SQL and log files after success
-U, --username=NAME          cluster superuser (default "postgres")
-v, --verbose                enable verbose internal logging


pg_upgrade有两种升级方式,一个是缺省的通过拷贝数据文件到新的data目录下,一个是创建硬链接。拷贝的方式升级较慢,但是原库还可用;硬链接的方式升级较快,但是原库不可用。


使用9.6.5的pg_upgrade检测兼容性
Darren2:postgres:/usr/local/pgsql:>/usr/local/pgsql/pgsql9.6.5/bin/pg_upgrade -b /usr/local/pgsql/pgsql9.5.9/bin -B /usr/local/pgsql/pgsql9.6.5/bin -d /usr/local/pgsql/pgsql9.5.9/data -D /usr/local/pgsql/pgsql9.6.5/data -p 5432 -P 5431 -U postgres -j 8 -k -c
Performing Consistency Checks
-----------------------------
Checking cluster versions                                  ok
Checking database user is the install user                  ok
Checking database connection settings                      ok
Checking for prepared transactions                          ok
Checking for reg* system OID user data types                ok
Checking for contrib/isn with bigint-passing mismatch      ok
Checking for roles starting with 'pg_'                      ok
Checking for presence of required libraries                ok
Checking database user is the install user                  ok
Checking for prepared transactions                          ok


正式升级
Darren2:postgres:/usr/local/pgsql:>/usr/local/pgsql/pgsql9.6.5/bin/pg_upgrade -b /usr/local/pgsql/pgsql9.5.9/bin -B /usr/local/pgsql/pgsql9.6.5/bin -d /usr/local/pgsql/pgsql9.5.9/data -D /usr/local/pgsql/pgsql9.6.5/data -p 5432 -P 5431 -U postgres -j 8 -k -r -v
......
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
    ./analyze_new_cluster.sh
Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh


#生成2个脚本, 用于收集统计信息和删除老集群,和一些有关升级过程的日志信息
Darren2:postgres:/usr/local/pgsql:>ls -ltr
-rw-r--r--. 1 postgres dba  2215 Oct 18 01:37 pg_upgrade_dump_globals.sql
-rw-------. 1 postgres dba  2237 Oct 18 01:37 pg_upgrade_dump_13241.custom
-rw-------. 1 postgres dba  2228 Oct 18 01:37 pg_upgrade_dump_1.custom
-rw-------. 1 postgres dba  3733 Oct 18 01:37 pg_upgrade_dump_16386.custom
-rw-------. 1 postgres dba  2422 Oct 18 01:37 pg_upgrade_dump_13241.log
-rw-------. 1 postgres dba  2409 Oct 18 01:37 pg_upgrade_dump_1.log
-rw-------. 1 postgres dba  2686 Oct 18 01:37 pg_upgrade_dump_16386.log
-rw-------. 1 postgres dba 240810 Oct 18 01:37 pg_upgrade_utility.log
-rwx------. 1 postgres dba    112 Oct 18 01:37 delete_old_cluster.sh
-rwx------. 1 postgres dba    809 Oct 18 01:37 analyze_new_cluster.sh
-rw-------. 1 postgres dba  2956 Oct 18 01:37 pg_upgrade_server.log
-rw-------. 1 postgres dba  42227 Oct 18 01:37 pg_upgrade_internal.log


#启动新的数据库集群
Darren2:postgres:/usr/local/pgsql:>/usr/local/pgsql/pgsql9.6.5/bin/pg_ctl start -D /usr/local/pgsql/pgsql9.6.5/data

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a8b82c3567b03ec0e287e0274dc2d7a2.html