postgresql - "The database cluster was initialized with CATALOG_VERSION_NO X, but the server was compiled with CATALOG_VERSION_NO Y."升级后

标签 postgresql ubuntu upgrade aptitude

今天我升级了Ubuntu服务器上的所有软件:

sudo aptitude upgrade

升级不顺利,postgresql 没有启动,错误:

alex@db:~$ sudo service postgresql start
* Starting PostgreSQL 9.5 database server[fail]
* The PostgreSQL server failed to start. Please check the log output:
2015-10-30 12:42:09 MSK FATAL:  database files are incompatible with server
2015-10-30 12:42:09 MSK DETAIL:  The database cluster was initialized with CATALOG_VERSION_NO 201507281, but the server was compiled with CATALOG_VERSION_NO 201510051.
2015-10-30 12:42:09 MSK HINT:  It looks like you need to initdb.

我不记得,升级前服务器上的 postgresql 是哪个版本,但升级后我只看到一个数据目录和一个集群:

alex@db:~$ ls /var/lib/postgresql/
9.5  Maildir

alex@db:~$ pg_lsclusters 
Ver Cluster Port Status Owner    Data directory               Log file
9.5 main    5432 down   postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log

所以看起来这是一个小升级。

将数据目录复制到某处后,再次运行 initdbaptitude upgrade 我注意到创建了一个 9.4 集群:

alex@db:~$ sudo cp /var/lib/postgresql/9.5/main /var/lib/postgresql/9.5/main.old
alex@db:~$ sudo /usr/lib/postgresql/9.5/bin/initdb -D /var/lib/postgresql/9.5/main/
alex@db:~$ sudo aptitude upgrade
alex@db:~$ ls /var/lib/postgresql/
9.4  9.5  Maildir
alex@db:~$ pg_lsclusters 
Ver Cluster Port Status Owner    Data directory               Log file
9.4 main    5433 down   postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log
9.5 main    5432 down   postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log

现在它工作正常,但是如何从/var/lib/postgresql/9.5/main.old 恢复保存的数据? pg_upgrade 不起作用。 而且...是的,我在升级前没有创建备份。

更新: /etc/apt/sources.list

的内容
#######################################################################################
# Hetzner APT-Mirror
#
deb http://mirror.hetzner.de/ubuntu/packages trusty main restricted universe multiverse
deb http://mirror.hetzner.de/ubuntu/packages trusty-backports main restricted universe multiverse
deb http://mirror.hetzner.de/ubuntu/packages trusty-updates main restricted universe multiverse
deb http://mirror.hetzner.de/ubuntu/security trusty-security main restricted universe multiverse

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://de.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ trusty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://de.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ trusty-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://de.archive.ubuntu.com/ubuntu/ trusty universe
deb-src http://de.archive.ubuntu.com/ubuntu/ trusty universe
deb http://de.archive.ubuntu.com/ubuntu/ trusty-updates universe
deb-src http://de.archive.ubuntu.com/ubuntu/ trusty-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://de.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://de.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ trusty-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://de.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu trusty partner
# deb-src http://archive.canonical.com/ubuntu trusty partner

## Uncomment the following two lines to add software from Ubuntu's
## 'extras' repository.
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
# deb http://extras.ubuntu.com/ubuntu trusty main
# deb-src http://extras.ubuntu.com/ubuntu trusty main

deb http://packages.elasticsearch.org/elasticsearch/1.4/debian stable main

更新 2:

alex@db:~$ sudo dpkg -l postgresql\*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                                      Version                           Architecture                      Description
+++-=========================================================-=================================-=================================-=======================================================================================================================
ii  postgresql                                                9.4+170.pgdg14.04+1               all                               object-relational SQL database (supported version)
un  postgresql-7.4                                            <none>                            <none>                            (no description available)
un  postgresql-8.0                                            <none>                            <none>                            (no description available)
un  postgresql-9.1                                            <none>                            <none>                            (no description available)
ii  postgresql-9.3                                            9.3.10-1.pgdg14.04+1              amd64                             object-relational SQL database, version 9.3 server
ii  postgresql-9.4                                            9.4.5-1.pgdg14.04+1               amd64                             object-relational SQL database, version 9.4 server
ii  postgresql-9.5                                            9.5~beta1-1.pgdg14.04+1           amd64                             object-relational SQL database, version 9.5 server
un  postgresql-client                                         <none>                            <none>                            (no description available)
ii  postgresql-client-9.3                                     9.3.10-1.pgdg14.04+1              amd64                             front-end programs for PostgreSQL 9.3
ii  postgresql-client-9.4                                     9.4.5-1.pgdg14.04+1               amd64                             front-end programs for PostgreSQL 9.4
ii  postgresql-client-9.5                                     9.5~beta1-1.pgdg14.04+1           amd64                             front-end programs for PostgreSQL 9.5
ii  postgresql-client-common                                  170.pgdg14.04+1                   all                               manager for multiple PostgreSQL client versions
ii  postgresql-common                                         170.pgdg14.04+1                   all                               PostgreSQL database-cluster manager
ii  postgresql-contrib                                        9.4+170.pgdg14.04+1               all                               additional facilities for PostgreSQL (supported version)
ii  postgresql-contrib-9.3                                    9.3.10-1.pgdg14.04+1              amd64                             additional facilities for PostgreSQL
ii  postgresql-contrib-9.4                                    9.4.5-1.pgdg14.04+1               amd64                             additional facilities for PostgreSQL
ii  postgresql-contrib-9.5                                    9.5~beta1-1.pgdg14.04+1           amd64                             additional facilities for PostgreSQL
ii  postgresql-doc                                            9.4+170.pgdg14.04+1               all                               documentation for the PostgreSQL database management system
ii  postgresql-doc-9.3                                        9.3.10-1.pgdg14.04+1              all                               documentation for the PostgreSQL database management system
ii  postgresql-doc-9.4                                        9.4.5-1.pgdg14.04+1               all                               documentation for the PostgreSQL database management system
un  postgresql-doc-9.5                                        <none>                            <none>                            (no description available)
ii  postgresql-server-dev-9.3                                 9.3.10-1.pgdg14.04+1              amd64                             development files for PostgreSQL 9.3 server-side programming


