4

I am about to implement an audit system in my database and am looking for the most effective way to do this.

I've read the wiki and did my research.

There is this example: https://wiki.postgresql.org/wiki/Audit_trigger And also this: https://wiki.postgresql.org/wiki/Audit_trigger_91plus

In the listed examples you have to create a trigger for each table (kinda redudant).

However with Postgres 9.3+ we have the ability of event triggers where we can react on special events like create, alter or drop table.

An optimal solution would be:

create event trigger UpdateTables
   on ddl_command_end
   when tag in ( 'insert ', 'update ')
   execute procedure DoAudit();

However that returns:

ERROR: filter value "insert " not recognized for filter variable "tag" SQL Status:42601

I am wondering if we also can react on insert, update events with event triggers and use this single trigger for all auditing?

1
  • 1
    You indeed need to create a trigger for each table, but all triggers can (re)use the same trigger function. Commented Aug 26, 2016 at 12:05

2 Answers 2

1

This won't work.

The "on ddl_command_end" means the event is intended to be invoked on structural changes in the database. The complete reference to events is here: https://www.postgresql.org/docs/current/static/event-trigger-matrix.html

Sign up to request clarification or add additional context in comments.

1 Comment

This list is helpful indeed. Hopefully in the future there will be additional functionality be added to event triggers so we can have a nice audit system.
-1

Have a look at this:

https://eager.io/blog/audit-postgres/

This is a quite simple, yet effective way to implement an auditing system, making use of the hstore data type. I recently tried it and it worked flawlessly "out of the box".

2 Comments

Thanks, i'll have a look at it.
link is not available anymore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.