HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

PostgreSQL doesn't log

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqldoesnlog

Problem

I'm using ArchLinux and PostgreSQL 9.4.4 and have enabled the logging in the config file:

$ sudo egrep -v "^[[:blank:]]*($|#|//|/\*| \*|\*/)" /var/lib/postgres/data/postgresql.conf

max_connections = 1024          # (change requires restart)
shared_buffers = 128MB          # min 128kB
dynamic_shared_memory_type = posix  # the default is the first option
logging_collector = on      # Enable capturing of stderr and csvlog
log_directory = '/tmp'      # directory where log files are written,
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
log_file_mode = 0644            # creation mode for log files,
log_error_verbosity = verbose       # terse, default, or verbose messages
log_statement = 'all'           # none, ddl, mod, all
log_timezone = 'Asia/Jakarta'
datestyle = 'iso, dmy'
timezone = 'Asia/Jakarta'
lc_messages = 'en_CA.UTF-8'         # locale for system error message
lc_monetary = 'en_CA.UTF-8'         # locale for monetary formatting
lc_numeric = 'en_CA.UTF-8'          # locale for number formatting
lc_time = 'en_CA.UTF-8'             # locale for time formatting
default_text_search_config = 'pg_catalog.english'


then restart or reload the service:

sudo systemctl restart postgresql
sudo systemctl reload postgresql


the loaded settings:

```
postgres=# SELECT name, setting FROM pg_settings WHERE name LIKE '%log%';
name | setting
-----------------------------+--------------------------------
log_autovacuum_min_duration | -1
log_checkpoints | off
log_connections | off
log_destination | stderr
log_directory | /tmp
log_disconnections | off
log_duration | off
log_error_verbosity | verbose
log_executor_stats | off
log_file_mode | 0644
log_filename | postgresql-%Y-%m-%d_%H%M%S.log
log_hostname | off
log_line_prefix |
lo

Solution

The logging collector tries to capture stderr and write it to a file. But it looks like systemd wins the redirecting war, and sends the output to the journal. You can check the systemd journal with:

journalctl -u postgresql


The systemd configuration is in usr/lib/systemd/system/postgresql.service. I've tried various settings for StandardError, but none seems to allow the regular Postgres logging to do its work.

Code Snippets

journalctl -u postgresql

Context

StackExchange Database Administrators Q#105384, answer score: 3

Revisions (0)

No revisions yet.