Upgrade to PostgreSQL 19 on FreeBSD 15

This Howto explains the upgrade to PostgreSQL 19 on FreeBSD 15.

Check if the Package is available

sudo pkg search --prefix postgresql19-server

postgresql18-server-19.0
Prefix      : /usr/local
Comment     : PostgreSQL is the most advanced open-source database available anywhere

Save / Backup

Take a snapshot of the virtual machine or save the entire server.

Get Information about the Environment

pkg info | grep sql

postgresql18-client-18.4       PostgreSQL database (client)
postgresql18-server-18.4       PostgreSQL is the most advanced open-source database available anywhere

Output the Location of the Configuration Directories

pg_config

BINDIR = /usr/local/bin
DOCDIR = /usr/local/share/doc/postgresql
HTMLDIR = /usr/local/share/doc/postgresql
INCLUDEDIR = /usr/local/include
PKGINCLUDEDIR = /usr/local/include/postgresql
INCLUDEDIR-SERVER = /usr/local/include/postgresql/server
LIBDIR = /usr/local/lib
PKGLIBDIR = /usr/local/lib/postgresql
LOCALEDIR = /usr/local/share/locale
MANDIR = /usr/local/share/man
SHAREDIR = /usr/local/share/postgresql
SYSCONFDIR = /usr/local/etc/postgresql
PGXS = /usr/local/lib/postgresql/pgxs/src/makefiles/pgxs.mk
'LDFLAGS_SL='
CC = cc
CFLAGS_SL = -fPIC -DPIC
LDFLAGS = -L/usr/local/lib -lpthread -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -Wl,--as-needed -Wl,-R'/usr/local/lib'
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lintl -lzstd -lssl -lcrypto -lz -lreadline -lexecinfo -lm
VERSION = PostgreSQL 18.4

Get a List of the PostgreSQL Databases

/usr/local/bin/psql -U postgres -l

                                                List of databases
   Name    |  Owner   | Encoding | Locale Provider | Collate |  Ctype  | Locale | ICU Rules |   Access privileges
-----------+----------+----------+-----------------+---------+---------+--------+-----------+-----------------------
 db1       | postgres | UTF8     | libc            | C       | C.UTF-8 |        |           |
 postgres  | postgres | UTF8     | libc            | C       | C.UTF-8 |        |           |
 template0 | postgres | UTF8     | libc            | C       | C.UTF-8 |        |           | =c/postgres          +
           |          |          |                 |         |         |        |           | postgres=CTc/postgres
(3 rows)

Dump all PostgreSQL Databases

/usr/local/bin/pg_dump --create --encoding=UTF8 --column-inserts --dbname=db1 --format=p --inserts --username=postgres --file=/usr/local/www/db1_20260808.sql

Check if the Dump Exists

Also check the size of the file!

