i installed postgresql and starting to use it for
first time. here is what i think could be improved.
1.
i think the postgres package readme could mention,
that while there is no default database location
the rc.d script has /var/postgresql/data hardcoded
in it.
2.
without actually initializing a database i tried:
$ sudo /etc/rc.d/postgresql start
postgresql(ok) # ???
$ sudo /etc/rc.d/postgresql check
postgresql(failed)
a bit of "set -x" reveals:
$ sudo su -l -c daemon -s /bin/sh _postgresql -c \
"/usr/local/bin/pg_ctl -D /var/postgresql/data \
start -l /var/postgresql/logfile"
server starting
$ echo $?
0
# tail -1 /var/postgresql/logfile
postgres cannot access the server configuration file
"/var/postgresql/data/postgresql.conf": No such file or directory
what happens is, that pg_ctl's return code cannot
be trusted because it starts the server in background
and does not wait for confirmation. to really make
sure the server was started, -w must be used:
$ sudo su -l -c daemon -s /bin/sh _postgresql -c \
"/usr/local/bin/pg_ctl -w -D /var/postgresql/data \
start -l /var/postgresql/logfile"
waiting for server to start........ stopped waiting
pg_ctl: could not start server
Examine the log output.
$ echo $?
1
i dont know how long it takes to start up a huge
postgres installation with -w, and maybe it is good
to have it start in the background at startup time,
but it can mask startup errors like this...
3.
my last issue is "check": i think it is a bit of overkill
that i have to be root to check if postgres is running.
this is because daemon_user is defined. so not even
'_postgresql' is allowed to check, although it
is allowed to run the actual 'pg_ctl check' command.
i think it would make sense to get rid of rc_usercheck=NO,
all of rc_check() and override pexp= to the actual
daemon signature instead of pg_ctl.. this way any user
can run the check.
please find attached my patch that tries to remedy
the issues mentioned above.
-f
--
the best way out of a difficulty is through it.
Index: pkg/README-server
===================================================================
RCS file: /cvs/ports/databases/postgresql/pkg/README-server,v
retrieving revision 1.16
diff -u -p -r1.16 README-server
--- pkg/README-server 21 Apr 2014 13:13:29 -0000 1.16
+++ pkg/README-server 22 Sep 2014 16:57:43 -0000
@@ -14,19 +14,20 @@ initialized using the initdb command.
If you are installing PostgreSQL for the first time, you have to create
a default database first. In the following example we install a database
-in /var/postgresql/data with a dba account 'postgres' and md5 authentication.
-We will be prompted for a password to protect the dba account:
+in /var/postgresql/data (this location is also used in the rc script)
+with a dba account 'postgres' and md5 authentication. We will be prompted
+for a password to protect the dba account:
# su - _postgresql
$ mkdir /var/postgresql/data
$ initdb -D /var/postgresql/data -U postgres -A md5 -W
-Please note that by default the cluster's encoding will be SQL_ASCII. If
+Please note that by default the cluster's encoding will be SQL_ASCII. If
you want to have an another default encoding, use the option -E with initdb:
$ initdb -D /var/postgresql/data -U postgres -E UTF8 -A md5 -W
-If your cluster is already created, you can specify an another encoding when
+If your cluster is already created, you can specify an another encoding when
you create a new database with this command:
CREATE DATABASE xxx TEMPLATE template0 ENCODING 'xxx' ;
@@ -106,7 +107,7 @@ maintainers so that we can update this f
Upgrade Howto (for a major upgrade)
===================================
-If you didn't install PostgreSQL by following this README,
+If you didn't install PostgreSQL by following this README,
you must adapt these instructions to your setup.
1) Backup all your data:
Index: pkg/postgresql.rc
===================================================================
RCS file: /cvs/ports/databases/postgresql/pkg/postgresql.rc,v
retrieving revision 1.10
diff -u -p -r1.10 postgresql.rc
--- pkg/postgresql.rc 4 Aug 2012 15:28:14 -0000 1.10
+++ pkg/postgresql.rc 22 Sep 2014 16:57:43 -0000
@@ -10,11 +10,7 @@ daemon_user="_postgresql"
. /etc/rc.d/rc.subr
-rc_usercheck=NO
-
-rc_check() {
- ${rcexec} "${daemon} -D ${datadir} status"
-}
+pexp="${TRUEPREFIX}/bin/postgres -D ${datadir}"
rc_reload() {
${rcexec} "${daemon} -D ${datadir} reload"
@@ -22,7 +18,7 @@ rc_reload() {
rc_start() {
rm -f ${datadir}/postmaster.pid
- ${rcexec} "${daemon} -D ${datadir} start ${daemon_flags}"
+ ${rcexec} "${daemon} -D ${datadir} start -w ${daemon_flags}"
}
rc_stop() {