我正在为我的Ruby on Rails应用程序(在Mac OS X 10.9上)使用PostgreSQL数据库。
关于如何升级PostgreSQL数据库有详细的说明吗?
我担心我会破坏数据库中的数据或把它弄乱。
我正在为我的Ruby on Rails应用程序(在Mac OS X 10.9上)使用PostgreSQL数据库。
关于如何升级PostgreSQL数据库有详细的说明吗?
我担心我会破坏数据库中的数据或把它弄乱。
当前回答
看来Homebrew现在已经有了解决方案:
$ brew info postgresql
...
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
....
其他回答
假设您已经使用自制程序安装和升级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文档,了解你在上述步骤中所做的事情,以减少挫折。
下面是Ubuntu用户的解决方案
首先,我们必须停止postgresql
sudo /etc/init.d/postgresql stop
创建一个名为/etc/apt/sources.list.d/pgdg的新文件。列出并在行下添加
deb http://apt.postgresql.org/pub/repos/apt/ utopic-pgdg main
遵循以下命令
wget -q -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.4
sudo pg_dropcluster --stop 9.4 main
sudo /etc/init.d/postgresql start
现在我们什么都有了,只需要升级如下
sudo pg_upgradecluster 9.3 main
sudo pg_dropcluster 9.3 main
就是这样。大多数升级后的集群将在端口号5433上运行。用下面的命令检查它
sudo pg_lsclusters
我认为这是您将postgres更新到9.6的解决方案的最佳链接
https://sandymadaan.wordpress.com/2017/02/21/upgrade-postgresql9-3-9-6-in-ubuntu-retaining-the-databases/
用户手册详细介绍了这个主题。您可以:
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