首页 > 其他分享 >pg升级(pg14-pg15)主从环境

pg升级(pg14-pg15)主从环境

时间:2024-05-15 11:10:05浏览次数:13  
标签:ok root pg14 pg15 pg new data

环境:
OS:Centos 7
旧版本的db:pg14
新版本的db:pg15
升级策略:必须先升级主库,然后重做从库

 

1.查看主库安装的插件

-bash-4.2$ psql -h localhost -U postgres -p5432
psql (14.11)
Type "help" for help.

postgres=# \dx
                                                                       List of installed extensions
             Name             | Version |   Schema   |                                                     Descriptio
n                                                     
------------------------------+---------+------------+---------------------------------------------------------------
------------------------------------------------------
 address_standardizer         | 3.3.3   | public     | Used to parse an address into constituent elements. Generally 
used to support geocoding address normalization step.
 address_standardizer_data_us | 3.3.3   | public     | Address Standardizer US dataset example
 dblink                       | 1.2     | public     | connect to other PostgreSQL databases from within a database
 fuzzystrmatch                | 1.1     | public     | determine similarities and distance between strings
 mysql_fdw                    | 1.2     | public     | Foreign data wrapper for querying a MySQL server
 plpgsql                      | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis                      | 3.3.3   | public     | PostGIS geometry and geography spatial types and functions
 postgis_raster               | 3.3.3   | public     | PostGIS raster types and functions
 postgis_sfcgal               | 3.3.3   | public     | PostGIS SFCGAL functions
 postgis_tiger_geocoder       | 3.3.3   | tiger      | PostGIS tiger geocoder and reverse geocoder
 postgis_topology             | 3.3.3   | topology   | PostGIS topology spatial types and functions
 postgres_fdw                 | 1.1     | public     | foreign-data wrapper for remote PostgreSQL servers
(12 rows)

安装的插件有:
mysql_fdw
postgis

 

2.查看数据库版本

postgres=# select version();
                                                 version                                                  
----------------------------------------------------------------------------------------------------------
 PostgreSQL 14.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)

 

3.安装新版本的pg
我这里安装pg15,确保新版本的pg可以正常运行
具体安装方法参考如下连接(只参考安装pg部分,插件部分不需要安装)
https://www.cnblogs.com/hxlasky/p/16846972.html
我这里上pg13的例子,替换成安装pg15即可

 

3.1 创建数据存储目录
[root@localhost bin]#mkdir -p /opt/pg15/data
[root@localhost bin]#mkdir -p /opt/pg15/log
[root@localhost bin]#mkdir -p /opt/pg15/archivelog
[root@localhost bin]#chown -R postgres:postgres /opt/pg15
[root@localhost bin]#chmod 0700 /opt/pg15/data

 

3.2 安装
[root@dsc1 pg15]#rpm -ivh postgresql15-libs-15.6-1PGDG.rhel7.x86_64.rpm
[root@dsc1 pg15]#rpm -ivh postgresql15-15.6-1PGDG.rhel7.x86_64.rpm
[root@dsc1 pg15]#rpm -ivh postgresql15-server-15.6-1PGDG.rhel7.x86_64.rpm
[root@dsc1 pg15]#rpm -ivh postgresql15-contrib-15.6-1PGDG.rhel7.x86_64.rpm

 

 

3.3 初始化数据库
su - postgres
/usr/pgsql-15/bin/initdb -D /opt/pg15/data

 

3.4 修改系统服务启动参数
su - root
[root@localhost postgresql-15.service.d]# ls -al /usr/lib/systemd/system/postgresql-15.service
-rw-r--r--. 1 root root 1764 Aug 10 06:06 /usr/lib/systemd/system/postgresql-15.service

vi /usr/lib/systemd/system/postgresql-15.service
修改为Environment=PGDATA=/opt/pg15/data/

到这里可以尝试启动新版本的数据库,但是需要修改端口号(其他参数不修改),不能与原来的一样,否则报错

比如我这里修改成如下:
su - postgres
vi /opt/pg15/data/postgresql.conf
port = 15432

 

3.5 尝试启动
[root@localhost]#systemctl daemon-reload
[root@localhost]#systemctl start postgresql-15
确定可以启动后,将上面修改的参数修改回来,port = 5432

