Mini HOWTO: Upgrade PostgreSQL database in Fedora
The main problem in upgrading PostgreSQL databases is downgrading to previous version of the RDBMS, especially if you accidentally updates the software but forget to make the database dump. I have faced the same problem and find it's not so easy task. So let me show my solution for this:
- The problem: after OS upgrade I have PostgreSQL 8.4, and can't start it because the database format is incompatible and suited for PSQL 8.3 only.
- Install required YUM-configuration for the version of PosgreSQL you want to install, for my case PostgreSQL 8.3. There is an excellent http://yum.pgrpms.org/ website, which provides required rpms:
$ sudo rpm -ivh http://yum.pgsqlrpms.org/reporpms/8.3/pgdg-fedora-8.3-7.noarch.rpm - Remove the current PostgreSQL installation. It requires few steps (there is no easy way to delete postgresql-libs because there are too many dependencies):
- Get the list of postgresql packages:
$ rpm -qa | grep postgresql
postgresql-server-8.4.3-1.fc12.i686
postgresql-8.4.3-1.fc12.i686
postgresql-libs-8.4.3-1.fc12.i686 - Remove these without checking dependencies:
$ sudo rpm -ev --nodeps postgresql-server-8.4.3-1.fc12.i686 postgresql-8.4.3-1.fc12.i686 postgresql-libs-8.4.3-1.fc12.i686
- Get the list of postgresql packages:
- Now install required packages:
$ sudo yum install postgresql-server.i386 postgresql-libs-8.3.10-1PGDG.fc12.i386 --disableplugin=protectbase - Start the server:
$ sudo /sbin/service postgresql start - Make dump:
$ sudo -u postgres pg_dumpall > /tmp/pg.dump - Stop the server:
$ sudo /sbin/service postgresql stop - Move the old installation out of the way:
$ sudo mv /var/lib/pgsql /var/lib/pgsql.old - Remove the server:
$ sudo yum remove postgresql-server.i386 postgresql-libs-8.3.10-1PGDG.fc12.i386 --disableplugin=protectbase - Install the current server:
$ sudo yum install postgresql-server - Initialize the new database:
$ sudo /sbin/service postgresql initdb - Start the current server:
$ sudo /sbin/service postgresql start - Restore database from the dump:
$ sudo -u postgres psql -d postgres -f /tmp/pg.dump
Upgrading PostgreSQL 8.1 to 8.4 on CentOS 5.5
ReplyDelete