广告
返回顶部
首页 > 资讯 > 数据库 >PostgreSQL升级之pg_upgrade升级
  • 342
分享到

PostgreSQL升级之pg_upgrade升级

2024-04-02 19:04:59 342人浏览 八月长安
摘要

postgresql中的升级,如果针对小版本的升级,比如9.6.1升级到9.6.2(当前的最新版本),只需要用9.6.2版本的软件替换9.6.1版本的软件即可,不需要做额外的操作,因为整个大版本是相互兼容的

postgresql中的升级,如果针对小版本的升级,比如9.6.1升级到9.6.2(当前的最新版本),只需要用9.6.2版本的软件替换9.6.1版本的软件即可,不需要做额外的操作,因为整个大版本是相互兼容的,内部存储形式也是兼容的。但如果涉及到跨大版本升级比如9.4.11升级到9.6.2,这种直接替换软件就不行了,因为跨版本的内部存储形式发生了变化。

官方给了三种升级的方式来解决跨版本升级:

  • pg_dumpall

  • pg_upgrade

  • 通过复制

pg_dumpall是一种把数据从旧版本逻辑导出,再导入新版本的方法,就是一个导出导入的过程。

通过复制的方式是创建一个高版本的从库,等数据同步完后主变备,备变主,达到升级的目的。

再一种是通过pg_upgrade命令的升级方式,它是一种快速升级的方法,通过创建新的系统表并使用旧的用户表的方式进行升级。它又分为两种方式:原地升级和非原地升级,原地升级需要指定--link参数。

下面介绍一下使用pg_upgrade做升级的大体步骤:

示例是从9.4.11升级到9.6.2。

1、安装新版本软件

新版本的软件需要保证与旧版本的软件在配置上兼容,pg_upgrade会在升级前检查pg_controldata,确保所有的设置是兼容的。

2、用新版本初始化一个新的数据库

[postgres@rhel7 ~]$ /opt/pgsql-9.6.2/bin/initdb -D /pgdata-new/
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /pgdata-new ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
perfORMing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /opt/pgsql-9.6.2/bin/pg_ctl -D /pgdata-new/ -l logfile start

3、设置pg_hba.conf,保证pg_upgrade通过连接新旧两个库

4、停止旧库

#创建测试表
[postgres@rhel7 ~]$ psql
psql (9.4.11)
Type "help" for help.
                            ^
postgres=# create table zx (id int);
CREATE TABLE
postgres=# \d 
        List of relations
 Schema | Name | Type  |  Owner   
--------+------+-------+----------
 public | zx   | table | postgres
(1 row)

postgres=# insert into zx values(1);
INSERT 0 1
postgres=# select * from zx;
 id 
----
  1
(1 row)
#停止旧库
[postgres@rhel7 ~]$ /opt/pgsql-9.4/bin/pg_ctl stop -D /usr/local/pgsql/data/
waiting for server to shut down.... done
server stopped

5、使用pg_upgrade执行升级

[postgres@rhel7 ~]$ /opt/pgsql-9.6.2/bin/pg_upgrade -d /usr/local/pgsql/data/ -D /pgdata-new/ -b /opt/pgsql-9.4/bin/ -B /opt/pgsql-9.6.2/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 reg* system OID user data types                ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for roles starting with 'pg_'                      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

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 on the new cluster                        ok
Deleting files from new pg_clog                             ok
Copying old pg_clog to new server                           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 analyze new cluster                      ok
Creating script to delete old cluster                       ok

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

介绍下使用的参数-b指定旧版本软件的bin目录-B指定新版本软件的bin目录,-d指定旧版本对应的数据目录,-D指定新版本对应的数据目录。

6、启动新版本数据库并做检查

[postgres@rhel7 ~]$ /opt/pgsql-9.6.2/bin/pg_ctl start -D /pgdata-new/ -l logfile 
server starting
[postgres@rhel7 ~]$ psql 
psql (9.6.2)
Type "help" for help.

postgres=# \d
        List of relations
 Schema | Name | Type  |  Owner   
--------+------+-------+----------
 public | zx   | table | postgres
(1 row)

postgres=# select * from zx;
 id 
----
  1
(1 row)

7、恢复配置文件如pg_hba.conf、postgresql.conf等

8、收集统计信息

由于升级过程中不会把统计信息传到新库系统表中,需要重新收集统计信息。pg_upgrade的最给出了收集统计信息的脚本:

[postgres@rhel7 ~]$ ./analyze_new_cluster.sh 
This script will generate minimal optimizer statistics rapidly
so your system is usable, and then gather statistics twice more
with increasing accuracy.  When it is done, your system will
have the default level of optimizer statistics.

If you have used ALTER TABLE to modify the statistics target for
any tables, you might want to remove them and restore them after
running this script because they will delay fast statistics generation.

If you would like default statistics as quickly as possible, cancel
this script and run:
    "/opt/pgsql-9.6.2/bin/vacuumdb" --all --analyze-only

vacuumdb: processing database "postgres": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "template1": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "postgres": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "template1": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "postgres": Generating default (full) optimizer statistics
vacuumdb: processing database "template1": Generating default (full) optimizer statistics

Done

9、升级成功后删除旧版本软件和数据。


官方文档:https://www.postgresql.org/docs/9.6/static/pgupgrade.html

Https://www.postgresql.org/docs/9.6/static/upgrading.html


您可能感兴趣的文档:

--结束END--

本文标题: PostgreSQL升级之pg_upgrade升级

