I recently had some fun and games upgrading PostgresSQL on my Gentoo box – I was running 8.2.7 and needed 8.3.x for it’s support of ENUM types.
After some googling I found this blog which explained how to do it. There were a few extra steps for me, however, so I though I’d repost my findings here.
So, here are the steps I went through:
pg_dumpall > /tmp/database.dump /etc/init.d/postgresql stop emerge --unmerge libpq postgresql echo "dev-db/postgresql-base ~x86" >> /etc/portage/package.keywords echo "dev-db/postgresql-server ~x86" >> /etc/portage/package.keywords echo "app-admin/eselect-postgresql ~x86" >> /etc/portage/package.keywords emerge -av dev-db/postgresql-base dev-db/postgresql-server emerge --config postgresql-server rc-update add postgresql-8.3 default revdep-rebuild
First of all, you need to dump (backup) your current database. Do that with the pg_dumpall command. It can take a number of options, so do a
pg_dumpall –helpto see if any apply to you.
Next you need to stop and remove your existing postgresql and libpq.
You’ll then need to unmask postgresql-base, postgresql-server and eselect-postgresql (lines 5,6 and 7 above). You might need to modify the ~x86 flag to match your architecture (~amd64 is another common one, for 64bit AMD cpus).
After that, you’ll want to emerge postgresql-base and postgresql-server. Make sure it’s the dev-db/ variety, and not the ‘virtual/’ variety. (I specified dev-db in mine). You’ll be instructed to do emerge –config when that completes.
Finally you may want to get postgresql to run when your server boots, you’ll also want to issue a
revdep-rebuild
command to rebuild any packages that were broken by removing libpq. If you don’t have revdep-rebuild, you’ll want to emerge gentoolkit.
And that’s it. All that’s left is to start up your new postgresql database and restore the contents of your old one using pg_restore. (again, pg_restore –help will help you with that).
Thanks for posting this. The integration of libpq with postgresql-base had me stumped for a bit until I read the ChangeLog, and I also had to do a
ln -s /usr/lib/postgresql-8.3/lib/libpq.so /usr/lib/libpq.so.4
before anything (well, pgadmin3 is all I tried) would work.
Finally, WRT the restore, I had to use psql < /tmp/database.dump, since pg_restore whined about invalid headers in the dump.
HTH someone else…
it should be
emerge –config postgresql-server
Thanks don, I missed that. I’ve updated the post.
The variation in the post was just more specific to the version of postgresql being emerged.