git: 4e2b811c04ce - main - databases/postgresql??-server: honour login class set in /etc/passwd

From: Palle Girgensohn <girgen_at_FreeBSD.org>
Date: Thu, 11 Jan 2024 21:51:25 UTC
The branch main has been updated by girgen:

URL: https://cgit.FreeBSD.org/ports/commit/?id=4e2b811c04ce0643e2f526f65a0cef442c14d4a0

commit 4e2b811c04ce0643e2f526f65a0cef442c14d4a0
Author:     Palle Girgensohn <girgen@FreeBSD.org>
AuthorDate: 2024-01-11 21:50:31 +0000
Commit:     Palle Girgensohn <girgen@FreeBSD.org>
CommitDate: 2024-01-11 21:50:31 +0000

    databases/postgresql??-server: honour login class set in /etc/passwd
    
    If postgresql_login_class is not set, honour the setting in /etc/passwd.
    The previous commit ignored the passwd setting and set the login class
    to "default" if it was left unset.
    
    PR:     275851
---
 databases/postgresql12-server/Makefile             |  2 +-
 .../files/pkg-message-server.in                    | 22 ++++++++++---------
 databases/postgresql12-server/files/postgresql.in  | 25 ++++++++++++++--------
 databases/postgresql13-server/Makefile             |  2 +-
 .../files/pkg-message-server.in                    | 22 ++++++++++---------
 databases/postgresql13-server/files/postgresql.in  | 25 ++++++++++++++--------
 databases/postgresql14-server/Makefile             |  2 +-
 .../files/pkg-message-server.in                    | 22 ++++++++++---------
 databases/postgresql14-server/files/postgresql.in  | 25 ++++++++++++++--------
 databases/postgresql15-server/Makefile             |  2 +-
 .../files/pkg-message-server.in                    | 22 ++++++++++---------
 databases/postgresql15-server/files/postgresql.in  | 25 ++++++++++++++--------
 databases/postgresql16-server/Makefile             |  2 +-
 .../files/pkg-message-server.in                    | 22 ++++++++++---------
 databases/postgresql16-server/files/postgresql.in  | 25 ++++++++++++++--------
 15 files changed, 145 insertions(+), 100 deletions(-)

diff --git a/databases/postgresql12-server/Makefile b/databases/postgresql12-server/Makefile
index 755fc000f558..7762b9b91697 100644
--- a/databases/postgresql12-server/Makefile
+++ b/databases/postgresql12-server/Makefile
@@ -1,7 +1,7 @@
 DISTVERSION?=	12.17
 # PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
 # not their own.  Probably best to keep it at ?=0 when reset here too.
-PORTREVISION?=	2
+PORTREVISION?=	3
 
 MAINTAINER?=	pgsql@FreeBSD.org
 
diff --git a/databases/postgresql12-server/files/pkg-message-server.in b/databases/postgresql12-server/files/pkg-message-server.in
index 88e83f067edd..6370d4a017cc 100644
--- a/databases/postgresql12-server/files/pkg-message-server.in
+++ b/databases/postgresql12-server/files/pkg-message-server.in
@@ -14,7 +14,7 @@ is a periodic script, %%PREFIX%%/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.
+~%%PG_USER%%/data/postgresql.conf.
 
 If you plan to access your PostgreSQL server using ODBC, please
 consider running the SQL script %%PREFIX%%/share/postgresql/odbc.sql
@@ -30,28 +30,33 @@ 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:\
+%%PG_USER%%:\
 	: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.
+Then add 'postgresql_login_class="%%PG_USER%%"' to /etc/rc.conf, or
+set it as the %%PG_USER%% 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
 
-  %%PREFIX%%/etc/rc.d/postgresql initdb
+  service postgresql initdb
 
 You can then start PostgreSQL by running:
 
-  %%PREFIX%%/etc/rc.d/postgresql start
+  service postgresql start
 
-For postmaster settings, see ~postgres/data/postgresql.conf
+For postmaster settings, see ~%%PG_USER%%/data/postgresql.conf
 
 NB. FreeBSD's PostgreSQL port logs to syslog by default
