PostgreSQL 9.5.3 版本升级到 9.6.2 版本后的数据兼容问题

参考链接: http://www.jianshu.com/p/354442add14f

  1. Installed new postgres with Homebrew (started getting the error)
  2. mv /usr/local/var/postgres /usr/local/var/postgres.old
  3. initdb -D /usr/local/var/postgres
  4. pg_upgrade -b /usr/local/Cellar/postgresql/9.0.4/bin -B /usr/local/Cellar/postgresql/9.1.2/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres
  5. ./delete_old_cluster.sh (this script is created for you automatically in current dir when you go through above steps)
  6. rm delete_old_cluster.sh

参考链接: http://serverfault.com/questions/342626/how-do-i-upgrade-postgresl-database-incompatibility-error

连接 PostgreSQL 时报以下错误:

psql: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

打开 PostgreSQL 的服务日志发现是 PostgreSQL 9.5.3 版本升级到 9.6.2 版本后的数据兼容问题:

tail -f /usr/local/var/postgres/server.log
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.3.1.

对于版本的数据升级问题,PostgreSQL 提供了 pg_upgrade 来做版本后的数据迁移,用法如下:

pg_upgrade -b 旧版本的bin目录 -B 新版本的bin目录 -d 旧版本的数据目录 -D 新版本的数据目录 [其他选项...]
数据迁移前,记得先关闭 PostgreSQL 的 postmaster 服务,不然会报以下错误:

There seems to be a postmaster servicing the new cluster.
Please shutdown that postmaster and try again.
Failure, exiting
  • 利用 pg_ctl 关闭 postmaster:
pg_ctl -D /usr/local/var/postgres stop

Mac 下也可以这样关闭:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  • 首先备份就版本的数据(默认是在 /usr/local/var/postgres 目录):
mv /usr/local/var/postgres /usr/local/var/postgres.old
  • 利用 initdb 命令再初始一个数据库文件:
initdb /usr/local/var/postgres -E utf8 --locale=zh_CN.UTF-8

NOTE:记得加 "--locale=zh_CN.UTF-8" 选项,不然会报以下错误:

lc_collate cluster values do not match:  old "zh_CN.UTF-8", new "en_US.UTF-8"
  • 最后运行 pg_upgrade 进行数据迁移:
pg_upgrade -b /usr/local/Cellar/postgresql/9.5.2/bin/ -B /usr/local/Cellar/postgresql/9.6.3/bin/ -d /usr/local/var/postgres.old 
-D /usr/local/var/postgres -v
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

从心所愿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值