ls -altr /usr/local/www/*.sql

Postgresql Data Dir: /var/db/postgres/data18/

Stop The PostgreSQL Service and Remove Old Packages

sudo service postgresql stop
sudo pkg delete -fy postgresql18-server-18.4;

Checking integrity... done (0 conflicting)
Installed packages to be REMOVED:
        postgresql18-server: 18.4
Number of packages to be removed: 1
The operation will free 51 MiB.
[1/1] Deinstalling postgresql18-server-18.4...
[1/1] Deleting files for postgresql18-server-18.4: 100%
==> You should manually remove the "postgres" user
==> You should manually remove the "postgres" group
sudo pkg delete -fy postgresql18-client-18.4 Checking integrity... done (0 conflicting) Installed packages to be REMOVED: postgresql18-client: 18.4 Number of packages to be removed: 1 The operation will free 15 MiB. [1/1] Deinstalling postgresql18-client-18.4... [1/1] Deleting files for postgresql18-client-18.4: 100%

Install PostgreSQL 19 Package

sudo pkg install postgresql19-server

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
New packages to be INSTALLED:
        postgresql19-client: 19.0
        postgresql19-server: 19.0

Number of packages to be installed: 2

The process will require 69 MiB more space.
20 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/2] Fetching postgresql19-server-19.0.pkg: 100%   17 MiB  17.4MB/s    00:01
[2/2] Fetching postgresql19-client-19.0.pkg: 100%    4 MiB   3.7MB/s    00:01
Checking integrity... done (0 conflicting)
[1/2] Installing postgresql19-client-19.0...
[1/2] Extracting postgresql19-client-19.0: 100%
[2/2] Installing postgresql19-server-19.0...
===> Creating groups
Using existing group 'postgres'
===> Creating users
Using existing user 'postgres'
===> Creating homedir(s)

= BACKUP YOUR DATA! =
  As always, backup your data before
  upgrading. If the upgrade leads to a higher
  major revision (e.g. 9.6 -> 10), a dump
  and restore of all databases is
  required. This is *NOT* done by the port!
  See https://www.postgresql.org/docs/current/upgrading.html
  ===
[2/2] Extracting postgresql19-server-19.0: 100%
=====
Message from postgresql19-server-19.0:
--
If you have many tables and many clients running, consider raising kern.maxfiles using sysctl(8), or reconfigure your kernel appropriately.

The port is set up to use autovacuum for new databases, but you might also want to vacuum and perhaps backup your database regularly. There is a periodic script, /usr/local/etc/periodic/daily/502.pgsql, that you may find useful. You can use it to backup and perform vacuum on all
databases nightly. Per default, it performs `vacuum analyze'. See the script for instructions. For autovacuum settings, please review
~postgres/data/postgresql.conf.

If you plan to access your PostgreSQL server using ODBC, please consider running the SQL script /usr/local/share/postgresql/odbc.sql
to get the functions required for ODBC compliance.

Please note that if you use the rc script,
/usr/local/etc/rc.d/postgresql, to initialize the database, unicode
(UTF-8) will be used to store character data by default.  Set
postgresql_initdb_flags or use login.conf settings described below to
alter this behaviour. See the start rc script for more info.

To set limits, environment stuff like locale and collation and other
things, you can set up a class in /etc/login.conf before initializing
the database. Add something similar to this to /etc/login.conf:
---
postgres:\
        :lang=en_US.UTF-8:\
        :setenv=LC_COLLATE=C:\
        :tc=default:
---
and run `cap_mkdb /etc/login.conf'.
Then add 'postgresql_login_class="postgres"' to /etc/rc.conf, or
set it as the postgres user's login class in /etc/passwd.

========

To use PostgreSQL, enable it in rc.conf using

  sysrc postgresql_enable=yes

To initialize the database, run

  service postgresql initdb

You can then start PostgreSQL by running:

  service postgresql start

For postmaster settings, see ~postgres/data/postgresql.conf

NB. FreeBSD's PostgreSQL port logs to syslog by default
    See ~postgres/data/postgresql.conf for more info

NB. If you're not using a checksumming filesystem like ZFS, you might
    wish to enable data checksumming. It can be enabled during
    the initdb phase, by adding the "--data-checksums" flag to
    the postgresql_initdb_flags rcvar. Otherwise you can enable it later by
    using pg_checksums.  Check the initdb(1) manpage for more info
    and make sure you understand the performance implications.
sudo service postgresql initdb

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with this locale configuration:
  locale provider:   libc
  LC_COLLATE:  C
  LC_CTYPE:    C.UTF-8
  LC_MESSAGES: C.UTF-8
  LC_MONETARY: C.UTF-8
  LC_NUMERIC:  C.UTF-8
  LC_TIME:     C.UTF-8
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/db/postgres/data19 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/bin/pg_ctl -D /var/db/postgres/data19 -l logfile start
sudo su - postgres
/usr/local/bin/pg_ctl -D /var/db/postgres/data19 -l logfile start

waiting for server to start.... done
server started

Load Data to PostgreSQL 19

psql
create user abc password 'abc';
psql -U postgres -f /usr/local/www/db1_20260808.sql > /usr/local/www/dbname_20260808_load.txt

Restart Server

sudo shutdown -r now

Published: Aug. 6, 2026

Change Content

The information on this page is user generated content. The content does not claim to be complete or correct.

Everybody is invited to add or change the data. Just click on this link. No login or email is required. Thanks.