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

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

恐怕我会 destruct 数据库中的数据或把它搞砸.

推荐答案

假设您已使用home brew安装和升级Postgres,则可以执行以下步骤.

  1. 停止当前Postgres服务器:

    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

  2. 初始化新的10.1数据库:

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

  3. 运行pg_upgrade (note: change bin version if you're upgrading from something other than below):

    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以启用详细的内部日志(log)记录

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

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

    -b旧的PostgreSQL可执行目录

    -B新的PostgreSQL可执行目录

  4. 将新数据移动到位:

    cd /usr/local/var
    mv postgres postgres9.6
    mv postgres10.1 postgres
    
  5. 重新启动Postgres:

    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

  6. 判断/usr/local/var/postgres/server.log以了解详细信息,并确保新服务器正确启动.

  7. 最后,重新安装rails pg gem

    gem uninstall pg
    gem install pg
    

我建议你花些时间阅读这PostgreSQL documentation篇文章,以便准确地理解你在上述步骤中所做的事情,从而最大限度地减少挫折感.

Postgresql相关问答推荐

如何在Windows中安装sql for golang

我无法在过程中提交

分区可以用于postgres中的同类查询吗?

如何在PostgreSQL中以行值的形式获取列

为什么更新不设置较晚的结束时间?

有没有一种方法可以在参数中添加密码,并在批处理文件中需要时自动获取密码?

PostgreSQL 中的 Datum 数据类型是什么以及它的用途是什么?

Postgres 生成的列不是不可变的

需要用 jack/pgx 更新 golang 中复合类型的 PSQL 行

Postgres内部如何计算月份间隔

使用间隔参数的 go postgres 准备好的语句不起作用

在 KnexJS 中插入

Heroku Rails 4 无法连接到服务器:connection refused

sql:转换参数 $1 类型:不支持的类型 []int,in 的一部分

如何从 .sql postgresql 备份恢复单个表?

PostgreSQL ,从 2 个表中 Select ,但仅从表 2 中 Select 最新的元素

python pip install psycopg2 安装错误

如何从 PostgreSQL 中的 Json 数组中获取元素

Oracle 相当于 Postgres 的 DISTINCT ON?

如何在 postgres 查询中排名