-    See ~postgres/data/postgresql.conf for more info
+    See ~%%PG_USER%%/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
@@ -61,9 +66,6 @@ NB. If you're not using a checksumming filesystem like ZFS, you might
     and make sure you understand the performance implications.
 
 ======================================================================
-
-To run PostgreSQL at startup, add
-'postgresql_enable="YES"' to /etc/rc.conf
 EOM
 }
 ]
diff --git a/databases/postgresql12-server/files/postgresql.in b/databases/postgresql12-server/files/postgresql.in
index 390c607f323e..ea232a915475 100644
--- a/databases/postgresql12-server/files/postgresql.in
+++ b/databases/postgresql12-server/files/postgresql.in
@@ -11,7 +11,8 @@
 #  postgresql_data="/var/db/%%PG_USER%%/data%%PG_VERSION%%"
 #  postgresql_flags="-w -s -m fast"
 #  postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
-#  postgresql_login_class="default"
+#  # leave empty to use the login class set in in /etc/passwd:
+#  postgresql_login_class="my_custom_login_class"
 #  postgresql_profiles=""
 #
 # See %%PREFIX%%/share/doc/postgresql/README-server for more info
@@ -29,12 +30,13 @@ command=%%PREFIX%%/bin/pg_ctl
 load_rc_config postgresql
 
 # set defaults
-postgresql_enable=${postgresql_enable:-"NO"}
-postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
-postgresql_user=${postgresql_user:-"%%PG_USER%%"}
-eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data%%PG_VERSION%%"}
-postgresql_login_class=${postgresql_login_class:-"default"}
-postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
+: ${postgresql_enable:="NO"}
+: ${postgresql_flags:="-w -s -m fast"}
+: ${postgresql_user:="%%PG_USER%%"}
+eval _pgdir="~${postgresql_user}/data%%PG_VERSION%%"
+: ${postgresql_data:="${_pgdir}"}
+: ${postgresql_login_class:=""}
+: ${postgresql_initdb_flags:="--encoding=utf-8 --lc-collate=C"}
 
 name=postgresql
 rcvar=postgresql_enable
@@ -62,6 +64,7 @@ if [ -n "$2" ]; then
 		eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}"
 		eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}"
 		eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
+		eval postgresql_login_class="\$postgresql_${profile}_login_class:-${postgresql_login_class}}"
 		eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
 	fi
 else
@@ -104,12 +107,16 @@ command_args="-D ${postgresql_data} ${postgresql_flags}"
 
 postgresql_command()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec ${command} ${command_args} ${rc_arg}"
 }
 
 postgresql_initdb()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
 }
 
 run_rc_command "$1"
diff --git a/databases/postgresql13-server/Makefile b/databases/postgresql13-server/Makefile
index a09a2f212118..8ace87490b33 100644
--- a/databases/postgresql13-server/Makefile
+++ b/databases/postgresql13-server/Makefile
@@ -1,7 +1,7 @@
 DISTVERSION?=	13.13
 # PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
 # not their own.  Probably best to keep it at ?=0 when reset here too.
-PORTREVISION?=	2
+PORTREVISION?=	3
 
 MAINTAINER?=	pgsql@FreeBSD.org
 
diff --git a/databases/postgresql13-server/files/pkg-message-server.in b/databases/postgresql13-server/files/pkg-message-server.in
index 88e83f067edd..6370d4a017cc 100644
--- a/databases/postgresql13-server/files/pkg-message-server.in
+++ b/databases/postgresql13-server/files/pkg-message-server.in
@@ -14,7 +14,7 @@ is a periodic script, %%PREFIX%%/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.
+~%%PG_USER%%/data/postgresql.conf.
 
 If you plan to access your PostgreSQL server using ODBC, please
 consider running the SQL script %%PREFIX%%/share/postgresql/odbc.sql
@@ -30,28 +30,33 @@ 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:\
+%%PG_USER%%:\
 	: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.
+Then add 'postgresql_login_class="%%PG_USER%%"' to /etc/rc.conf, or
+set it as the %%PG_USER%% 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
 
-  %%PREFIX%%/etc/rc.d/postgresql initdb
+  service postgresql initdb
 
 You can then start PostgreSQL by running:
 
-  %%PREFIX%%/etc/rc.d/postgresql start
+  service postgresql start
 
