Category Archives: FreeBSD ports collection

Upgrading PostgreSQL from 9.5.7 to 9.6.3

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

# 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';

# 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

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

devel/py-setuptools27 renamed to devel/py27-setuptools

r436290 renamed devel/py-setuptools27 to devel/py27-setuptools.

Here are four portupgrade commands to make amends:

portupgrade  -ncfpvo devel/py27-setuptools devel/py-setuptools27
portupgrade    -fpvo devel/py27-setuptools devel/py-setuptools27
portupgrade -ncfprvx devel/py27-setuptools devel/py27-setuptools
portupgrade   -fprvx devel/py27-setuptools devel/py27-setuptools

Run similar commands for updating the origin of, say, devel/py-setuptools36 to devel/py36-setuptools.

Upgrading Qt4 and Qt5 after r434380

r434380 made massive changes to Qt4 and Qt5 in FreeBSD. Sadly, there are no instructions on how to upgrade an existing system. The changes to ports/head/UPDATING didn’t help at all. Here are the notes I made while upgrading my laptop running stable/11.

To successfully install misc/qtchooser and upgrade the remaining Qt4 and Qt5 ports, you need to recursively uninstall

  • devel/qt4-linguisttools,
  • devel/qt4-rcc, and
  • devel/qt4-moc.

At some point you to need to upgrade devel/qt5-core before everything else, e.g. portupgrade -fpv devel/qt5-core.

Upgrading PostgreSQL 9.4.6 to 9.5.1

All commands were done as the root user unless indicated.

su -l pgsql
pg_dumpall | bzip2 -9c > all-db-9.4.6-2016-02-17.sql.bz2
chmod 0600 all-db-9.4.6-2016-02-17.sql.bz2
/usr/local/etc/rc.d/postgresql stop
make -C /usr/ports/databases/postgresql95-server config-recursive
pkg delete databases/postgresql94-contrib
portupgrade -fpvo databases/postgresql95-client databases/postgresql94-client
portupgrade -Nfpv databases/postgresql95-contrib
portupgrade -fpvo databases/postgresql95-server databases/postgresql94-server
portupgrade -fprv -x databases/postgresql95-client -x databases/postgresql95-server -x databases/postgresql95-contrib databases/postgresql95-client
mv /usr/local/pgsql/data /usr/local/pgsql/data0
su -l pgsql -c 'mkdir /usr/local/pgsql/data'
/usr/local/etc/rc.d/postgresql initdb
/usr/local/etc/rc.d/postgresql start
su -l pgsql
bzcat all-db-9.4.6-2016-02-17.sql.bz2 | psql -f - template1
# Transfer all relevant settings from /usr/local/pgsql/data0 to /usr/local/pgsql/data for pg_hba.conf and postgresql.conf
/usr/local/etc/rc.d/postgresql restart
su -l pgsql
pg_dumpall | bzip2 -9c > all-db-9.5.1-2016-02-17.sql.bz2
chmod 0600 all-db-9.5.1-2016-02-17.sql.bz2
rm -R /usr/local/pgsql/data0

Adding 24 hour clock to FreeBSD’s hardstatus string for GNU Screen

FreeBSD gives the user an option of installing the file /usr/local/etc/screenrc with some sensible defaults along with GNU Screen, aka sysutils/screen.

Among the defaults are a format string for the hardstatus line. It shows the date using yy/dd/mm notation and the time as a 12 hour clock. That may be fine in the English speaking parts of the world.

hardstatus string '%{gk}[%{G}%H%{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}]%{=b C}[%m/%d/%y %C %A]%{W}'

Continue reading Adding 24 hour clock to FreeBSD’s hardstatus string for GNU Screen