我正在为我的Ruby on Rails应用程序(在Mac OS X 10.9上)使用PostgreSQL数据库。
关于如何升级PostgreSQL数据库有详细的说明吗?
我担心我会破坏数据库中的数据或把它弄乱。
我正在为我的Ruby on Rails应用程序(在Mac OS X 10.9上)使用PostgreSQL数据库。
关于如何升级PostgreSQL数据库有详细的说明吗?
我担心我会破坏数据库中的数据或把它弄乱。
当前回答
在Windows上,当尝试使用pg_upgrade时,我一直面临不同的错误消息。
为我节省了很多时间
备份数据库 卸载PostgreSQL的所有副本 安装9.5 恢复数据库
其他回答
我在Windows 10上从Postgresql 11升级到Postgresql 12的解决方案如下。
首先,你需要能够停止和启动Postgresql服务。您可以在Powershell中通过以下命令完成此操作。
开始: pg_ctl start -D " d:\postgresql\11\data "
站: pg_ctl stop -D " d:\postgresql\11\data "
状态: pg_ctl status -D " d:\postgresql\11\data "
在进行升级之前进行备份是明智的。Postgresql 11实例必须正在运行。然后复制全局函数
pg_dumpall -U postgres -g -f d:\bakup\postgresql\11\globals.sql
然后是每个数据库
pg_dump -U postgres -Fc <database> > d:\backup\postgresql\11\<database>.fc
or
pg_dump -U postgress -Fc -d <database> -f d:\backup\postgresql\11\<database>.fc . d:\backup\postgresql\11\<database>.fc . d:\backup\postgresql\11\
如果还没有安装Postgresql 12 (Postgresql 11也安装在5433端口上)
然后按如下步骤进行升级:
1)停止Postgresql 11服务(见上文)
2)编辑d:\postgresql\12\data目录下的postgresql.conf文件,将port = 5433修改为port = 5432
3)编辑windows用户环境路径(windows start然后输入env)指向Postgresql 12而不是Postresql 11
4)执行upgrade,输入如下命令。
pg_upgrade `
-b “c:\program files\postgresql\11\bin” `
-B “c:\program files\postgresql\12\bin” `
-d “d:\postgresql\11\data” `
-D “d:\postgresql\12\data” --username=postgres
(在powershell中使用反引号(或反引号)'来继续下一行的命令)
5)最后启动新的Postgresql 12服务
pg_ctl start -D " d:\postgresql\12\data "
看来Homebrew现在已经有了解决方案:
$ brew info postgresql
...
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
....
尽管上面有所有的答案,我还是有5美分。
它适用于任何操作系统和从任何到任何postgres版本。
停止任何正在运行的postgres实例; 安装新版本并启动它;检查你是否可以连接到新版本; 将旧版本postgresql.conf ->端口从5432修改为5433; 启动旧版postgres实例; 打开终端并cd到新版本的bin文件夹; 执行命令pg_dumpall -p 5433 -U <username> | psql -p 5432 -U <username> 停止旧的postgres运行实例;
假设您已经使用自制程序安装和升级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文档,了解你在上述步骤中所做的事情,以减少挫折。
这对我很有用。
https://gist.github.com/dideler/60c9ce184198666e5ab4
言简意赅。老实说,我的目标不是理解PostgreSQL的精髓,我只想把事情做好。