alex@db:~$ sudo apt-cache policy postgresql-9.5
postgresql-9.5:
  Installed: 9.5~beta1-1.pgdg14.04+1
  Candidate: 9.5~beta1-1.pgdg14.04+1
  Version table:
 *** 9.5~beta1-1.pgdg14.04+1 0
        500 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main amd64 Packages
        100 /var/lib/dpkg/status

最佳答案

您正在/正在使用数据库的 alpha 版本明确记录为不保持格式稳定。不过,在没有意识到这一点的情况下,看起来安装起来可能有点太容易了;我有 mailed the apt packaging team about that .


更新:您必须明确地完成aptitude install postgresql-9.5 并且要么使用--force 当最初手动安装或添加 9.5 到您的 sources.list 条目时。默认情况下不安装 9.5 包,需要额外的步骤来安装。见:

我用一条警告说明更新了 wiki,以防你在没有意识到格式更改的情况下按照这些说明进行操作。尽管我认为使用包含您关心的数据的预发布数据库显然不是一个好主意,真的。


如果您需要读取旧数据,则需要下载当时正在运行的特定版本,安装它,然后使用它来转储数据库。然后您可以将它们恢复到新副本。

强烈建议您转储数据,然后将其恢复到 PostgreSQL 9.4,并继续使用它直到 9.5.0 出来或者至少直到 beta 发布。 Beta 之后,PostgreSQL 团队努力避免更改格式。


更新:您现在正在运行 9.5~beta1-1.pgdg14.04+1,所以我很确定是 9.5alpha2 到 9.5beta1 的更新导致了问题。这是有道理的。

所以我们要做的就是找到9.5alpha1版本,然后强制降级。请注意,这将阻止您访问 9.5beta2 数据库,直到您再次升级,因此我建议先将其丢弃。

从版本来看,很明显它是一个 PGDG 版本,即来自 apt.postgresql.org(由 PostgreSQL 开发组运行)的版本。检查 http://apt.postgresql.org/pub/repos/apt/dists/trusty-pgdg/9.5/binary-amd64/Packages 向我们展示了当前的包列表,而 alpha 不是在里面。这是可以预料的,因为它不再是当前版本,但这意味着您不能直接从该存储库下载它。但是,它不在 trusty-pgdg-testing 中,也不在 http://apt.postgresql.org/pub/repos 的包池中/apt/pool/main/p/postgresql-9.5/ 或者。

换句话说,alpha 已经完全从存储库中删除,并且不再可以从 apt.postgresql.org 下载。

首先,检查您的 /var/cache/apt/archives 中是否还有 alpha。如果这样做,请现在将名称中带有 alpha2 的所有内容复制到单独的位置。

如果你不这样做,你的选择是自己编译它,或者在邮件列表上询问是否还有人有这些包。

关于postgresql - "The database cluster was initialized with CATALOG_VERSION_NO X, but the server was compiled with CATALOG_VERSION_NO Y."升级后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33433088/

相关文章:

postgresql - 导入 OpenStreetMaps 数据失败

sql - 生成行并插入到表中

performance - 需要将整个 postgreSQL 数据库加载到 RAM 中

javascript - 如何在客户端将javascript动画转换为视频输出

docker - 在 Debian 10 上更新 docker

database - 我应该相信自动生成的数据库比较脚本吗?

django - TurnKey Django -- 如何将 Django 升级到 1.4

php postgresql pg_fetch_all

c++ - 设置 QtCreator 在 Ubuntu 14.04 上为 arm7 设备开发应用程序

sql-server - TFS 2010 到 2013 : SQL Server from 2008 R2 Standard to 2014 Express