Re: Postgres pgaudit CSV-Logs can they be written outside the instance directory.

From: Justin <zzzzz(dot)graf(at)gmail(dot)com>
To: "Subramanian,Ramachandran" <ramachandran(dot)subramanian(at)alte-leipziger(dot)de>
Cc: "pgsql-novice(at)lists(dot)postgresql(dot)org" <pgsql-novice(at)lists(dot)postgresql(dot)org>
Subject: Re: Postgres pgaudit CSV-Logs can they be written outside the instance directory.
Date: 2026-09-01 12:12:24
Message-ID: CALL-XePqxFJvM-D8DUiMn7_Kp9ms-hAwBaYLTcRY+_hfq1C64g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, Sep 1, 2026 at 5:26 AM Subramanian,Ramachandran <
ramachandran(dot)subramanian(at)alte-leipziger(dot)de> wrote:

> We have a statuatory monitoring requirement (SIEM-SOC/NTT) for which we
> are asked to turn on the below parms.
>
>
>
> The problem is, that so much data is generated, that the logs become
> bigger than the actual database. Every 1 hour we generate 48MB of data (
> not sure who can read through so much data and make sense of it , but it is
> beside the point).
>
>
>
> Adding to this problem, These csv logs are backed up every day ( as they
> reside inside the directory that belongs to the instance ).
>
>
>
>
>
> Is there any way by which we can write this CSVLOG outside the
> $HOME/data/log directory, so that it need not be part of the backups and is
> there a way to have a sliding window of say only the last 10000 entries in
> the log ( This sounds a bit risky because any information critical to the
> health of the instance may be lost ) .
>
>
>
> Is there any way by which we can tell pgaudit to write it’s information
> outside the Instance directory?
>
>
>
>
> log_destination = 'csvlog'
>
> logging_collector = on
>
>
>
> log_line_prefix = '%m [%p] %c %u(at)%d %r %a '
>
>
>
> log_statement = 'none'
>
>
>
> log_connections = on
>
> log_disconnections = on
>
> log_checkpoints = on
>
> log_lock_waits = on
>
> log_replication_commands = on
>
>
>
> log_error_verbosity = verbose
>
>
>
> log_min_duration_statement = 5000
>
>
>
> shared_preload_libraries = 'pgaudit'
>
>
>
> pgaudit.log = 'WRITE,DDL,ROLE,FUNCTION'
>
> pgaudit.log_relation = on
>
> pgaudit.log_parameter = on
>

Hi Subramanian, Ramachandran,

No, there is no pg_audit setting to redirect its output.

No, there is no mechanism in PG to rotate after X entries. There is Size,
and Time log_rotation_age, log_rotation_size

However, you can change the log directory with the parameter log_directory.
Make sure the login PostgreSQL is using (typically postgres) has read/write
permissions to the directory.

I would remove the pg_audit bits and just turn on full logging. Pg_audit
only changes the logging format a bit and bloats it up. It adds little to
nothing that is actually useful when auditing. It becomes a check-off box
for the auditor who knows about it but has never actually used or
reviews logs.

I think pg_audit is a useless plugin.

What we care about for auditing is who, when, and what, PostgreSQL logs
provide out of the box:

who = User id, Session Id

when = Timestamp

what = SQL they ran

The current log settings are not logging all the SELECTs with
log_min_duration_statement = 5000. A query has to execute for 5 seconds.
This does not prevent someone from harvesting/mining all the data from the
database going unnoticed.

I am not familiar with SIEM-SOC/NTT. I suspect they have rules for
monitoring data access and validating users are not accessing data they are
not supposed to access. The current settings do not meet that requirement.

I would do:

log_min_duration_statement = 0 (going to increase the log size even more)

Remove the pg_audit stuff unless the SIEM-SOC/NTT specifically has a SHALL
for it...

Links:

https://www.postgresql.org/docs/18/runtime-config-logging.html#GUC-LOG-ROTATION-AGE

https://www.postgresql.org/docs/18/runtime-config-logging.html#GUC-LOG-DIRECTORY
https://www.postgresql.org/docs/18/runtime-config-logging.html#GUC-LOG-LINE-PREFIX

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message KK 2026-09-01 15:25:42 Re: Disk layout for parallel instances
Previous Message Subramanian,Ramachandran 2026-09-01 09:26:24 Postgres pgaudit CSV-Logs can they be written outside the instance directory.