[PATCH] services: postgresql: Log from pg_ctl.

  • Done
  • quality assurance status badge
Details
2 participants
  • Christopher Baines
  • Mathieu Othacehe
Owner
unassigned
Submitted by
Christopher Baines
Severity
normal

Debbugs page

Christopher Baines wrote 4 years ago
(address . guix-patches@gnu.org)
20210101101015.6524-1-mail@cbaines.net
pg_ctl will output errors when starting PostgreSQL, for example about errors
in the configuration file. Without getting pg_ctl to log to a file, I'm not
sure how to find those errors.

* gnu/services/databases.scm (postgresql-activation): Create
/var/log/postgresql.
(postgresql-shepherd-service): Pass --log=/var/log/postgresql/pg_ctl to
pg_ctl.
---
gnu/services/databases.scm | 5 +++++
1 file changed, 5 insertions(+)

Toggle diff (25 lines)
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index d2dc5f0da8..479a3c56f7 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -205,6 +205,10 @@ host all all ::1/128 md5"))
(mkdir-p #$data-directory)
(chown #$data-directory (passwd:uid user) (passwd:gid user))
+ ;; Create log directory
+ (mkdir-p "/var/log/postgresql")
+ (chown "/var/log/postgresql" (passwd:uid user) (passwd:gid user))
+
;; Drop privileges and init state directory in a new
;; process. Wait for it to finish before proceeding.
(match (primitive-fork)
@@ -247,6 +251,7 @@ host all all ::1/128 md5"))
(setgid (passwd:gid user))
(setuid (passwd:uid user))
(execl pg_ctl pg_ctl "-D" #$data-directory "-o" options
+ "--log=/var/log/postgresql/pg_ctl"
mode)))))))
(pid-file (in-vicinity data-directory "postmaster.pid"))
(action (lambda args
--
2.29.2
Mathieu Othacehe wrote 4 years ago
(name . Christopher Baines)(address . mail@cbaines.net)(address . 45588@debbugs.gnu.org)
87mtxmpghz.fsf@gnu.org
Hello Chris,

Toggle quote (4 lines)
> pg_ctl will output errors when starting PostgreSQL, for example about errors
> in the configuration file. Without getting pg_ctl to log to a file, I'm not
> sure how to find those errors.

On Ubuntu, I noticed that pg_ctl logs are located in
'/var/log/postgresql/postgresql-12-main.log'.

Turns out it's using a Debian wrapper called pg_ctlcluster around pg_ctl
that is setting up logging between other things.

You could maybe call the log file 'pg_ctl.log', otherwise seems fine.

Thanks,

Mathieu
Mathieu Othacehe wrote 4 years ago
(name . Christopher Baines)(address . mail@cbaines.net)(address . 45588@debbugs.gnu.org)
87a6tb4oeb.fsf@gnu.org
Hello Chris,

Toggle quote (2 lines)
> You could maybe call the log file 'pg_ctl.log', otherwise seems fine.

I added what you proposed to a patch refactoring PostgreSQL service

Thanks,

Mathieu
Christopher Baines wrote 4 years ago
(address . 45588-close@debbugs.gnu.org)
878s7fn3a5.fsf@cbaines.net
Christopher Baines <mail@cbaines.net> writes:

Toggle quote (36 lines)
> pg_ctl will output errors when starting PostgreSQL, for example about errors
> in the configuration file. Without getting pg_ctl to log to a file, I'm not
> sure how to find those errors.
>
> * gnu/services/databases.scm (postgresql-activation): Create
> /var/log/postgresql.
> (postgresql-shepherd-service): Pass --log=/var/log/postgresql/pg_ctl to
> pg_ctl.
> ---
> gnu/services/databases.scm | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
> index d2dc5f0da8..479a3c56f7 100644
> --- a/gnu/services/databases.scm
> +++ b/gnu/services/databases.scm
> @@ -205,6 +205,10 @@ host all all ::1/128 md5"))
> (mkdir-p #$data-directory)
> (chown #$data-directory (passwd:uid user) (passwd:gid user))
>
> + ;; Create log directory
> + (mkdir-p "/var/log/postgresql")
> + (chown "/var/log/postgresql" (passwd:uid user) (passwd:gid user))
> +
> ;; Drop privileges and init state directory in a new
> ;; process. Wait for it to finish before proceeding.
> (match (primitive-fork)
> @@ -247,6 +251,7 @@ host all all ::1/128 md5"))
> (setgid (passwd:gid user))
> (setuid (passwd:uid user))
> (execl pg_ctl pg_ctl "-D" #$data-directory "-o" options
> + "--log=/var/log/postgresql/pg_ctl"
> mode)))))))
> (pid-file (in-vicinity data-directory "postmaster.pid"))
> (action (lambda args

?
Your comment

This issue is archived.

To comment on this conversation send an email to 45588@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 45588
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help