Re: Is PgAudit extension database specific?

From: Pierre Forstmann <pierre(dot)forstmann(at)gmail(dot)com>
To: Dharin Shah <dharinshah95(at)gmail(dot)com>, zaidagilist <zaidagilist(at)gmail(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Siraj G <tosiraj(dot)g(at)gmail(dot)com>, Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: Is PgAudit extension database specific?
Date: 2026-01-15 15:10:47
Message-ID: 69e04307-809c-418b-9f86-903df8d8f317@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

if parameter log_line_prefix uses %d parameter then you get database
name in log;

2026-01-15 16:09:05.784 CET [47861] db1 LOG:  AUDIT:
SESSION,1,1,READ,SELECT,,,select * from t1,<not logged>
2026-01-15 16:09:11.502 CET [47864] db2 LOG:  AUDIT:
SESSION,1,1,READ,SELECT,,,select * from t2,<not logged>

Le 15/01/2026 à 16:02, Pierre Forstmann a écrit :
>
> I have just tested pgaudit 18 with PostgreSQL 18.1.
>
> I have only installed pgaudit in postgres database and I have created
> 2 other databases db1 and db2.
>
> If I run:
>
> postgres(at)alma ~]$ psql db1
> psql (18.1)
> Type "help" for help.
>
> db1=# \dx
>                           List of installed extensions
>   Name   | Version | Default version |   Schema   |  Description
> ---------+---------+-----------------+------------+------------------------------
>  plpgsql | 1.0     | 1.0             | pg_catalog | PL/pgSQL
> procedural language
> (1 row)
>
> db1=# select * from t1;
>  x
> ---
> (0 rows)
>
> db1=#
> \q
> [postgres(at)alma ~]$ psql db2
> psql (18.1)
> Type "help" for help.
>
> db2=# \dx
>                           List of installed extensions
>   Name   | Version | Default version |   Schema   |  Description
> ---------+---------+-----------------+------------+------------------------------
>  plpgsql | 1.0     | 1.0             | pg_catalog | PL/pgSQL
> procedural language
> (1 row)
>
> db2=# select * from t2;
>  x
> ---
> (0 rows)
>
> db2=#
> \q
> [postgres(at)alma ~]$
>
>
> I get in PG log:
>
>
> 2026-01-15 15:58:23.044 CET [47325] LOG:  AUDIT:
> SESSION,1,1,READ,SELECT,,,"SELECT e.extname AS ""Name"", e.extversion
> AS ""Version"", ae.default_version AS ""Default version"",n.nspname AS
> ""Schema"", d.description AS ""Description""
>     FROM pg_catalog.pg_extension e LEFT JOIN pg_catalog.pg_namespace n
> ON n.oid = e.extnamespace LEFT JOIN pg_catalog.pg_description d ON
> d.objoid = e.oid AND d.classoid =
> 'pg_catalog.pg_extension'::pg_catalog.regclass LEFT JOIN
> pg_catalog.pg_available_extensions() ae(name, default_version,
> comment) ON ae.name = e.extname
>     ORDER BY 1",<not logged>
> 2026-01-15 15:58:29.192 CET [47325] LOG:  AUDIT:
> SESSION,2,1,READ,SELECT,,,select * from t1,<not logged>
> 2026-01-15 15:58:39.620 CET [47332] LOG:  AUDIT:
> SESSION,1,1,READ,SELECT,,,"SELECT e.extname AS ""Name"", e.extversion
> AS ""Version"", ae.default_version AS ""Default version"",n.nspname AS
> ""Schema"", d.description AS ""Description""
>     FROM pg_catalog.pg_extension e LEFT JOIN pg_catalog.pg_namespace n
> ON n.oid = e.extnamespace LEFT JOIN pg_catalog.pg_description d ON
> d.objoid = e.oid AND d.classoid =
> 'pg_catalog.pg_extension'::pg_catalog.regclass LEFT JOIN
> pg_catalog.pg_available_extensions() ae(name, default_version,
> comment) ON ae.name = e.extname
>     ORDER BY 1",<not logged>
> 2026-01-15 15:58:42.416 CET [47332] LOG:  AUDIT:
> SESSION,2,1,READ,SELECT,,,select * from t2,<not logged>
>
>
> We can conclude that  installing pgaudit extension works for all
> databases.
>
> It seems also that pgaudit does not log database name (I have not
> anything pgaudit documentation about database name).
>
>
>
> Le 06/01/2026 à 18:55, Dharin Shah a écrit :
>> Hello,
>>
>> This is standard for all pg extensions as mentioned above.
>>
>> Just adding a minor doc patch to add clarification in the doc.
>>
>> Thanks,
>> Dharin
>>
>> On Tue, Jan 6, 2026 at 6:30 PM zaidagilist <zaidagilist(at)gmail(dot)com> wrote:
>>
>> Hello Siraj,
>>
>> pgAudit is a coupled component build for a specific PG version,
>> for each PG version you are required to install separately. Same
>> behavior as other PG based extensions.
>>
>> Regards,
>> Zaid
>>
>> On Tue, Jan 6, 2026 at 10:19 PM Siraj G <tosiraj(dot)g(at)gmail(dot)com> wrote:
>>
>> Hello Experts!
>>
>> Here is my observation:
>>
>> Connected to postgres DB and ran:
>> CREATE EXTENSION pgaudit;
>>
>> Within postgres DB, I ran this:
>> SELECT*FROMpg_catalog.pg_extension WHEREextname ='pgaudit';
>>
>> It does return a row.
>>
>> I changed the DB and ran the same SQL, but it does not return
>> any thing.
>>
>> The PostgreSQL instance is a GCP cloud SQL running with
>> postgres V14.19.
>>
>> Would you help me understand this, please.
>>
>> Regards
>> Siraj
>>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Erik Wienhold 2026-01-18 16:29:00 Re: Unable to compile postgresql-18.1
Previous Message Pierre Forstmann 2026-01-15 15:02:34 Re: Is PgAudit extension database specific?