The last flavor of BSD we’ll look at is NetBSD. We already had FreeBSD (here and here) and OpenBSD (here and here). If you want to learn more about the history of NetBSD and the goals of the project, head over to the about page on the official website. We’ll use the same structure as in the other BSD related posts: First we’ll look at how you can get started with PostgreSQL on NetBSD with packages in this post. The next post we’ll be about getting PostgreSQL up and running on NetBSD from source code.

Again, we’ll not look into how to get NetBSD installed. The text based installation procedure is really simple and you should get it up and running within a few minutes.

The tool on NetBSD to apply the latest updates is pkgin. As this is not installed by default in a minimal installation we need to do that first:

localhost$ PKG_PATH="https://cdn.NetBSD.org/pub/pkgsrc/packages/NetBSD/$(uname -p)/$(uname -r | cut -d_ -f1)/All"
localhost$ export PKG_PATH
localhost$ pkg_add pkgin
pkg_add: Warning: package `pkgin-21.12.0nb2' was built for a platform:
pkg_add: NetBSD/x86_64 9.0 (pkg) vs. NetBSD/x86_64 9.3 (this host)
pkg_add: Warning: package `pkg_install-20211115' was built for a platform:
pkg_add: NetBSD/x86_64 9.0 (pkg) vs. NetBSD/x86_64 9.3 (this host)
pkgin-21.12.0nb2: copying /usr/pkg/share/examples/pkgin/repositories.conf.example to /usr/pkg/etc/pkgin/repositories.conf
localhost$ which pkgin
/usr/pkg/bin/pkgin

Now we can update the packages to the latest release:

