你好,游客 登录 注册 搜索
背景:
阅读新闻

Postgres 9.2.4的升级方案与步骤

[日期:2013-04-11] 来源:oschina.net  作者:Kenyon [字体: ]

社区最近推出了Postgres 9.2.4版本,旨在打一个安全补丁,需要做一个升级,升级的步骤文档上也写得较为详细(Part 17),一般有pg_upgrade和dump/restore两种方式,对9.2.0及以上版本采用直接编译安装的方式即可,9.2.0以下版本还需要dump/restore方式,中间会涉及停机操作,做好业务沟通工作。本次升级,数据量较大的版本是9.2.0,其他小版本的数据量相对不大,故采用后一种方式升级。

步骤 :

1.备份
pg_dump -h 192.168.2.150 -p 5432 -U postgres -b -Fp  db_www.linuxidc.com  -f db.bak
安全起见,备份出来的文件检查一下是否正常,能否正确导入,最好记一下用户名及密码等

2.关闭服务
pg_stop
ps -ef|grep postgres 检查一下

3.编译postgresql_9.2.4,原先是9.1.3
[postgres@www.linuxidc.com ~] $tar -zxvf postgresql_9.2.4.tar.gz
[postgres@www.linuxidc.com ~] cd postgresql_9.2.4
[postgres@www.linuxidc.com postgresql_9.2.4]./configure --prefix=/home/postgres --with-pgport=5432 --with-segsize=8 --with-wal-segsize=64 --with-wal-blocksize=64 --with-perl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety
[postgres@www.linuxidc.com postgresql_9.2.4]gmake world
[postgres@www.linuxidc.com postgresql_9.2.4]gmake install-world
如果顺利的话,这个时候可以看一下BIN是否已经换成9.2.4
[postgres@www.linuxidc.com postgresql_9.2.4]$ psql -V
psql (PostgreSQL) 9.2.4
[postgres@www.linuxidc.com postgresql_9.2.4]$
说明BIN文件等已经OK
如果原始版本是9.2.0及以上,可忽略以下步骤,直接启动postgres,如果是9.2.0以下版本,直接启动会报错,则继续,类似initdb与configure版本不一致的问题

4.修改数据文件
[postgres@www.linuxidc.com ~]mv /database/pgdata /database/pgdata.old
[postgres@www.linuxidc.com ~]mkdir /database/pgdata

5.初始化DB
[postgres@www.linuxidc.com ~]$initdb -D /database/pgdata -E UTF8 --locale=C -U postgres -W

6.拷贝老的postgresql.conf与pg_hba.conf文件到新的$PGDATA下
[postgres@www.linuxidc.com ~]$cp /database/pgdata.old/postgresql.conf /database/pgdata/postgresql.conf
[postgres@www.linuxidc.com ~]$cp /database/pgdata.old/hba.conf /database/pgdata/hba.conf

7.启动数据库
pg_start
--如果是单个库导出恢复则建一下DB和相关的用户,省得导入报错

8.恢复数据
[postgres@www.linuxidc.com ~]$psql -d db_www.linuxidc.com -f db.bak

9.检查
检查数据、应用及日志是否有异常,还有一些容易遗漏的参数如timezone等,这个可以通过数据库里select now()与系统时间是否匹配来检查还有一种不用数据dump导出的pg_upgrade方式,后续再记。

就这样吧。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款