重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1044|回复: 0
打印 上一主题 下一主题

PG13升级PG14

[复制链接]
跳转到指定楼层
楼主
发表于 2021-10-10 21:58:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.环境说明
   操作系统:ROCKY LINUX 8.4
   升级前版本为:pg13.4
   升级到:PG14.0

    PG 13.4 软件位置:/usr/pgsql-13/bin
                数据文件位置:/var/lib/pgsql/13/data
    PG 14.0 软件位置:/usr/pgsql-14/bin
                数据文件位置:/pgdata/data

2.安装新版本
  方法略

3.初始化新版本数据库
    su - postgres
    cd /usr/pgsql-14/bin
    ./initdb --wal-segsize=16 -D /pgdata/data/   


4.检擦是否可以升级
    cd /tmp
    mkdir upgrade_log
    cd upgrade_log
    /usr/pgsql-14/bin/pg_upgrade -c --link -b /usr/pgsql-13/bin -B /usr/pgsql-14/bin -d /var/lib/pgsql/13/data -D /pgdata/data


  Performing Consistency Checks on Old Live Server
------------------------------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for system-defined composite types in user tables  ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for user-defined encoding conversions              ok
Checking for user-defined postfix operators                 ok
Checking for presence of required libraries                 ok
Checking database user is the install user                  ok
Checking for prepared transactions                          ok
Checking for new cluster tablespace directories             ok

*Clusters are compatible*

5.开始升级

       关闭旧版本数据库
       systemctl stop postgresql-13.service

      COPY方式升级
      /usr/pgsql-14/bin/pg_upgrade -b /usr/pgsql-13/bin -B /usr/pgsql-14/bin -d /var/lib/pgsql/13/data -D /pgdata/data

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 system-defined composite types in user tables  ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for user-defined encoding conversions              ok
Checking for user-defined postfix operators                 ok
Creating dump of global objects                             ok
Creating dump of database schemas
                                                            ok
Checking for presence of required libraries                 ok
Checking database user is the install user                  ok
Checking for prepared transactions                          ok
Checking for new cluster tablespace directories             ok

If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.

Performing Upgrade
------------------
Analyzing all rows in the new cluster                       ok
Freezing all rows in the new cluster                        ok
Deleting files from new pg_xact                             ok
Copying old pg_xact to new server                           ok
Setting oldest XID for new cluster                          ok
Setting next transaction ID and epoch for new cluster       ok
Deleting files from new pg_multixact/offsets                ok
Copying old pg_multixact/offsets to new server              ok
Deleting files from new pg_multixact/members                ok
Copying old pg_multixact/members to new server              ok
Setting next multixact ID and offset for new cluster        ok
Resetting WAL archives                                      ok
Setting frozenxid and minmxid counters in new cluster       ok
Restoring global objects in the new cluster                 ok
Restoring database schemas in the new cluster
                                                            ok
Copying user relation files
                                                            ok
Setting next OID for new cluster                            ok
Sync data directory to disk                                 ok
Creating script to delete old cluster                       ok
Checking for extension updates                              ok

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
    /usr/pgsql-14/bin/vacuumdb --all --analyze-in-stages

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh

6.修改环境变量

    su - postgres
   vim .bash_profile
    export PGDATA=/pgdata/data
    export PGHOME=/usr/pgsql-14
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
    export PATH=$PATH:$PGHOME/bin/      

7.修改postgresql.conf和pg_hba.conf文件

8.验证一下版本
  postgres=# select version();
                                                version                                                
--------------------------------------------------------------------------------------------------------
PostgreSQL 14.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
(1 row)


9.创建系统服务
     vim /etc/systemd/system/postgresql-14.service
      [Unit]
     Description=PostgreSQL database server
     Documentation=man:postgres(1)
     After=network.target
     [Service]
     Type=forking
     User=pgsql
     Group=pgsql
     Environment=PGPORT=5432
     Environment=PGDATA=/pgdata/data
     OOMScoreAdjust=-1000
     ExecStart=/usr/pgsql-14/bin/pg_ctl start -D ${PGDATA} -s -o '-p ${PGPORT}' -w -t 300
     ExecStop=/usr/pgsql-14/bin/pg_ctl stop -D ${PGDATA} -s -m fast
     ExecReload=/usr/pgsql-14/bin/pg_ctl reload -D ${PGDATA} -s
     KillMode=mixed
     KillSignal=SIGINT
     TimeoutSec=0
    [Install]
     WantedBy=multi-user.target

    --让修改生效
    # systemctl daemon-reload

    # systemctl enable postgresql-14


到此,PG13,升级到PG14完成。

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-4-19 11:15 , Processed in 0.083267 second(s), 19 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表