本文链接: https://www.lsjlt.com/news/45504.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • PostgreSQL升级之pg_upgrade升级
    PostgreSQL中的升级,如果针对小版本的升级,比如9.6.1升级到9.6.2(当前的最新版本),只需要用9.6.2版本的软件替换9.6.1版本的软件即可,不需要做额外的操作,因为整个大版本是相互兼容的...
    99+
    2022-10-18
  • pg_upgrade大版本升级
    pg_upgrade(1)PostgreSQL提供大版本升级的一个工具,比如说从9.1到9.2,也可以一次跨多个大版本,直接从9.1到9.5等,它的优点是不需要把数据导入导出,这在数据量比较大的时候,非常方...
    99+
    2022-10-18
  • Windows版 PostgreSQL 利用 pg_upgrade 进行大版升级操作方法
    最近 PostgreSQL 15 版本正式发布了,新版本的各种特性和好处本文就不展开介绍了,主要介绍一下 Windows 环境下 PostgreSQL 大版本升级的方法,我们现在的几...
    99+
    2022-11-13
    Windows PostgreSQL升级 Windows PostgreSQL pg_upgrade 升级
  • Windows版 PostgreSQL 利用 pg_upgrade 进行大版升级操作方法
    最近 PostgreSQL 15 版本正式发布了,新版本的各种特性和好处本文就不展开介绍了,主要介绍一下 Windows 环境下 PostgreSQL 大版本升级的方法,我们现在的几个数据库都是运行在 Windows服务...
    99+
    2022-10-19
  • PostgreSQL小版本升级
    我们知道pg_upgrade和pg_dump/pg_restore可以实现大版本升级数据库,那么小版本如何升级,比如从9.6.3到9.6.5?原理:用新版本的软件程序启动,指定老的的数据目录安装pgsql9...
    99+
    2022-10-18
  • Oracle 10g RAC 升级(CPU Update)之--升级CRS
    Oracle 10g RAC 升级(CPU Update)之--升级CRS系统环境:操作系统:RedHat EL5Cluster: Oracle CRS 10.2.0.1.0Oracle: &nb...
    99+
    2022-10-18
  • PostgreSQL Master Slave升级过程
    1.初始状态:Master,slave均为running状态。2.升级过程Master1).关闭 master 记录最后检查点位置 (latest checkpoint location),这是宕机时间开始...
    99+
    2022-10-18
  • mysql升级(物理升级)
    mysql升级是经常要做的工作,整理下升级步骤(物理升级) 1,关闭mysql服务 2,高版本软件覆盖低版本软件(替换掉basedir) 3,赋予新的高版本软件mysql权限 4,使用新的软件开启数据库 5...
    99+
    2022-10-18
  • vSphere5.1升级5.5(一)——升级vCenter Server
    背景介绍某企业原有8台Esxi host组成了一个Cluster,版本为vSphere5.1u2,今年要求将vSphere升级到5.5u3,并要求在虚拟机不中断的情况下完成替换,以下就来介绍该项目的实施计划...
    99+
    2022-10-18
  • 从vSphere 5.5升级到6之2-升级vCenter Server 5.5到6.0
    9.3 升级vCenter Server 5.5到6.0在升级vCenter Server 5.5之前,要检查你的vCenter Server 5.5的虚拟机至少要有8GB内存、2个处理器,如图1-15所示...
    99+
    2022-10-18
  • Oracle Study之--Oracle TimeZone升级
    Oracle Study之--Oracle TimeZone升级http://tiany.blog.51cto.com/513694/1411882  Oracle 10gR2升级到Oracle ...
    99+
    2022-10-18
  • PostgreSQL升级的方法有哪几种
    这篇文章主要介绍“PostgreSQL升级的方法有哪几种”,在日常操作中,相信很多人在PostgreSQL升级的方法有哪几种问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Po...
    99+
    2022-10-18
  • CentOS7 升级openssl版本(升级至3.0.3)
    首先查看本地openssl版本 openssl version 创建一个放源码的目录(按自己习惯) #这里是我的习惯cd /usr/local/src #去官网获取你想要版本的tar压...
    99+
    2023-09-27
    linux 服务器 ubuntu
  • oracle 10 rac 升级 10.2.0.1升级到10.2.0.5
    Oracle Database 10g Release 2 (10.2.0) RAC for RedHat4 Oracle Rac 10.2.0.1升级至10.2.0.5 升级集群件-滚动升级 升级数据...
    99+
    2022-10-18
  • OpenSSH升级
    1、基础准备 官方网站下载最新版*.tar.gz安装包: 官方下载地址:http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/ openssh-9.0p1.tar.gz (注意:要下载p1版...
    99+
    2023-09-18
    服务器 运维
  • python升级
    安装系统后python版本低 需要更新更高版本1wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz1234567tar zxvf Python-2.7.9.tgz./c...
    99+
    2023-01-31
    python
  • MySQL升级
    一、概述 Linux MySQL 5.7二进制 小版本升级,升级前需要备份数据和mysql主配置文件my.cnf 对数据字典的升级数据字典有:mysql、information_schema、perform...
    99+
    2022-10-18
  • gitlab 升级
    gitlab不断的进行迭代更新,所以如果有实用的新功能或严重的bug修复时,必然要考虑gitlab的更新一、下载新版本的RPM包途径1:通过清华开源镜像站:https://mirrors.tuna.tsinghua.edu.cn/gitla...
    99+
    2023-01-30
    gitlab
  • mac 10.13.6 升级至10.14.6再升级至12.4
    mac 10.13.6 升级至10.14.6再升级至12.4 前几天一个月薪35k的兄弟,给我推了一个人工智能学习网站,看了一段时间挺有意思的。包括语音识别、机器翻译等从基础到实战都有,很详细,分享给...
    99+
    2023-10-23
    macos
  • windows微软升级助手怎么升级
    本篇内容主要讲解“windows微软升级助手怎么升级”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“windows微软升级助手怎么升级”吧!升级方法:首先下载微软升级助手。 然后打开,选择“立即升...
    99+
    2023-07-01
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作