PostgreSQL跨版本升级时如何保留数据
作者:互联网
昨天将Fedora 24升级到了26,然后依次升级到28、30、32,直到最新的Fedora 33。系统升级成功了,但是Postgresql无法启动了:
[octopus@pc3 ~]$ sudo systemctl status postgresql
● postgresql.service
Loaded: not-found (Reason: Unit postgresql.service not found.)
Active: failed (Result: exit-code) since Sat 2021-02-13 08:12:44 CST; 2h 23min ago
CPU: 43ms
Feb 13 08:12:43 pc3 systemd[1]: Starting PostgreSQL database server...
Feb 13 08:12:44 pc3 postgresql-check-db-dir[841]: An old version '9.5' of the database format was found.
Feb 13 08:12:44 pc3 postgresql-check-db-dir[841]: You need to dump and reload before using PostgreSQL 12.4.
Feb 13 08:12:44 pc3 postgresql-check-db-dir[841]: See /usr/share/doc/postgresql/README.rpm-dist for more information.
Feb 13 08:12:44 pc3 systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
Feb 13 08:12:44 pc3 systemd[1]: postgresql.service: Failed with result 'exit-code'.
Feb 13 08:12:44 pc3 systemd[1]: Failed to start PostgreSQL database server.
说是数据库文件的版本太旧了,从postgresql 9.5到12跨了很多版本,无法直接inplace升级数据库文件。
那就只好先卸载12.4版本,装上旧的9.x版本,用pg_dumpall把数据备份出来。再装上最新的12.4版本,initdb初始化数据库,把数据重新导进去。
卸载12.4版本:sudo dnf erase postgresql
在https://pkgs.org/download/postgresql-server可以看到,Fedora33可以装PostgreSQL 9.6 x86_64。执行安装命令:
[octopus@pc3 ~]$ sudo dnf install postgresql96-server
[sudo] password for octopus:
Last metadata expiration check: 1:58:52 ago on Sat 13 Feb 2021 08:44:00.
No match for argument: postgresql96-server
Error: Unable to find a match: postgresql96-server
提示找不到这个软件包,我们需要把这个软件包所在的软件源导入进去。
进入https://yum.postgresql.org/repopackages/,找到Fedora 33 - x86_64链接,把软件源rpm文件下载下来,安装:
[octopus@pc3 Downloads]$ sudo rpm -ivh pgdg-fedora-repo-latest.noarch.rpm
warning: pgdg-fedora-repo-latest.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:pgdg-fedora-repo-42.0-13 ################################# [100%]
查看软件源是否导入成功:
[octopus@pc3 Downloads]$ sudo dnf repolist
repo id repo name
fedora Fedora 33 - x86_64
fedora-cisco-openh264 Fedora 33 openh264 (From Cisco) - x86_64
fedora-modular Fedora Modular 33 - x86_64
pgdg-common PostgreSQL common RPMs for Fedora 33 - x86_64
pgdg10 PostgreSQL 10 for Fedora 33 - x86_64
pgdg11 PostgreSQL 11 for Fedora 33 - x86_64
pgdg12 PostgreSQL 12 for Fedora 33 - x86_64
pgdg13 PostgreSQL 13 for Fedora 33 - x86_64
pgdg95 PostgreSQL 9.5 for Fedora 33 - x86_64
pgdg96 PostgreSQL 9.6 for Fedora 33 - x86_64
updates Fedora 33 - x86_64 - Updates
updates-modular Fedora Modular 33 - x86_64 - Updates
这下就可以安装postgresql 9.6了:
[octopus@pc3 Downloads]$ sudo dnf install postgresql96-server
Last metadata expiration check: 0:00:50 ago on Sat 13 Feb 2021 12:17:19.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
postgresql96-server x86_64 9.6.21-1PGDG.f33 pgdg96 5.0 M
Installing dependencies:
postgresql96 x86_64 9.6.21-1PGDG.f33 pgdg96 1.4 M
postgresql96-libs x86_64 9.6.21-1PGDG.f33 pgdg96 671 k
Transaction Summary
================================================================================
Install 3 Packages
Total download size: 7.1 M
Installed size: 29 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): postgresql96-libs-9.6.21-1PGDG.f33.x86_6 237 kB/s | 671 kB 00:02
(2/3): postgresql96-9.6.21-1PGDG.f33.x86_64.rpm 332 kB/s | 1.4 MB 00:04
(3/3): postgresql96-server-9.6.21-1PGDG.f33.x86 508 kB/s | 5.0 MB 00:10
--------------------------------------------------------------------------------
Total 716 kB/s | 7.1 MB 00:10
warning: /var/cache/dnf/pgdg96-6e7ffec6a25ca5b0/packages/postgresql96-9.6.21-1PGDG.f33.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
PostgreSQL 9.6 for Fedora 33 - x86_64 169 kB/s | 1.7 kB 00:00
Importing GPG key 0x442DF0F8:
Userid : "PostgreSQL RPM Building Project <pgsqlrpms-hackers@pgfoundry.org>"
Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : postgresql96-libs-9.6.21-1PGDG.f33.x86_64 1/3
Running scriptlet: postgresql96-libs-9.6.21-1PGDG.f33.x86_64 1/3
Installing : postgresql96-9.6.21-1PGDG.f33.x86_64 2/3
Running scriptlet: postgresql96-9.6.21-1PGDG.f33.x86_64 2/3
Running scriptlet: postgresql96-server-9.6.21-1PGDG.f33.x86_64 3/3
Installing : postgresql96-server-9.6.21-1PGDG.f33.x86_64 3/3
Running scriptlet: postgresql96-server-9.6.21-1PGDG.f33.x86_64 3/3
Verifying : postgresql96-9.6.21-1PGDG.f33.x86_64 1/3
Verifying : postgresql96-libs-9.6.21-1PGDG.f33.x86_64 2/3
Verifying : postgresql96-server-9.6.21-1PGDG.f33.x86_64 3/3
Installed:
postgresql96-9.6.21-1PGDG.f33.x86_64
postgresql96-libs-9.6.21-1PGDG.f33.x86_64
postgresql96-server-9.6.21-1PGDG.f33.x86_64
Complete!
标签:postgresql96,PostgreSQL,x86,1PGDG,保留,版本升级,64,9.6,21 来源: https://blog.csdn.net/ZLK1214/article/details/113799603