localhost$ pkgin update
reading local summary...
processing local summary...
processing remote summary (https://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/x86_64/9.0/All)...
pkg_summary.bz2                                                                                                   100% 3839KB 479.9KB/s   00:08     
localhost$ pkgin upgrade
calculating dependencies...done.
nothing to do.
localhost#

Lets check what we have available when it comes to PostgreSQL:

netbsd-latest$ pkgin search postgresql | grep server
dovecot-pgsql-2.3.19.1  Secure IMAP and POP3 server (PostgreSQL plugin)
mydns-pgsql-1.1.0nb18  PostgreSQL-based DNS server
pgpool-3.4.1         Connection pooling/replication server for PostgreSQL
php56-davical-1.1.10nb1  Simple CalDAV server using a PostgreSQL backend
php74-davical-1.1.10nb1  Simple CalDAV server using a PostgreSQL backend
php80-davical-1.1.10nb1  Simple CalDAV server using a PostgreSQL backend
php81-davical-1.1.10nb1  Simple CalDAV server using a PostgreSQL backend
postfix-pgsql-3.6.4  Postfix SMTP server PostgreSQL backend module
postgresql10-pgpool2-4.3.2  Middleware between PostgreSQL servers and a PostgreSQL database client
postgresql10-server-10.21  PostgreSQL database server programs
postgresql11-pgpool2-4.3.2  Middleware between PostgreSQL servers and a PostgreSQL database client
postgresql11-server-11.16  PostgreSQL database server programs
postgresql12-pgpool2-4.3.2  Middleware between PostgreSQL servers and a PostgreSQL database client
postgresql12-server-12.11  PostgreSQL database server programs
postgresql13-pgpool2-4.3.2  Middleware between PostgreSQL servers and a PostgreSQL database client
postgresql13-server-13.7  PostgreSQL database server programs
postgresql14-pgpool2-4.3.2  Middleware between PostgreSQL servers and a PostgreSQL database client
postgresql14-server-14.4  PostgreSQL database server programs
zabbix-server-postgresql-5.0.17nb2  Enterprise-class Monitoring Solution for Everyone

Versions 10 to 14, and not only the latest version as in OpenBSD, so more choice in NetBSD. The minor version is also more up to date with 14.4 (one minor release behind as of today).

Again, and no surprise, the installation from packages is easy:

netbsd-latest# pkgin install postgresql14-server-14.4 
calculating dependencies...done.

5 packages to install:
  postgresql14-server-14.4 postgresql14-client-14.4 lz4-1.9.3nb1 libxml2-2.9.14 xmlcatmgr-2.2nb1

0 to refresh, 0 to upgrade, 5 to install
16M to download, 49M to install

proceed ? [Y/n] y
xmlcatmgr-2.2nb1.tgz                                                                                              100%   29KB  29.4KB/s   00:00    
postgresql14-client-14.4.tgz                                                                                      100% 5720KB   2.8MB/s   00:02    
lz4-1.9.3nb1.tgz                                                                                                  100%  345KB 344.6KB/s   00:01    
libxml2-2.9.14.tgz                                                                                                100% 2305KB   1.1MB/s   00:02    
postgresql14-server-14.4.tgz                                                                                      100% 7477KB   2.4MB/s   00:03    
installing postgresql14-server-14.4...
xmlcatmgr-2.2nb1: copying /usr/pkg/share/examples/xmlcatmgr/catalog.etc.sgml to /usr/pkg/etc/sgml/catalog
xmlcatmgr-2.2nb1: copying /usr/pkg/share/examples/xmlcatmgr/catalog.etc.xml to /usr/pkg/etc/xml/catalog
xmlcatmgr-2.2nb1: copying /usr/pkg/share/examples/xmlcatmgr/catalog.share.sgml to /usr/pkg/share/sgml/catalog
xmlcatmgr-2.2nb1: copying /usr/pkg/share/examples/xmlcatmgr/catalog.share.xml to /usr/pkg/share/xml/catalog
postgresql14-client-14.4: copying /usr/pkg/share/postgresql/pg_service.conf.sample to /usr/pkg/etc/postgresql/pg_service.conf
postgresql14-client-14.4: copying /usr/pkg/share/postgresql/psqlrc.sample to /usr/pkg/etc/postgresql/psqlrc
postgresql14-server-14.4: Creating group ``pgsql''
postgresql14-server-14.4: Creating user ``pgsql''
===========================================================================
The following files should be created for postgresql14-server-14.4:

        /etc/rc.d/pgsql (m=0755)
            [/usr/pkg/share/examples/rc.d/pgsql]

===========================================================================
installing postgresql14-client-14.4...
postgresql14-client-14.4: copying /usr/pkg/share/postgresql/pg_service.conf.sample to /usr/pkg/etc/postgresql/pg_service.conf
postgresql14-client-14.4: copying /usr/pkg/share/postgresql/psqlrc.sample to /usr/pkg/etc/postgresql/psqlrc
installing lz4-1.9.3nb1...
installing libxml2-2.9.14...
installing xmlcatmgr-2.2nb1...
xmlcatmgr-2.2nb1: copying /usr/pkg/share/examples/xmlcatmgr/catalog.etc.sgml to /usr/pkg/etc/sgml/catalog
xmlcatmgr-2.2nb1: copying /usr/pkg/share/examples/xmlcatmgr/catalog.etc.xml to /usr/pkg/etc/xml/catalog
xmlcatmgr-2.2nb1: copying /usr/pkg/share/examples/xmlcatmgr/catalog.share.sgml to /usr/pkg/share/sgml/catalog
xmlcatmgr-2.2nb1: copying /usr/pkg/share/examples/xmlcatmgr/catalog.share.xml to /usr/pkg/share/xml/catalog
pkg_install warnings: 1, errors: 0
pkg_install error log can be found in /var/db/pkgin/pkg_install-err.log
reading local summary...
processing local summary...
marking postgresql14-server-14.4 as non auto-removable

A few dependencies have been installed. Lets do what the output is recommending and copy the template to /etc/rc.d and enable the service in rc.conf:

netbsd-latest$ cp /usr/pkg/share/examples/rc.d/pgsql /etc/rc.d/pgsql
netbsd-latest$ cat /etc/rc.conf | grep pg
pgsql=YES

Initializing the cluster and starting it up can now be done using the “service” command:

netbsd-latest$ service pgsql initdb
Initializing PostgreSQL databases.
initdb: warning: enabling "trust" authentication for local connections
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.
netbsd-latest$ service pgsql start
Starting pgsql.

That was easy and PostgreSQL is up and running:

netbsd-latest$ psql -U pgsql postgres
psql (14.4)
Type "help" for help.

postgres=# select version();
                                     version                                     
---------------------------------------------------------------------------------
 PostgreSQL 14.4 on x86_64--netbsd, compiled by gcc (nb4 20200810) 7.5.0, 64-bit
(1 row)

postgres=# 

As usual, installation from packages is not a big deal. NetBSD comes with a couple of PostgreSQL versions to chose from and seems to be more up to date than OpenBSD.