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

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

我担心我会破坏数据库中的数据或把它弄乱。


当前回答

在Windows上,当尝试使用pg_upgrade时,我一直面临不同的错误消息。

为我节省了很多时间

备份数据库 卸载PostgreSQL的所有副本 安装9.5 恢复数据库

其他回答

用户手册详细介绍了这个主题。您可以:

pg_upgrade就地;或 Pg_dump和pg_restore。

如果有疑问,请使用转储。不要删除旧的数据目录,保留下来,以防出现问题/你犯了错误;这样,您就可以返回到未更改的9.3安装。

具体操作请参见产品手册。

如果你被卡住了,发一个详细的问题,解释你是如何被卡住的,在哪里,你首先尝试了什么。这也取决于你如何安装PostgreSQL,因为在OS X上有几个不同的PostgreSQL“发行版”(不幸的是)。所以你需要提供这些信息。

站在其他可怜的动物的肩膀上,踩着淤泥,我能够按照以下步骤重新站起来,并在约塞米蒂升级后运行:

假设您已经使用自制程序安装和升级Postgres,您可以执行以下步骤。

Stop current Postgres server: launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Initialize a new 9.4 database: initdb /usr/local/var/postgres9.4 -E utf8 Install postgres 9.3 (as it was no longer present on my machine): brew install homebrew/versions/postgresql93 Add directories removed during Yosemite upgrade: mkdir -p /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/touch /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/.keep run pg_upgrade: pg_upgrade -v -d /usr/local/var/postgres -D /usr/local/var/postgres9.4 -b /usr/local/Cellar/postgresql93/9.3.5/bin/ -B /usr/local/Cellar/postgresql/9.4.0/bin/ Move new data into place: cd /usr/local/var mv postgres postgres9.3 mv postgres9.4 postgres Restart Postgres: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Check /usr/local/var/postgres/server.log for details and to make sure the new server started properly. Finally, re-install related libraries? pip install --upgrade psycopg2 gem uninstall pg gem install pg

Mac通过homebrew:

编译petere/postgresql,

(例如:Brew install peere /postgresql/postgresql-9.6)

删除旧Postgres:

Brew unlink postgresql

编译链接-f postgresql-9.6

如果发生任何错误,不要忘记阅读并遵循每一步的酿造说明。

查看更多信息:https://github.com/petere/homebrew-postgresql

假设您已经使用自制程序安装和升级Postgres,您可以执行以下步骤。

Stop current Postgres server: launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Initialize a new 10.1 database: initdb /usr/local/var/postgres10.1 -E utf8 run 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 to enable verbose internal logging -d the old database cluster configuration directory -D the new database cluster configuration directory -b the old PostgreSQL executable directory -B the new PostgreSQL executable directory Move new data into place: cd /usr/local/var mv postgres postgres9.6 mv postgres10.1 postgres Restart Postgres: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Check /usr/local/var/postgres/server.log for details and to make sure the new server started properly. Finally, re-install the rails pg gem gem uninstall pg gem install pg

我建议你花点时间阅读PostgreSQL文档,了解你在上述步骤中所做的事情,以减少挫折。

如果你正在使用自制和自制服务,你可能只需要做:

brew services stop postgresql
brew upgrade postgresql
brew postgresql-upgrade-database
brew services start postgresql

我认为如果您正在使用高级postgres功能,这可能不完全有效,但它对我来说非常有效。