首页 > 数据库 >PostgreSQL数据库大版本升级

PostgreSQL数据库大版本升级

时间:2024-09-15 13:51:41浏览次数:3  
标签:opt ok Checking 数据库 版本升级 user new PostgreSQL app

  1. 简介

该文档中描述的方式针对源码安装的数据进行升级

  1. 操作过程
1. 说明
	a. 当前数据库版本为11.22,升级后为15.8
2. 备份原数据库
3. 安装目标版本
  [root@olinux73_model sws]# tar -zxf postgresql-15.8.tar.gz
  [root@olinux73_model sws]# cd postgresql-15.8/
  [root@olinux73_model postgresql-15.8]# mkdir -p /opt/app/pg15
  [root@olinux73_model postgresql-15.8]# chown -R postgres:postgres /opt/app/pg15
  [root@olinux73_model postgresql-15.8]# ./configure --prefix=/opt/app/pg15 --with-pgport=5432 --with-openssl  --with-blocksize=32 --with-readline
  [root@olinux73_model postgresql-15.8]# make && make install

  [root@olinux73_model ~]# mkdir /opt/app/pgdata
  [root@olinux73_model ~]# chown -R postgres:postgres /opt/app/pgdata/

  [root@olinux73_model postgresql-15.8]# su - postgres 
  -bash-4.2$  /opt/app/pg15/bin/initdb  -D /opt/app/pgdata -U postgres

4. 兼容性测试
  [root@olinux73_model pg_backup]# systemctl stop  postgresql.service 
  -bash-4.2$ /opt/app/pg15/bin/pg_upgrade --old-datadir=/u01/app/pgdata --new-datadir /opt/app/pgdata --old-bindir /u01/app/pgsql/bin --new-bindir /opt/app/pg15/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 removed "abstime" data type in user tables     ok
  Checking for removed "reltime" data type in user tables     ok
  Checking for removed "tinterval" data type in user tables   ok
  Checking for user-defined encoding conversions              ok
  Checking for user-defined postfix operators                 ok
  Checking for incompatible polymorphic functions             ok
  Checking for tables WITH OIDS                               ok
  Checking for invalid "sql_identifier" user columns          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. 执行升级
  -bash-4.2$ /opt/app/pg15/bin/pg_upgrade --old-datadir=/u01/app/pgdata --new-datadir /opt/app/pgdata --old-bindir /u01/app/pgsql/bin --new-bindir /opt/app/pg15/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
  Checking for removed "abstime" data type in user tables     ok
  Checking for removed "reltime" data type in user tables     ok
  Checking for removed "tinterval" data type in user tables   ok
  Checking for user-defined encoding conversions              ok
  Checking for user-defined postfix operators                 ok
  Checking for incompatible polymorphic functions             ok
  Checking for tables WITH OIDS                               ok
  Checking for invalid "sql_identifier" user columns          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:
    /opt/app/pg15/bin/vacuumdb --all --analyze-in-stages

  Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh
6. 修改环境变量
  [root@olinux73_model ~]# vim /home/postgres/.bash_profile
  export PGHOME=/opt/app/pg15
  export PGDATA=/opt/app/pgdata
  export PGPORT=5432
  export PGPASSWORD=123456
  export PATH=$PGHOME/bin:$PATH
  export MANPATH=$PGHOME/share/man:$MANPATH
  export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
  export SCRIPTS_DIR=$SCRIPTS_DIR
  export LANG=en_US.UTF-8
  export DATE=`date +"%Y%m%d%H%M"`

	[root@olinux73_model ~]# source /home/postgres/.bash_profile
7. 启动数据库
  -bash-4.2$   /opt/app/pg15/bin/pg_ctl -D /opt/app/pgdata -l logfile start
  waiting for server to start.... done
  server started
8. 收集统计信息
  -bash-4.2$ /opt/app/pg15/bin/vacuumdb --all --analyze-in-stages
  vacuumdb: processing database "postgres": Generating minimal optimizer statistics (1 target)
  vacuumdb: processing database "template1": Generating minimal optimizer statistics (1 target)
  vacuumdb: processing database "testdb": 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 "testdb": Generating medium optimizer statistics (10 targets)
  vacuumdb: processing database "postgres": Generating default (full) optimizer statistics
  vacuumdb: processing database "template1": Generating default (full) optimizer statistics
  vacuumdb: processing database "testdb": Generating default (full) optimizer statistics