-For postmaster settings, see ~postgres/data/postgresql.conf
+For postmaster settings, see ~%%PG_USER%%/data/postgresql.conf
 
 NB. FreeBSD's PostgreSQL port logs to syslog by default
-    See ~postgres/data/postgresql.conf for more info
+    See ~%%PG_USER%%/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
@@ -61,9 +66,6 @@ NB. If you're not using a checksumming filesystem like ZFS, you might
     and make sure you understand the performance implications.
 
 ======================================================================
-
-To run PostgreSQL at startup, add
-'postgresql_enable="YES"' to /etc/rc.conf
 EOM
 }
 ]
diff --git a/databases/postgresql13-server/files/postgresql.in b/databases/postgresql13-server/files/postgresql.in
index 390c607f323e..ea232a915475 100644
--- a/databases/postgresql13-server/files/postgresql.in
+++ b/databases/postgresql13-server/files/postgresql.in
@@ -11,7 +11,8 @@
 #  postgresql_data="/var/db/%%PG_USER%%/data%%PG_VERSION%%"
 #  postgresql_flags="-w -s -m fast"
 #  postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
-#  postgresql_login_class="default"
+#  # leave empty to use the login class set in in /etc/passwd:
+#  postgresql_login_class="my_custom_login_class"
 #  postgresql_profiles=""
 #
 # See %%PREFIX%%/share/doc/postgresql/README-server for more info
@@ -29,12 +30,13 @@ command=%%PREFIX%%/bin/pg_ctl
 load_rc_config postgresql
 
 # set defaults
-postgresql_enable=${postgresql_enable:-"NO"}
-postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
-postgresql_user=${postgresql_user:-"%%PG_USER%%"}
-eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data%%PG_VERSION%%"}
-postgresql_login_class=${postgresql_login_class:-"default"}
-postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
+: ${postgresql_enable:="NO"}
+: ${postgresql_flags:="-w -s -m fast"}
+: ${postgresql_user:="%%PG_USER%%"}
+eval _pgdir="~${postgresql_user}/data%%PG_VERSION%%"
+: ${postgresql_data:="${_pgdir}"}
+: ${postgresql_login_class:=""}
+: ${postgresql_initdb_flags:="--encoding=utf-8 --lc-collate=C"}
 
 name=postgresql
 rcvar=postgresql_enable
@@ -62,6 +64,7 @@ if [ -n "$2" ]; then
 		eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}"
 		eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}"
 		eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
+		eval postgresql_login_class="\$postgresql_${profile}_login_class:-${postgresql_login_class}}"
 		eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
 	fi
 else
@@ -104,12 +107,16 @@ command_args="-D ${postgresql_data} ${postgresql_flags}"
 
 postgresql_command()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec ${command} ${command_args} ${rc_arg}"
 }
 
 postgresql_initdb()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
 }
 
 run_rc_command "$1"
diff --git a/databases/postgresql14-server/Makefile b/databases/postgresql14-server/Makefile
index 9e885c421f71..0e67fa4dc5d2 100644
--- a/databases/postgresql14-server/Makefile
+++ b/databases/postgresql14-server/Makefile
@@ -1,7 +1,7 @@
 DISTVERSION?=	14.10
 # PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
 # not their own.  Probably best to keep it at ?=0 when reset here too.
-PORTREVISION?=	2
+PORTREVISION?=	3
 
 MAINTAINER?=	pgsql@FreeBSD.org
 
diff --git a/databases/postgresql14-server/files/pkg-message-server.in b/databases/postgresql14-server/files/pkg-message-server.in
index 88e83f067edd..6370d4a017cc 100644
--- a/databases/postgresql14-server/files/pkg-message-server.in
+++ b/databases/postgresql14-server/files/pkg-message-server.in
@@ -14,7 +14,7 @@ is a periodic script, %%PREFIX%%/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.
+~%%PG_USER%%/data/postgresql.conf.
 
 If you plan to access your PostgreSQL server using ODBC, please
 consider running the SQL script %%PREFIX%%/share/postgresql/odbc.sql
@@ -30,28 +30,33 @@ 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:\
+%%PG_USER%%:\
 	: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.
