将postgresql集群从9.1升级到9.2时出错

时间:2012-10-17 23:14:27

标签: postgresql postgresql-9.2

我在Amazon EC2上使用Ubuntu 12.04 64位。 尝试将postgresql从9.1升级到9.2。

$ uname -a
Linux db2 3.2.0-32-virtual #51-Ubuntu SMP Wed Sep 26 21:53:42 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

$ apt-cache policy postgresql
postgresql:
  Installed: 9.1+136~precise
  Candidate: 9.1+136~precise
  Version table:
 *** 9.1+136~precise 0
    500 http://ppa.launchpad.net/pitti/postgresql/ubuntu/ precise/main amd64                 Packages
    100 /var/lib/dpkg/status
 9.1+129ubuntu1 0
    500 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages
 9.1+129 0
    500 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

我正在关注的升级过程是:

$ sudo add-apt-repository ppa:pitti/postgresql
$ sudo apt-get update
$ sudo apt-get install postgres-9.2
$ sudo pg_dropcluster --stop 9.2 main
$ sudo pg_upgradecluster 9.1 main /var/lib/postgresql/9.2
Stopping old cluster...
Disabling connections to the old cluster during upgrade...
Restarting old cluster with restricted connections...
Creating new cluster (configuration: /etc/postgresql/9.2/main, data: /var/lib/postgresql/9.2)...
Moving configuration file /var/lib/postgresql/9.2/postgresql.conf to /etc/postgresql/9.2/main...
Moving configuration file /var/lib/postgresql/9.2/pg_hba.conf to /etc/postgresql/9.2/main...
Moving configuration file /var/lib/postgresql/9.2/pg_ident.conf to /etc/postgresql/9.2/main...
Configuring postgresql.conf to use port 5433...
Disabling connections to the new cluster during upgrade...
Roles, databases, schemas, ACLs...
Fixing hardcoded library paths for stored procedures...
ERROR:  cannot set transaction read-write mode during recovery
Error: Could not fix library paths
Re-enabling connections to the old cluster...
Re-enabling connections to the new cluster...
Error during cluster dumping, removing new cluster

任何帮助将不胜感激。 谢谢。

2 个答案:

答案 0 :(得分:4)

问题的根本原因是hot_standby中的onpostgresql.conf,因此服务器是只读的。

一般情况下,如果您在Debian和Ubuntu中通常打包的pg_upgradecluster工具遇到pg_wrapper问题,则可以进行手动群集升级:

  • 启动旧服务器
  • sudo -i -u postgres
  • for db in $(psql --tuples-only template1 -c "select datname from pg_database where datname not in ('template0','template1','postgres','template_postgis');"); do pg_dump -Fc -f $db.backup $db; done
  • pg_dumpall --globals-only > globals.sql
  • 停止旧服务器
  • initdb新服务器上的新群集(如果已删除)。使用pg_wrapper我认为您使用pg_createcluster
  • 启动新服务器;仍然是postgres用户:
  • psql -f globals.sql
  • for backup in *.backup; do pg_restore --dbname postgres --create $backup; done

或者,使用pg_upgrade工具工具就地转换您的数据库,但这可能会让pg_wrapper感到困惑。

使用pg_dumpall命令进行整个群集转储可以简化这些步骤,但我不太喜欢它。我认为恢复pg_dumpall转储在错误处理方面有很多不足之处,很难从转储中提取单个数据库或表,并且不能在单个事务中恢复它们。我强烈建议仅将pg_dumpall用于像用户/组/角色这样的全局变量,并为各个数据库使用pg_dump每个数据库的自定义格式备份,如上所示。

答案 1 :(得分:0)

installed from apt时,升级的一般步骤。

在我的情况下,从pg11到pg12:

sudo apt update
sudo apt install postgresql-12
sudo systemctl stop postgresql@12-main #stop the autocreated/autostarted one
pg_dropcluster 12 main # drop it
sudo -u postgres pg_upgradecluster -v 12 11 main

sudo systemctl start postgresql@12-main
sudo -u postgres psql <yourdb> # up and test it