Unable to run the PostgreSQL pkg on FreeBSD 14.1

I am trying to use the PostgeSQL package on FreeBSD 14.1 and I've tried following these three guides exactly.


The problem is that PostgreSQL server will not start on root.

Code:
# service postgresql start
2024-08-02 12:47:27.295 UTC [8815] LOG:  ending log output to stderr
2024-08-02 12:47:27.295 UTC [8815] HINT:  Future log output will go to log destination "syslog".
pg_ctl: could not start server

It seems that starting the service on root is not permitted:

Code:
# postgres
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.

I run into the exact same problem whether I use postgresql16 or postgresql15.
 
Seems to work just fine:
Code:
root@fbsd-test:~ # ps -ax | grep postgres
26292  1  S+       0:00.00 grep postgres
root@fbsd-test:~ #
root@fbsd-test:~ # pkg install postgresql16-server
Updating FreeBSD repository catalogue...
Fetching data.pkg: 100%    7 MiB   7.4MB/s    00:01
Processing entries: 100%
FreeBSD repository update completed. 34465 packages processed.
All repositories are up to date.
The following 8 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        icu: 74.2_1,1 [FreeBSD]
        libedit: 3.1.20240517,1 [FreeBSD]
        llvm15: 15.0.7_10 [FreeBSD]
        lua53: 5.3.6_1 [FreeBSD]
        perl5: 5.36.3_1 [FreeBSD]
        postgresql16-client: 16.3 [FreeBSD]
        postgresql16-server: 16.3 [FreeBSD]
        python311: 3.11.9 [FreeBSD]

Number of packages to be installed: 8

The process will require 1 GiB more space.
196 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/5] Fetching postgresql16-server-16.3.pkg: 100%   16 MiB  16.7MB/s    00:01
[2/5] Fetching lua53-5.3.6_1.pkg: 100%  300 KiB 307.3kB/s    00:01
[3/5] Fetching python311-3.11.9.pkg: 100%   27 MiB  14.0MB/s    00:02
[4/5] Fetching postgresql16-client-16.3.pkg: 100%    3 MiB   3.5MB/s    00:01
[5/5] Fetching llvm15-15.0.7_10.pkg: 100%  150 MiB  19.7MB/s    00:08
Checking integrity... done (0 conflicting)
[1/8] Installing libedit-3.1.20240517,1...
[1/8] Extracting libedit-3.1.20240517,1: 100%
[2/8] Installing lua53-5.3.6_1...
[2/8] Extracting lua53-5.3.6_1: 100%
[3/8] Installing python311-3.11.9...
[3/8] Extracting python311-3.11.9: 100%
[4/8] Installing perl5-5.36.3_1...
[4/8] Extracting perl5-5.36.3_1: 100%
[5/8] Installing icu-74.2_1,1...
[5/8] Extracting icu-74.2_1,1: 100%
[6/8] Installing postgresql16-client-16.3...
[6/8] Extracting postgresql16-client-16.3: 100%
[7/8] Installing llvm15-15.0.7_10...
[7/8] Extracting llvm15-15.0.7_10: 100%
[8/8] Installing postgresql16-server-16.3...
===> Creating groups
Creating group 'postgres' with gid '770'
===> Creating users
Creating user 'postgres' with uid '770'
===> 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
  ===========================================
[8/8] Extracting postgresql16-server-16.3: 100%
=====
Message from python311-3.11.9:

--
Note that some standard Python modules are provided as separate ports
as they require additional dependencies. They are available as:

py311-gdbm       databases/py-gdbm@py311
py311-sqlite3    databases/py-sqlite3@py311
py311-tkinter    x11-toolkits/py-tkinter@py311
=====
Message from postgresql16-client-16.3:

--
The PostgreSQL port has a collection of "side orders":

postgresql-docs
  For all of the html documentation

p5-Pg
  A perl5 API for client access to PostgreSQL databases.