这里确保新版本的pg要正常启动.

 

########################升级主库处理###########################
1.停掉新旧版本的数据库
[root@localhost ~]#systemctl stop postgresql-14
[root@localhost ~]#systemctl stop postgresql-15

 

2.升级检查
使用新版本的pg_upgrade进行升级

 

su - postgres
-bash-4.2$ /usr/pgsql-15/bin/pg_upgrade --old-datadir /opt/pg14/data/ --new-datadir /opt/pg15/data --old-bindir /usr/pgsql-14/bin/ --new-bindir /usr/pgsql-15/bin/ --check
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 presence of required libraries                 fatal

Your installation references loadable libraries that are missing from the
new installation.  You can add these libraries to the new installation,
or remove the functions using them from the old installation.  A list of
problem libraries is in the file:
    /opt/pg15/data/pg_upgrade_output.d/20240514T162609.626/loadable_libraries.txt

Failure, exiting
-bash-4.2$ more /opt/pg15/data/pg_upgrade_output.d/20240514T162609.626/loadable_libraries.txt
could not load library "$libdir/mysql_fdw": ERROR:  could not access file "$libdir/mysql_fdw": No such file or directory
In database: postgres
could not load library "$libdir/postgis-3": ERROR:  could not access file "$libdir/postgis-3": No such file or directory
In database: postgres
could not load library "$libdir/postgis_raster-3": ERROR:  could not access file "$libdir/postgis_raster-3": No such file or directory
In database: postgres
could not load library "$libdir/postgis_sfcgal-3": ERROR:  could not access file "$libdir/postgis_sfcgal-3": No such file or directory
In database: postgres
could not load library "$libdir/postgis_topology-3": ERROR:  could not access file "$libdir/postgis_topology-3": No such file or directory
In database: postgres
could not load library "$libdir/address_standardizer-3": ERROR:  could not access file "$libdir/address_standardizer-3": No such file or directory
In database: postgres

 

这里原因是安装的插件没有升级导致的,下面进行插件的升级

 

升级mysql_fdw和postgis插件:
[root@localhost extension]#yum list mysql_fdw*
[root@dsc1 ~]#yum install mysql_fdw_15.x86_64

[root@localhost extension]#yum list postgis*
[root@localhost extension]#yum install postgis33_15.x86_64

 

4.拷贝旧版本的配置文件到新版
su - postgres
cp /opt/pg14/data/pg_hba.conf /opt/pg15/data/
cp /opt/pg14/data/postgresql.conf /opt/pg15/data/

拷贝过去注意修改如下配置项postgresql.conf
log_directory = '/opt/pg15/log'
archive_command = 'DATE=`date +%Y%m%d`;DIR="/opt/pg15/archivelog/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f

 

5.执行升级

su - postgres
/usr/pgsql-15/bin/pg_upgrade --old-datadir /opt/pg14/data/ --new-datadir /opt/pg15/data --old-bindir /usr/pgsql-14/bin/ --new-bindir /usr/pgsql-15/bin/

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
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-15/bin/vacuumdb --all --analyze-in-stages

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh
    
我这里没有执行建议执行的2个命令
/usr/pgsql-15/bin/vacuumdb --all --analyze-in-stages 
./delete_old_cluster.sh

脚本内容:
-bash-4.2$ more delete_old_cluster.sh
#!/bin/sh

rm -rf '/opt/pg14/data'

 

6.启动新版本数据库
[root@localhost ~]#systemctl start postgresql-15

 

7.这个时候查看主从情况
-bash-4.2$ psql -h localhost -U postgres -p5432
postgres=# \x on
Expanded display is on.
postgres=# select * from pg_stat_replication;

 

发现从库报错误:

从库的日志:
2024-05-14 16:56:43 CST [9519]: [1-1] user=,db=,app=,client=FATAL:  database system identifier differs between the primary and standby
2024-05-14 16:54:23 CST [9466]: [2-1] user=,db=,app=,client=DETAIL:  The primary's identifier is 7368767584432480743, the standby's identifier is 7368670560794476245.

 

这个时候需要对重库重做了.

 

标签:ok,root,pg14,pg15,pg,new,data
From: https://www.cnblogs.com/hxlasky/p/18193454

