ubuntu下使用pg_upgrade从PostgreSQL9.5升级到PostgreSQL9.6

原创
2016/10/15 20:42
阅读数 1.8K

更新apt

sudo apt update
sudo apt upgrade

安装PostgreSQL9.6

sudo apt install postgresql-9.6

停止PostgreSQL

sudo service postgresql stop

修改/etc/postgresql/9.5/main/pg_hba.conf,确保本机信任访问

local   all             postgres                                peer

修改/etc/postgresql/9.6/main/pg_hba.conf,确保本机信任访问

local   all             postgres                                peer

切换到postges角色

sudo su postgres

升级检查

/usr/lib/postgresql/9.6/bin/pg_upgrade -c -p 15431 -P 5432 -b /usr/lib/postgresql/9.5/bin/ -B /usr/lib/postgresql/9.6/bin/ -d /var/lib/postgresql/9.5/main -D  /var/lib/postgresql/9.6/main -o ' -c config_file=/etc/postgresql/9.5/main/postgresql.conf' -O ' -c config_file=/etc/postgresql/9.6/main/postgresql.conf'

检查无误后,执行升级

/usr/lib/postgresql/9.6/bin/pg_upgrade -v -p 15431 -P 5432 -b /usr/lib/postgresql/9.5/bin/ -B /usr/lib/postgresql/9.6/bin/ -d /var/lib/postgresql/9.5/main -D  /var/lib/postgresql/9.6/main -o ' -c config_file=/etc/postgresql/9.5/main/postgresql.conf' -O ' -c config_file=/etc/postgresql/9.6/main/postgresql.conf'

升级无误后,exit回到root用户,移除旧的9.5版本

sudo apt remove postgresql-9.5

启动PostgreSQL

sudo service postgresql start

切换到postges角色

sudo su postgres

优化新数据库

"/usr/lib/postgresql/9.6/bin/vacuumdb" --all --analyze-in-stages

使用客户端连接新数据库后,无误后,删除旧数据库数据。

rm -rf '/var/lib/postgresql/9.5/main'

到此,升级完毕。

你可以编辑 /etc/postgresql/9.6/main/postgresql.conf 文件来优化PostgreSQL。

展开阅读全文
加载中
点击加入讨论🔥(3) 发布并加入讨论🔥
3 评论
2 收藏
0
分享
返回顶部
顶部