+Then add 'postgresql_login_class="%%PG_USER%%"' to /etc/rc.conf, or
+set it as the %%PG_USER%% 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
 
-  %%PREFIX%%/etc/rc.d/postgresql initdb
+  service postgresql initdb
 
 You can then start PostgreSQL by running:
 
-  %%PREFIX%%/etc/rc.d/postgresql start
+  service postgresql start
 
-For postmaster settings, see ~postgres/data/postgresql.conf
+For postmaster settings, see ~%%PG_USER%%/data/postgresql.conf
 
 NB. FreeBSD's PostgreSQL port logs to syslog by default
-    See ~postgres/data/postgresql.conf for more info
+    See ~%%PG_USER%%/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
@@ -61,9 +66,6 @@ NB. If you're not using a checksumming filesystem like ZFS, you might
     and make sure you understand the performance implications.
 
 ======================================================================
-
-To run PostgreSQL at startup, add
-'postgresql_enable="YES"' to /etc/rc.conf
 EOM
 }
 ]
diff --git a/databases/postgresql14-server/files/postgresql.in b/databases/postgresql14-server/files/postgresql.in
index 390c607f323e..ea232a915475 100644
--- a/databases/postgresql14-server/files/postgresql.in
+++ b/databases/postgresql14-server/files/postgresql.in
@@ -11,7 +11,8 @@
 #  postgresql_data="/var/db/%%PG_USER%%/data%%PG_VERSION%%"
 #  postgresql_flags="-w -s -m fast"
 #  postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
-#  postgresql_login_class="default"
+#  # leave empty to use the login class set in in /etc/passwd:
+#  postgresql_login_class="my_custom_login_class"
 #  postgresql_profiles=""
 #
 # See %%PREFIX%%/share/doc/postgresql/README-server for more info
@@ -29,12 +30,13 @@ command=%%PREFIX%%/bin/pg_ctl
 load_rc_config postgresql
 
 # set defaults
-postgresql_enable=${postgresql_enable:-"NO"}
-postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
-postgresql_user=${postgresql_user:-"%%PG_USER%%"}
-eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data%%PG_VERSION%%"}
-postgresql_login_class=${postgresql_login_class:-"default"}
-postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
+: ${postgresql_enable:="NO"}
+: ${postgresql_flags:="-w -s -m fast"}
+: ${postgresql_user:="%%PG_USER%%"}
+eval _pgdir="~${postgresql_user}/data%%PG_VERSION%%"
+: ${postgresql_data:="${_pgdir}"}
+: ${postgresql_login_class:=""}
+: ${postgresql_initdb_flags:="--encoding=utf-8 --lc-collate=C"}
 
 name=postgresql
 rcvar=postgresql_enable
@@ -62,6 +64,7 @@ if [ -n "$2" ]; then
 		eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}"
 		eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}"
 		eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
+		eval postgresql_login_class="\$postgresql_${profile}_login_class:-${postgresql_login_class}}"
 		eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
 	fi
 else
@@ -104,12 +107,16 @@ command_args="-D ${postgresql_data} ${postgresql_flags}"
 
 postgresql_command()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec ${command} ${command_args} ${rc_arg}"
 }
 
 postgresql_initdb()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
 }
 
 run_rc_command "$1"
diff --git a/databases/postgresql15-server/Makefile b/databases/postgresql15-server/Makefile
index 7dcc58a4c0fa..c4fa63f7baf1 100644
--- a/databases/postgresql15-server/Makefile
+++ b/databases/postgresql15-server/Makefile
@@ -1,7 +1,7 @@
 DISTVERSION?=	15.5
 # PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
 # not their own.  Probably best to keep it at ?=0 when reset here too.
-PORTREVISION?=	2
+PORTREVISION?=	3
 
 MAINTAINER?=	pgsql@FreeBSD.org
 
diff --git a/databases/postgresql15-server/files/pkg-message-server.in b/databases/postgresql15-server/files/pkg-message-server.in
index 88e83f067edd..6370d4a017cc 100644
--- a/databases/postgresql15-server/files/pkg-message-server.in
+++ b/databases/postgresql15-server/files/pkg-message-server.in
@@ -14,7 +14,7 @@ is a periodic script, %%PREFIX%%/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.
+~%%PG_USER%%/data/postgresql.conf.
 
 If you plan to access your PostgreSQL server using ODBC, please
 consider running the SQL script %%PREFIX%%/share/postgresql/odbc.sql