相关文章

  • 基于肤色模型的人脸识别FPGA实现,包含tb测试文件和MATLAB辅助验证
    1.算法运行效果图预览matlab2022a的测试结果如下:   vivado2019.2的仿真结果如下:   将数据导入到matlab中,   系统的RTL结构图如下图所示:   系统包括中值滤波,RGB转换为ycbcr,人脸检测三个模块 2.算法运行软件版本vivado2019.2 matlab2022a......
  • 通过LCD屏幕显示开机动画(将gif图片转为逐帧JPG图片)
    /**@filename: main.c@brief通过LCD屏幕显示开机动画@[email protected]@date2024/05/[email protected]:版本@property:属性介绍@note补充注意说明CopyRight(c)[email protected]*/#include<stdio.h>#incl......
  • 文件IO完成libjpeg库的移植,并设计程序实现在LCD上的任意位置显示一张任意大小的jpg图
    文件IO:完成libjpeg库的移植,并设计程序实现在LCD上的任意位置显示一张任意大小的jpg图片,注意不要越界。1.库的移植1.下载需要移植的库的源码包,libjpeg库源码包在官网可以下载www.ijg.org2.解压压缩包,解压后找到自述文件README,打开README了解libjpeg库的使用规则!3.打开源码包......
  • FPGA/EDA实验箱-竞赛普及版(ALTERA)
    型号:XQEP4CE-TEBV6.11、产品概述FPGA/EDA实验箱是一款FPGA教学实验系统,由FPGA开发板、显示屏、下载器、应用模块及相关实验配件组成;FPGA开发板采用底板+核心板的设计架构,核心板板采用是六层PCB设计,采用大容量管脚更多的BGA封装,F484封装,使整个核心板的性能和稳定性有了很大的提......
  • jpg图片的解压
    IO编程jpg图片的解压在完成jpg图片的解压之前,我们先得了解到libjpeg库的正确移植1.下载需要移植的库的源码包,libjpeg库源码包在官网可以下载www.ijg.org2.解压压缩包,解压后找到自述文件README,打开README了解libjpeg库的使用规则以下就是看了README才知道执行的步骤,很多库......
  • 在LCD上的任意位置显示一张任意大小的jpg图片
    /***************************************************filename:lcdshowjpg.c*author:[email protected]*date:2024/05/13*brief:完成libjpeg库的移植,并设计程序实现在LCD上的任意位置显示一张任意大小的jpg图片,注意不要越界。*note:......
  • WDS+MDT网络启动自动部署windows(二十)MDT upgrade任务序列
    WDS+MDT网络启动自动部署windows(十九)MDTreplace任务序列 简介#MDT的默认任务序列有很多个,我们不能只盯着标准客户序列啊, 不管用不用,我替你们测试一下replace upgrade两个标准序列。sysprepandcapture,这个是做胖镜像的,终端机祛除各种信息,然后抓镜像回来的,介绍的很多......
  • 基于FPGA的贪吃蛇游戏 之代码解析
    基于FPGA的贪吃蛇游戏之代码解析1. 代码结构代码结构包含7格.v文件。  下面依次解析。   2. 代码解析(1) seg_display.v数码管的译码模块是最熟悉,最简单的模块了。这里是共阳极的数码管,用case语句编码即可。从上图可以看到,这个模块被例化了3次,分别驱动3个数码......
  • Python执行PG数据库查询语句:以Markdown格式打印查询结果
    哈喽,大家好,我是木头左!1.准备工作在开始之前,需要确保已经安装了psycopg2和pandas这两个Python库。psycopg2是Python的一个PostgreSQL数据库适配器,用于连接和操作PostgreSQL数据库。而pandas则是一个强大的数据处理库,将用它来处理查询结果并以Markdown格式打印。pipinstallp......
  • JPA使用pg数据库时,bool字段不能跨库迁移的解决方案
    首先,大多数人的印象里,hibernate作为一个笨重学习成本高的近乎全自动的框架它的优点就是可以支持很多数据库,但是最近研究发现,java中的boolean类型的字段,在mariadb/mysql中为bit0/1,在sqlserver/oracle中为bit0/1numeric(1,0)check*in(0,1),然而在PG数据库中却是bool,因为pg......