postgresql-tcltk
  If you want tcl/tk client support.

postgresql-jdbc
  For Java JDBC support.

postgresql-odbc
  For client access from unix applications using ODBC as access
  method. Not needed to access unix PostgreSQL servers from Win32
  using ODBC. See below.

ruby-postgres, py-psycopg2
  For client access to PostgreSQL databases using the ruby & python
  languages.

postgresql-plperl, postgresql-pltcl & postgresql-plruby
  For using perl5, tcl & ruby as procedural languages.

postgresql-contrib
  Lots of contributed utilities, postgresql functions and
  datatypes. There you find pg_standby, pgcrypto and many other cool
  things.

etc...
=====
Message from postgresql16-server-16.3:

--
For procedural languages and postgresql functions, please note that
you might have to update them when updating the server.

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.

======================================================================

SECURITY ADVICE

If upgradring from a version 16.x < 16.3
A security vulnerability was found in the system views pg_stats_ext
and pg_stats_ext_exprs, potentially allowing authenticated database
users to see data they shouldn't.  If this is of concern in your
installation, run the SQL script /usr/local/share/postgresql/fix-CVE-2024-4317.sql
for each of your databases. For details, see
https://www.postgresql.org/support/security/CVE-2024-4317/
root@fbsd-test:~ # service postgresql initdb
Cannot 'initdb' postgresql. Set postgresql_enable to YES in /etc/rc.conf or use 'oneinitdb' instead of 'initdb'.
root@fbsd-test:~ # sysrc postgresql_enable="YES"
postgresql_enable:  -> YES
root@fbsd-test:~ # 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:
  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/data16 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... CET
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/data16 -l logfile start

root@fbsd-test:~ # service postgresql start
2024-08-02 16:02:26.885 CEST [26542] LOG:  ending log output to stderr
2024-08-02 16:02:26.885 CEST [26542] HINT:  Future log output will go to log destination "syslog".
root@fbsd-test:~ # ps -aux | grep postgres
postgres 26542   0.0  0.8 182068 31724  -  Ss   16:02       0:00.03 /usr/local/bin/postgres -D /var/db/postgres/data16
postgres 26543   0.0  0.8 182068 31784  -  Ss   16:02       0:00.00 postgres: checkpointer  (postgres)
postgres 26544   0.0  0.8 182068 31776  -  Ss   16:02       0:00.00 postgres: background writer  (postgres)
postgres 26546   0.0  0.8 182068 31776  -  Ss   16:02       0:00.00 postgres: walwriter  (postgres)
postgres 26547   0.0  0.8 185652 32140  -  Ss   16:02       0:00.00 postgres: autovacuum launcher  (postgres)
postgres 26548   0.0  0.8 185652 32108  -  Ss   16:02       0:00.00 postgres: logical replication launcher  (postgres)
root     26550   0.0  0.1  12808  2396  1  S+   16:02       0:00.00 grep postgres
 
Hmm, that's very strange. I uninstalled it and installed just the postgresql16-server (no client) and now it seems to work fine just as SirDice did it. And then I also install the postgresql16-client and it works fine now. Not sure what I did wrong. Thanks.
 
I have no issues with postgres in 14.1


# service postgresql start <- by root or su
2024-08-06 10:59:54.950 PDT [73245] LOG: ending log output to stderr
2024-08-06 10:59:54.950 PDT [73245] HINT: Future log output will go to log destination "syslog".

# ps -ax | grep postgres
73245 - Is 0:00.03 /usr/local/bin/postgres -D /var/db/postgres/data16
73246 - Is 0:00.00 postgres: checkpointer (postgres)
73247 - Ss 0:00.01 postgres: background writer (postgres)
73249 - Ss 0:00.00 postgres: walwriter (postgres)
73250 - Is 0:00.00 postgres: autovacuum launcher (postgres)
73251 - Is 0:00.00 postgres: logical replication launcher (postgres)
 
Back
Top