pgMemento icon indicating copy to clipboard operation
pgMemento copied to clipboard

Feature request: start auditing on some columns of table

Open stephane-klein opened this issue 5 years ago • 4 comments

Hi,

this is a feature request: I would like to start auditing for some columns of table.

For instance:

SELECT pgmemento.create_table_audit(
  tablename := 'contacts,
  schemaname := 'public',
  audit_id_column_name := 'audit_trail_id',
  log_old_data := TRUE,
  log_new_data := TRUE,
  log_state := TRUE,
  include_columns := ['firstname', 'lastname']
);

or

SELECT pgmemento.create_table_audit(
  tablename := 'contacts,
  schemaname := 'public',
  audit_id_column_name := 'audit_trail_id',
  log_old_data := TRUE,
  log_new_data := TRUE,
  log_state := TRUE,
  exclude_columns := ['foobar']
);

Best regards, Stéphane

stephane-klein avatar Mar 10 '21 14:03 stephane-klein

Thank your for creating this issue! I was looking for a feature just like this one.

Our use-case is this : Some fields update very frequently while others not so often. Allowing us to audit a single column of a table would avoid us lots of noise, power and space waste.

Best, Michael

MichaelTSS avatar Mar 10 '21 14:03 MichaelTSS

Let me think about it. I think, I would still log everything in the audit_column_log but maybe have an extra column there show if the column is logged or not. This would have an effect on the log trigger function requiring an extra treatment after (or before?) to_jsonb(OLD) / to_jsonb(NEW). Hopefully not too much overhead. Implementation could take up more time so I can't tell how fast it will be there...

FxKu avatar Mar 21 '21 17:03 FxKu

HI @FxKu, by any chance excluding of columns from a table is that feature available now?

GLakshmiSravanthi avatar Jun 23 '23 10:06 GLakshmiSravanthi

hi @stephane-klein, can I know how did solve this problem with current features? I know this is an old issue but we had a requirement with this feature it would be great if you provide a few inputs regarding this issue.

GLakshmiSravanthi avatar Jul 03 '23 06:07 GLakshmiSravanthi