All commands were done as the root user unless indicated.

This time it was necessary to create a new ZFS hierarchy of filesystems rooted at /var/db/postgres/data96. Also, the new PostgreSQL DBMS runs as the postgres user, not the pgsql user.

# Dump the current database cluster.
su -l pgsql
pg_dumpall | bzip2 -9c > all-db-9.5.7-2017-05-15.sql.bz2
chmod 0400 all-db-9.5.7-2017-05-15.sql.bz2
exit

# Stop the DBMS.
/usr/local/etc/rc.d/postgresql stop

# Configure the new versions.
make -C /usr/ports/databases/postgresql96-server config-recursive

# Upgrade the components using portupgrade.
portupgrade -fpvo databases/postgresql96-client databases/postgresql95-client
portupgrade -fpvo databases/postgresql96-server databases/postgresql95-server
portupgrade -fpvo databases/postgresql96-contrib databases/postgresql95-contrib

# Upgrade everything depending on databases/postgresql96-client.
# Omit the components upgraded in the previous step.
portupgrade -fprv -x databases/postgresql96-client -x databases/postgresql96-server -x databases/postgresql96-contrib databases/postgresql96-client

# Create the new hierarchy.
zfs create zdata/var/db/postgres
zfs create zdata/var/db/postgres/data96
zfs create zdata/var/db/postgres/data96/base
zfs create zdata/var/db/postgres/data96/pg_xlog
zfs set logbias=throughput zdata/var/db/postgres/data96/base
zfs set logbias=throughput zdata/var/db/postgres/data96/pg_xlog
zfs set primarycache=metadata zdata/var/db/postgres/data96/base
zfs set primarycache=metadata zdata/var/db/postgres/data96/pg_xlog
zfs set recordsize=8K zdata/var/db/postgres/data96/base
zfs set recordsize=8K zdata/var/db/postgres/data96/pg_xlog
zfs set redundant_metadata=most zdata/var/db/postgres/data96/base
zfs set redundant_metadata=most zdata/var/db/postgres/data96/pg_xlog
chown -R postgres:postgres /var/db/postgres
chmod -R 0700 /var/db/postgres/data96

# Hide the base and pg_xlog filesystems for now.
zfs unmount zdata/var/db/postgres/data96/base
zfs unmount zdata/var/db/postgres/data96/pg_xlog

# Edit /etc/rc.conf, if necessary, and change postgresql_data to "/var/db/postgres/data96"

# Create the initial database cluster.
/usr/local/etc/rc.d/postgresql initdb

# Rename /var/db/postgres/data96/base and /var/db/postgres/data96/pg_xlog.
mv /var/db/postgres/data96/base /var/db/postgres/data96/base-old
mv /var/db/postgres/data96/pg_xlog /var/db/postgres/data96/pg_xlog-old

# Unhide the two special filesystems.
zfs mount zdata/var/db/postgres/data96/base
zfs mount zdata/var/db/postgres/data96/pg_xlog

# Copy the contents of /var/db/postgres/data96/base-old and /var/db/postgres/data96/pg_xlog-old.
cp -Rp /var/db/postgres/data96/base-old /var/db/postgres/data96/base
cp -Rp /var/db/postgres/data96/pg_xlog-old /var/db/postgres/data96/pg_xlog

# Delete /var/db/postgres/data96/base-old and /var/db/postgres/data96/pg_xlog-old.
rm -R /var/db/postgres/data96/base-old /var/db/postgres/data96/pg_xlog-old

# Start the DBMS.
/usr/local/etc/rc.d/postgresql start

# Copy the old DB dump and change the ownership.
cp -p ~pgsql/all-db-9.5.7-2017-05-15.sql.bz2 ~postgres
chown postgres:postgres ~postgres/all-db-9.5.7-2017-05-15.sql.bz2

# Recreate the old database cluster.
su -l postgres
bzcat all-db-9.5.7-2017-05-15.sql.bz2 | psql -f - template1

# Set a password for the postgres user/role within the database cluster.
psql template1
alter user postgres with password 'somethingsomething';
\q
exit

# Transfer all relevant settings from /usr/local/pgsql/data to /var/db/postgres/data96 for pg_hba.conf and postgresql.conf

# Restart the DBMS.
/usr/local/etc/rc.d/postgresql restart

# Create a new dump of the database cluster.
su -l postgres
pg_dumpall | bzip2 -9c > all-db-9.6.3-2017-05-15.sql.bz2
chmod 0400 all-db-9.6.3-2017-05-15.sql.bz2
exit

# You may now remove the old PostgreSQL hierarchy rooted at /usr/local/pgsql.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>