如何在不丢失数据的情况下将PostgreSQL从9.6版升级到10.1版? [英] How to upgrade PostgreSQL from version 9.6 to version 10.1 without losing data?

查看:280
本文介绍了如何在不丢失数据的情况下将PostgreSQL从9.6版升级到10.1版?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Ruby on Rails应用程序上使用PostgreSQL数据库(在Mac OS X 10.9上)。

I'm using the PostgreSQL database for my Ruby on Rails application (on Mac OS X 10.9).

是否有有关如何升级PostgreSQL数据库的详细说明?

Are there any detailed instructions on how to upgrade PostgreSQL database?

恐怕我会破坏数据库中的数据或将其弄乱。

I'm afraid I will destroy the data in the database or mess it up.

推荐答案

假定您使用自制软件安装和升级Postgres,则可以执行以下步骤。

Assuming you've used home-brew to install and upgrade Postgres, you can perform the following steps.


  1. 停止当前的Postgres服务器:

  1. Stop current Postgres server:

launchctl卸载〜/ Library / LaunchAgents / homebrew.mxcl.postgresql.plist

初始化新的10.1数据库:

Initialize a new 10.1 database:

initdb / usr /local/var/postgres10.1 -E utf8

run pg_upgrade (注意:如果要从下面的版本升级,请更改bin版本)

pg_upgrade -v \
    -d /usr/local/var/postgres \
    -D /usr/local/var/postgres10.1 \
    -b /usr/local/Cellar/postgresql/9.6.5/bin/ \
    -B /usr/local/Cellar/postgresql/10.1/bin/

-v 启用详细的内部日志记录

-v to enable verbose internal logging

- d 旧数据库集群配置目录

-d the old database cluster configuration directory

-D 新数据库集群配置目录

-D the new database cluster configuration directory

-b 旧的PostgreSQL可执行目录

-b the old PostgreSQL executable directory

-B 新的PostgreSQL可执行文件目录

-B the new PostgreSQL executable directory

将新数据移动到位:

cd /usr/local/var
mv postgres postgres9.6
mv postgres10.1 postgres


  • 重新启动Postgres:

  • Restart Postgres:

    launchctl加载〜/ Library / LaunchAgents / homebrew.mxcl.postgresql.plist

    检查 / usr / local /var/postgres/server.log 详细信息并确保新服务器正常启动。

    Check /usr/local/var/postgres/server.log for details and to make sure the new server started properly.

    最后,重新安装轨道 pg gem

    Finally, re-install the rails pg gem

    gem uninstall pg
    gem install pg
    


  • 我建议您花一些时间阅读 PostgreSQL文档,以准确了解您在上述步骤中所做的操作,以最大程度地减少挫败感。

    I suggest you take some time to read the PostgreSQL documentation to understand exactly what you're doing in the above steps to minimize frustrations.

    这篇关于如何在不丢失数据的情况下将PostgreSQL从9.6版升级到10.1版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