[postgres升级]CostOS7下升级postgres至最新版9.5,已经过验证

2016年3月27日09:17:58 发表评论 3,019 views

环境

CentOS7 
原版本: 
psql -version 
psql (9.2.14) 
准备升级到9.5版本

操作步骤

完整备份Postgresql

-bash-4.2$ pg_dump -U postgres whr_info_db>whr_info_db_bak.copy.sql; 这句使用copy备份,可以不运行。
-bash-4.2$ pg_dump -U postgres --column-inserts whr_info_db>whr_info_db_bak.insert.sql;

备份的文件位置是在:  /var/lib/pgsql

安装新版本(这一步操作后面遇到问题,这里作记录,但不要使用此步骤)

查找资源

到http://yum.postgresql.org

wget https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
rpm -ivh ./pgdg-centos95-9.5-2.noarch.rpm

确定目前正在运行的包。运行

rpm -qa | grep postgre 
 
yum list postgres* | grep 95  如果yum资源无法连接,则可运行命令:  yum install yum-plugin-fastestmirror 自动寻找最快的镜像。 

  yum install postgresql95.x86_64 postgresql95-server.x86_64 postgresql95-libs.x86_64 postgresql95-contrib.x86_64 postgresql95-devel.x86_64

这时它的安装位置可以通过命令查询到: 

  /usr/pgsql-9.5

运行upgrade

停止sudo systemctl stop postgresql

删除现有postgresql

rpm -qa | grep postgresql  把找到的包全部删除  yum remove postgresql*

再运行安装命令:  yum install postgresql95-server

数据位置:  /var/lib/pgsql/9.5/data

初始化

运行:  service postgresql-9.5 initdb  当然这句很可能会失败,则运行:

  /usr/pgsql-9.5/bin/postgresql95-setup initdb

上行命令还是提示的话:Data directory is not empty! [FAILED]

加运行:

rm -rf /var/lib/pgsql/9.5/data

systemctl enable postgresql-9.5.service

或者 

chkconfig postgresql-9.5 on

参照http://blog.csdn.net/xundh/article/details/50037353#t1修改配置: 

  这里路径要改为/var/lib/pgsql/9.5/data/pg_hba.conf设置允许远程访问,修改

vi /var/lib/pgsql/9.5/data/pg_hba.conf

  把里边的这个信息

host all all 127.0.0.1/32 ident 更换成 host all all 127.0.0.1/32 md5

host    all             all       ::1/128            ident换成 host    all      all       ::1/128          md5

在该配置文件的host all all 127.0.0.1/32 md5行下添加以下配置,或者直接将这一行修改为以下配置

host    all             all             0.0.0.0/0             md5

service postgresql-9.5 start

还原数据

           sudo su - postgres
-bash-4.2$ psql
创建用户用色
postgres=# CREATE USER whr_info WITH PASSWORD '123456';
postgres=# CREATE DATABASE whr_info_db OWNER whr_info;
postgres=# GRANT ALL PRIVILEGES ON DATABASE whr_info_db to whr_info;
postgres=# \q
-bash-4.2$ psql -d whr_info_db -U postgres -f whr_info_db_bak.insert.sql
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
0 0 投票数
文章评分
订阅评论
提醒
guest

0 评论
内联反馈
查看所有评论