Re: Is PgAudit extension database specific? - Mailing list pgsql-admin

From Pierre Forstmann
Subject Re: Is PgAudit extension database specific?
Date
Msg-id 2c004899-b0c2-41fd-8d58-2c9f4e7a4a32@gmail.com
Whole thread Raw
In response to Re: Is PgAudit extension database specific?  (Dharin Shah <dharinshah95@gmail.com>)
Responses Re: Is PgAudit extension database specific?
List pgsql-admin

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@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@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@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@gmail.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.g@gmail.com> wrote:
Hello Experts!

Here is my observation:

Connected to postgres DB and ran:
CREATE EXTENSION pgaudit;

Within postgres DB, I ran this:
SELECT * FROM pg_catalog.pg_extension WHERE extname = '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

pgsql-admin by date:

Previous
From: Gabriel Guillem Barceló Soteras
Date:
Subject: Re: VACUUM/ANALYZE Strategy for Low-Activity PostgreSQL 15 Instance
Next
From: Pierre Forstmann
Date:
Subject: Re: Is PgAudit extension database specific?