posted 2012-02-13; updated 2015-06-04
This is here because most upgrade instructions don't work too well on Gentoo. This is not really Gentoo's fault at the moment; the pg_upgrade tool makes you jump through hoops, but it's still miles ahead of pg_dump and pg_restore.
In the following, OLD will refer to your old version. For example, 9.0. Likewise, NEW will refer to the new version, e.g. 9.1.
PG_INITDB_OPTS="--locale=en_US.UTF-8"
.
emerge --config dev-db/postgresql-server:NEW
, and say
yes to create data files for the new version.
local all all trust
to both
/etc/postgresql-{OLD,NEW}/pg_hba.conf.
No, this doesn't make sense, but pg_upgrade doesn't let you tell it where the config files are stored.
root # cp /etc/postgresql-OLD/*.conf /var/lib/postgresql/OLD/data/
root # cp /etc/postgresql-NEW/*.conf /var/lib/postgresql/NEW/data/
root # chown postgres:postgres /var/lib/postgresql/OLD/data/*.conf
root # chown postgres:postgres /var/lib/postgresql/NEW/data/*.conf
Run /etc/init.d/postgres-OLD stop
to stop the old
instance. Neither of them can be running during the upgrade. If
you'd like to check the new one before the upgrade, you can
start/stop it here.
We eselect the new version first so that we get the correct pg_upgrade command…
root # eselect postgresql set NEW
Now we can upgrade,
root # su - postgres
postgres $ cd /var/lib/postgresql
postgres $ pg_upgrade -d /var/lib/postgresql/OLD/data/ -D /var/lib/postgresql/NEW/data/ -b /usr/lib/postgresql-OLD/bin/ -B /usr/lib/postgresql-NEW/bin/
Assuming that worked, let's switch from the old version to the new.
root # rc-update del postgresql-OLD default
root # rc-update add postgresql-NEW default
Get rid of junk from the old version.
root # rm /etc/conf.d/postgresql-OLD
root # rm -rf /var/lib/postgresql/OLD
root # rm -rf /etc/postgresql-OLD
root # emerge -C =dev-db/postgresql-server-OLD
And the conf files we stuck in the data directory…
root # rm /var/lib/postgresql/NEW/data/*.conf
First, edit /etc/postgresql-NEW/pg_hba.conf and remove the
local all all trust
line that we added earlier.
Finally, make sure the permissions are set correctly on the configuration files:
root # chown postgres:postgres /etc/postgresql-NEW/*
root # chmod 600 /etc/postgresql-NEW/*
You were going to forget, I know you were.