Обсуждение: Is PgAudit extension database specific?

Поиск
Список
Период
Сортировка

Is PgAudit extension database specific?

От
Siraj G
Дата:
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

Re: Is PgAudit extension database specific?

От
"David G. Johnston"
Дата:
On Tue, Jan 6, 2026 at 10:19 AM Siraj G <tosiraj.g@gmail.com> wrote:
Connected to postgres DB and ran:
CREATE EXTENSION pgaudit;


"create extension" always executes strictly within the database you are connected to.  It may have effects that go beyond that database, depending on what the extension does, but absent documentation to the contrary assume that an extension only operates within the database it was installed into.

David J.

Re: Is PgAudit extension database specific?

От
zaidagilist
Дата:
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

Re: Is PgAudit extension database specific?

От
Dharin Shah
Дата:
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

Вложения

Re: Is PgAudit extension database specific?

От
Pierre Forstmann
Дата:

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

Re: Is PgAudit extension database specific?

От
Pierre Forstmann
Дата:

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@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