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

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

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


当前回答

我的解决方案是将这两种资源结合起来:

https://gist.github.com/tamoyal/2ea1fcdf99c819b4e07d

and

http://www.gab.lc/articles/migration_postgresql_9-3_to_9-4

第二个比第一个更有帮助。也要不要,不要按照步骤去做,因为有些是没有必要的。 此外,如果您不能通过postgres控制台备份数据,您可以使用替代方法,使用pgAdmin 3或其他程序进行备份,就像我在我的案例中所做的那样。

还有,链接:https://help.ubuntu.com/stable/serverguide/postgresql.html 帮助设置postgres用户的加密密码和md5认证。

所有这些都完成后,检查终端中运行的postgres服务器版本:

sudo -u postgres psql postgres

输入密码后在postgres终端运行:

SHOW SERVER_VERSION;

它将输出如下内容:

 server_version 
----------------
 9.4.5

设置和启动postgres我使用命令:

> sudo bash # root
> su postgres # postgres

> /etc/init.d/postgresql start
> /etc/init.d/postgresql stop

然后从文件中恢复数据库:

> psql -f /home/ubuntu_username/Backup_93.sql postgres

或者如果不奏效,试试这个:

> pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d name_of_database ~/your_file.dump

如果你正在使用Rails做一个bundle exec rake db:migrate后拉代码:)

其他回答

在Windows 10上,因为我有npm,所以我安装了rimraf包。NPM安装rimraf

使用pg_dump -U $username——format=c——file=$mydatabase命令逐个备份所有数据库。美元sqlc dbname

然后安装了最新的PostgreSQL版本,即11.2,这提示我这次使用端口5433。

其次是卸载旧版本的PostgreSQL我是10。注意,卸载程序可能会提示不删除文件夹C:\PostgreSQL\10\data。这就是为什么我们有下一步使用rimraf永久删除文件夹和它的子文件夹。

2 .进入PostgreSQL安装目录,执行命令rimraf 10。10为目录名。注意使用旧版本的PostgreSQL,比如9.5之类的。

现在将C:\PostgreSQL\pg11\bin, C:\PostgreSQL\pg11\lib添加到Windows环境变量中。注意我的新安装版本是11,这就是为什么我使用pg11。

打开C:\PostgreSQL\data\pg11,打开PostgreSQL .conf编辑port = 5433到port = 5432

就是这样。打开cmd,输入psql -U postgres

现在,您可以使用命令pg_restore -U $username——dbname=$databasename $filename来逐个恢复所有已备份的数据库

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

假设您已经使用自制程序安装和升级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

我的解决方案是将这两种资源结合起来:

https://gist.github.com/tamoyal/2ea1fcdf99c819b4e07d

and

http://www.gab.lc/articles/migration_postgresql_9-3_to_9-4

第二个比第一个更有帮助。也要不要,不要按照步骤去做,因为有些是没有必要的。 此外,如果您不能通过postgres控制台备份数据,您可以使用替代方法,使用pgAdmin 3或其他程序进行备份,就像我在我的案例中所做的那样。

还有,链接:https://help.ubuntu.com/stable/serverguide/postgresql.html 帮助设置postgres用户的加密密码和md5认证。

所有这些都完成后,检查终端中运行的postgres服务器版本:

sudo -u postgres psql postgres

输入密码后在postgres终端运行:

SHOW SERVER_VERSION;

它将输出如下内容:

 server_version 
----------------
 9.4.5

设置和启动postgres我使用命令:

> sudo bash # root
> su postgres # postgres

> /etc/init.d/postgresql start
> /etc/init.d/postgresql stop

然后从文件中恢复数据库:

> psql -f /home/ubuntu_username/Backup_93.sql postgres

或者如果不奏效,试试这个:

> pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d name_of_database ~/your_file.dump

如果你正在使用Rails做一个bundle exec rake db:migrate后拉代码:)

这对我很有用。

https://gist.github.com/dideler/60c9ce184198666e5ab4

言简意赅。老实说,我的目标不是理解PostgreSQL的精髓,我只想把事情做好。

我在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 "