9. 删除旧数据
	-bash-4.2$ ./delete_old_cluster.sh    #会删除老的数据目录
10. 查看数据
  postgres=# \c testdb 
  psql (11.22, server 15.8)
  WARNING: psql major version 11, server major version 15.
       Some psql features might not work.
  You are now connected to database "testdb" as user "postgres".
  testdb=# select * from tb01;
   id | name 
  ----+------
    1 | a
  (1 row)

标签:opt,ok,Checking,数据库,版本升级,user,new,PostgreSQL,app
From: https://blog.51cto.com/ablewang/12023859

相关文章

  • SQL查询技巧:深入解析学生选课系统数据库
            在大学的学生选课系统中,数据库的管理和查询是日常操作中的重要部分。本文通过一系列具体的SQL查询示例,深入解析如何高效地从数据库中获取所需信息,包括学生选课情况、成绩分析、教师课程管理等。系统数据库结构首先,我们有一个包含以下表的数据库:course -存......
  • Elasticsearch和向量数据库的快速入门
    在比较Elasticsearch和向量数据库之前,让我们简要解释它们是什么:什么是Elasticsearch?Elasticsearch是一个流行的开源搜索和分析引擎,建立在ApacheLucene之上。它专为全文搜索、分析和日志分析用例而设计。主要特点:文档导向的NoSQL数据库分布式和可扩展的架构实时搜索和分析无需......
  • 通过脚本自动部署PostgreSQL数据库
    说明该脚本部署的pg数据库为源码通过编译安装的方式执行过程[root@olinux73_model~]#chmod+x./install.sh[root@olinux73_model~]#./install.sh####清理环境####关闭防火墙####关闭Selinuxsetenforce:SELinuxisdisabled####设置PG环境变量PGBASE=/u01/appFILE_CO......
  • StarRocks实时分析数据库的基础与应用
    1.什么是StarRocks?StarRocks是一款开源的在线分析处理(OLAP)数据库,专为实时、低延迟的分析场景而设计。它以其大规模并行处理(MPP)架构和列式存储设计,极大地提高了查询性能和处理效率。通过支持实时数据摄入、快速查询和高并发,StarRocks已经广泛应用于金融、互联网、广告、......
  • 【附源码】网上蛋糕商城系统(源码+数据库+毕业论文+答辩PPT),java开发 springboot框架开
    ......
  • 【附源码】超市管理系统(源码+数据库+毕业论文+答辩ppt齐全)java开发springboot框架vu
    ......
  • 【数据库系统实用教程】 第一章 数据库系统概述
    1.1基本概念1.数据什么是数据:数据是现实世界中客体在计算机中的抽象表示,具体的说,它是一种存储于计算机内的符号串。数据的特性:(1)数据表现形式的多样性(2)数据的可构造性:数据分为结构化数据、半结构化数据和非结构化数据。结构化数据有型(type)和值(value)之分。结构化数......
  • Java 学习路线:语言、框架、中间件与数据库
    Java是一门功能强大、应用广泛的编程语言,适用于企业级应用、Web开发、大数据处理、Android开发等各种场景。这里为大家介绍了一下我认为较为合适的学习路线一、Java基础1.1Java语言基础1.1.1安装JDK和IDE安装JDK:下载JDK:访问Oracle官网,下载最新的JavaDevelopm......
  • MySQL 慢查询日志:解锁数据库性能优化的关键
    在MySQL数据库的使用过程中,性能优化是一个持续的挑战。而慢查询日志就是我们手中的一把利器,能够帮助我们发现和解决性能瓶颈。那么,MySQL中的慢查询日志究竟是什么呢?又该如何使用它来优化性能呢?让我们一起来深入了解。一、慢查询日志的定义与作用慢查询日志是MySQL数据库用来......
  • 数据库连接池与Druid【后端 16】
    数据库连接池与Druid在现代软件开发中,数据库连接池作为一种关键的技术手段,被广泛用于提升数据库访问的效率和稳定性。本文将深入探讨数据库连接池的概念、常见实现,并重点介绍我国阿里集团开源的数据库连接池——Druid,以及如何在项目中切换数据库连接池。什么是数据库连接......