您的位置:首页 > 博客中心 > 数据库 >

postgresql 9.3 升级至 9.4

时间:2022-03-14 09:30

前言: 

postgresql的升级方式有两种 一种是使用 pg_dumpall 备份后 导入至新版本即可。

另一种就是本文使用pg_upgrade方式升级 是从文件级别将 老的数据库文件 复制至新的版本中 


注意:

升级前请备份重要数据 最好在测试环境测试后再升级 

环境:

  系统: centos6.x x86 已安装 postgresql 9.3 

  

升级步骤:

 首先安装postgresql 9.4

一 、安装9.4的yum源

yum install -y http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm


二、安装postgresql 9.4

yum install -y postgresql94-server postgresql94-contrib


   初始化数据库

/etc/init.d/postgresql-9.4 initdb


三、开始升级

   首先 需要关掉postgresql9.3 

/etc/init.d/postgresql-9.3 stop


  切换至postgres 用户

 su - postgres


   执行升级命令

/usr/pgsql-9.4//bin/pg_upgrade -v -d /var/lib/pgsql/9.3/data/  -D /var/lib/pgsql/9.4/data/  -b /usr/pgsql-9.3/bin/  -B /usr/pgsql-9.4/bin/

   选项:  -b 老版本bin目录

           -B 新版本目录

           -d 老版本data目录

           -D 新版本data目录

   升级成功后会提示如下信息:

 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

    切换到root 启动9.4 

/etc/init.d/postgresql-9.4 start

   切换到postgres 执行如下脚本

sh analyze_new_cluster.sh

   删除老版本数据目录(可选)

sh delete_old_cluster.sh

最后:

   数据的升级到此就结束了,不过若你更改过pg_hba.conf 或者其它配置文件 别忘记去新版本中更改



参考:  

pg_dumpall 升级见:  

postgresql 源: 

postgresql 9.3 安装见 

本类排行

今日推荐

热门手游