@@ -30,28 +30,33 @@ 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:\
+%%PG_USER%%:\
 	: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.
+Then add 'postgresql_login_class="%%PG_USER%%"' to /etc/rc.conf, or
+set it as the %%PG_USER%% 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
 
-  %%PREFIX%%/etc/rc.d/postgresql initdb
+  service postgresql initdb
 
 You can then start PostgreSQL by running:
 
-  %%PREFIX%%/etc/rc.d/postgresql start
+  service postgresql start
 
-For postmaster settings, see ~postgres/data/postgresql.conf
+For postmaster settings, see ~%%PG_USER%%/data/postgresql.conf
 
 NB. FreeBSD's PostgreSQL port logs to syslog by default
-    See ~postgres/data/postgresql.conf for more info
+    See ~%%PG_USER%%/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
@@ -61,9 +66,6 @@ NB. If you're not using a checksumming filesystem like ZFS, you might
     and make sure you understand the performance implications.
 
 ======================================================================
-
-To run PostgreSQL at startup, add
-'postgresql_enable="YES"' to /etc/rc.conf
 EOM
 }
 ]
diff --git a/databases/postgresql15-server/files/postgresql.in b/databases/postgresql15-server/files/postgresql.in
index 390c607f323e..ea232a915475 100644
--- a/databases/postgresql15-server/files/postgresql.in
+++ b/databases/postgresql15-server/files/postgresql.in
@@ -11,7 +11,8 @@
 #  postgresql_data="/var/db/%%PG_USER%%/data%%PG_VERSION%%"
 #  postgresql_flags="-w -s -m fast"
 #  postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
-#  postgresql_login_class="default"
+#  # leave empty to use the login class set in in /etc/passwd:
+#  postgresql_login_class="my_custom_login_class"
 #  postgresql_profiles=""
 #
 # See %%PREFIX%%/share/doc/postgresql/README-server for more info
@@ -29,12 +30,13 @@ command=%%PREFIX%%/bin/pg_ctl
 load_rc_config postgresql
 
 # set defaults
-postgresql_enable=${postgresql_enable:-"NO"}
-postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
-postgresql_user=${postgresql_user:-"%%PG_USER%%"}
-eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data%%PG_VERSION%%"}
-postgresql_login_class=${postgresql_login_class:-"default"}
-postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
+: ${postgresql_enable:="NO"}
+: ${postgresql_flags:="-w -s -m fast"}
+: ${postgresql_user:="%%PG_USER%%"}
+eval _pgdir="~${postgresql_user}/data%%PG_VERSION%%"
+: ${postgresql_data:="${_pgdir}"}
+: ${postgresql_login_class:=""}
+: ${postgresql_initdb_flags:="--encoding=utf-8 --lc-collate=C"}
 
 name=postgresql
 rcvar=postgresql_enable
@@ -62,6 +64,7 @@ if [ -n "$2" ]; then
 		eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}"
 		eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}"
 		eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
+		eval postgresql_login_class="\$postgresql_${profile}_login_class:-${postgresql_login_class}}"
 		eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
 	fi
 else
@@ -104,12 +107,16 @@ command_args="-D ${postgresql_data} ${postgresql_flags}"
 
 postgresql_command()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec ${command} ${command_args} ${rc_arg}"
 }
 
 postgresql_initdb()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
 }
 
 run_rc_command "$1"
diff --git a/databases/postgresql16-server/Makefile b/databases/postgresql16-server/Makefile
index b33f71a47525..9c08dd554452 100644
--- a/databases/postgresql16-server/Makefile
+++ b/databases/postgresql16-server/Makefile
@@ -2,7 +2,7 @@ PORTNAME?=	postgresql
 DISTVERSION?=	16.1
 # PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
 # not their own.  Probably best to keep it at ?=0 when reset here too.
-PORTREVISION?=	2
+PORTREVISION?=	3
 CATEGORIES?=	databases
 MASTER_SITES=	PGSQL/source/v${DISTVERSION}
 PKGNAMESUFFIX?= ${PORTVERSION:R}${COMPONENT}
diff --git a/databases/postgresql16-server/files/pkg-message-server.in b/databases/postgresql16-server/files/pkg-message-server.in
index 88e83f067edd..6370d4a017cc 100644
--- a/databases/postgresql16-server/files/pkg-message-server.in
+++ b/databases/postgresql16-server/files/pkg-message-server.in
@@ -14,7 +14,7 @@ is a periodic script, %%PREFIX%%/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.
+~%%PG_USER%%/data/postgresql.conf.
 
 If you plan to access your PostgreSQL server using ODBC, please
 consider running the SQL script %%PREFIX%%/share/postgresql/odbc.sql
@@ -30,28 +30,33 @@ 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:\
+%%PG_USER%%:\
 	: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.
+Then add 'postgresql_login_class="%%PG_USER%%"' to /etc/rc.conf, or
+set it as the %%PG_USER%% 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
 
-  %%PREFIX%%/etc/rc.d/postgresql initdb
+  service postgresql initdb
 
 You can then start PostgreSQL by running:
 
-  %%PREFIX%%/etc/rc.d/postgresql start
+  service postgresql start
 
-For postmaster settings, see ~postgres/data/postgresql.conf
+For postmaster settings, see ~%%PG_USER%%/data/postgresql.conf
 
 NB. FreeBSD's PostgreSQL port logs to syslog by default
-    See ~postgres/data/postgresql.conf for more info
+    See ~%%PG_USER%%/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
@@ -61,9 +66,6 @@ NB. If you're not using a checksumming filesystem like ZFS, you might
     and make sure you understand the performance implications.
 
 ======================================================================
-
-To run PostgreSQL at startup, add
-'postgresql_enable="YES"' to /etc/rc.conf
 EOM
 }
 ]
diff --git a/databases/postgresql16-server/files/postgresql.in b/databases/postgresql16-server/files/postgresql.in
index 390c607f323e..ea232a915475 100644
--- a/databases/postgresql16-server/files/postgresql.in
+++ b/databases/postgresql16-server/files/postgresql.in
@@ -11,7 +11,8 @@
 #  postgresql_data="/var/db/%%PG_USER%%/data%%PG_VERSION%%"
 #  postgresql_flags="-w -s -m fast"
 #  postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
-#  postgresql_login_class="default"
+#  # leave empty to use the login class set in in /etc/passwd:
+#  postgresql_login_class="my_custom_login_class"
 #  postgresql_profiles=""
 #
 # See %%PREFIX%%/share/doc/postgresql/README-server for more info
@@ -29,12 +30,13 @@ command=%%PREFIX%%/bin/pg_ctl
 load_rc_config postgresql
 
 # set defaults
-postgresql_enable=${postgresql_enable:-"NO"}
-postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
-postgresql_user=${postgresql_user:-"%%PG_USER%%"}
-eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data%%PG_VERSION%%"}
-postgresql_login_class=${postgresql_login_class:-"default"}
-postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
+: ${postgresql_enable:="NO"}
+: ${postgresql_flags:="-w -s -m fast"}
+: ${postgresql_user:="%%PG_USER%%"}
+eval _pgdir="~${postgresql_user}/data%%PG_VERSION%%"
+: ${postgresql_data:="${_pgdir}"}
+: ${postgresql_login_class:=""}
+: ${postgresql_initdb_flags:="--encoding=utf-8 --lc-collate=C"}
 
 name=postgresql
 rcvar=postgresql_enable
@@ -62,6 +64,7 @@ if [ -n "$2" ]; then
 		eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}"
 		eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}"
 		eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
+		eval postgresql_login_class="\$postgresql_${profile}_login_class:-${postgresql_login_class}}"
 		eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
 	fi
 else
@@ -104,12 +107,16 @@ command_args="-D ${postgresql_data} ${postgresql_flags}"
 
 postgresql_command()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec ${command} ${command_args} ${rc_arg}"
 }
 
 postgresql_initdb()
 {
-    ${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
+    ${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
+	    -l ${postgresql_user} \
+	    -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
 }
 
 run_rc_command "$1"