public inbox for [email protected]  
help / color / mirror / Atom feed
Re: question on audit columns
5+ messages / 5 participants
[nested] [flat]

* Re: question on audit columns
@ 2024-09-04 13:17 Khan Muhammad Usman <[email protected]>
  2024-09-04 14:36 ` Re: question on audit columns Adrian Klaver <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Khan Muhammad Usman @ 2024-09-04 13:17 UTC (permalink / raw)
  To: yudhi s <[email protected]>; +Cc: pgsql-general <[email protected]>

Yes this would be the better approach.

Sent from Outlook for Android<https://aka.ms/AAb9ysg;
________________________________
From: yudhi s <[email protected]>
Sent: Wednesday, September 4, 2024 6:10:04 PM
To: Muhammad Usman Khan <[email protected]>
Cc: pgsql-general <[email protected]>
Subject: Re: question on audit columns


On Wed, Sep 4, 2024 at 6:29 PM Muhammad Usman Khan <[email protected]<mailto:[email protected]>> wrote:
Hi,

In your scenario, triggers can add some overhead since they require extra processing after each update operation. Considering the size of your table and the high transaction volume, you need to observe that this might significantly affect performance.




On Wed, 4 Sept 2024 at 17:50, yudhi s <[email protected]<mailto:[email protected]>> wrote:
Hello,
In postgres database , we have all the tables with audit columns like created_by_user, created_timestamp,updated_by_user, updated_timestamp. So we have these fields that were supposed to be populated by the time at which the insert/update operation happened on the database but not at the application level. So we are planning to populate the created_by_user, created_timestamp columns by setting a default value of "current_timestamp" and "current_user" for the two columns,  but no such this is available to populate while we do the update of the row, so the only option seems to be through a trigger.

So wanted to check with the experts here  ,considering the table will be DML heavy table (300M+ transactions will be inserted daily), Is is okay to have the trigger for this table for populating all the audit columns or should we keep default for  created_by_user, created_timestamp and just trigger for the update related two audit column? Basically wanted to see, if the default value does the same thing as a trigger or it does something more optimally than trigger?

Regards
Yudhi

Thank you so much. So do you mean to say that , we should add default values for the create_timestamp and create_user_id as current_timestamp and current_user,  but for update_user_id and update_timestamp , we can ask the application to update the values manually , whenever they are executing the update statement on the rows?


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: question on audit columns
  2024-09-04 13:17 Re: question on audit columns Khan Muhammad Usman <[email protected]>
@ 2024-09-04 14:36 ` Adrian Klaver <[email protected]>
  2024-09-04 14:48   ` Re: question on audit columns Tim Clarke <[email protected]>
  2024-11-14 08:58   ` Re: question on audit columns Johannes Lochmann <[email protected]>
  0 siblings, 2 replies; 5+ messages in thread

From: Adrian Klaver @ 2024-09-04 14:36 UTC (permalink / raw)
  To: Khan Muhammad Usman <[email protected]>; yudhi s <[email protected]>; +Cc: pgsql-general <[email protected]>

On 9/4/24 06:17, Khan Muhammad Usman wrote:
> Yes this would be the better approach.

1) Except the overhead is now shifted to the application, which may or 
not be better. You are also moving the audit responsibility to the 
application and the application maintainers and making it application 
specific. If a new application/client starts hitting the database and it 
did not get the memo about the audit fields they won't be filled in.

2) I would recommend setting up a some realistic tests and see if the 
overhead of the update triggers would be a concern.



-- 
Adrian Klaver
[email protected]







^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: question on audit columns
  2024-09-04 13:17 Re: question on audit columns Khan Muhammad Usman <[email protected]>
  2024-09-04 14:36 ` Re: question on audit columns Adrian Klaver <[email protected]>
@ 2024-09-04 14:48   ` Tim Clarke <[email protected]>
  1 sibling, 0 replies; 5+ messages in thread

From: Tim Clarke @ 2024-09-04 14:48 UTC (permalink / raw)
  To: Adrian Klaver <[email protected]>; Khan Muhammad Usman <[email protected]>; yudhi s <[email protected]>; +Cc: pgsql-general <[email protected]>

>
> On 9/4/24 06:17, Khan Muhammad Usman wrote:
> > Yes this would be the better approach.
>
> 1) Except the overhead is now shifted to the application, which may or
> not be better. You are also moving the audit responsibility to the
> application and the application maintainers and making it application
> specific. If a new application/client starts hitting the database and it
> did not get the memo about the audit fields they won't be filled in.
>
> 2) I would recommend setting up a some realistic tests and see if the
> overhead of the update triggers would be a concern.
>
>
>
> --
> Adrian Klaver
> [email protected]

If it helps, we implemented a trigger based audit system 20 years ago. It both creates a separate inviolate audit table record and updates the record being changed with a timestamp and a userid of last change. We've not regretted it and moderate hardware deals well with the overhead (500+ table database, 80+ concurrent users, 18 million audit records a month).

--
Tim Clarke MSc, BSc (Hons), MBCS
IT Director
Direct: +44 (0)1376 504510 | Mobile: +44 (0)7887 563420
[https://i0.wp.com/www.manifest.co.uk/wp-content/uploads/2022/12/Minerva-Analytics-Logo-PORTRAIT.png]    [https://i0.wp.com/www.manifest.co.uk/wp-content/uploads/2022/12/esg_finalist.png]



Telephone: Witham: +44(0)1376 503500 | London: +44 (0)20 3009 0853 | Frankfurt: +49 (0)69 7191 6000 | Hong Kong: +852 5803 1687 | Toronto: +1 647 503 2848
Web: https://www.manifest.co.uk/

Watch our latest Minerva Briefings on BrightTALK<https://www.brighttalk.com/channel/18792/?utm_source=brighttalk-sharing&utm_medium=web&utm_c...;



Minerva Analytics Ltd - A Solactive Company
9 Freebournes Court | Newland Street | Witham | Essex | CM8 2BL | United Kingdom

________________________________

Copyright: This e-mail may contain confidential or legally privileged information. If you are not the named addressee you must not use or disclose such information, instead please report it to [email protected]<mailto:[email protected]>
Legal: Minerva Analytics is the trading name of: Minerva Analytics Ltd: Registered in England Number 11260966 & The Manifest Voting Agency Ltd: Registered in England Number 2920820 Registered Office at above address. Please Click Here https://www.manifest.co.uk/legal/ for further information.






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: question on audit columns
  2024-09-04 13:17 Re: question on audit columns Khan Muhammad Usman <[email protected]>
  2024-09-04 14:36 ` Re: question on audit columns Adrian Klaver <[email protected]>
@ 2024-11-14 08:58   ` Johannes Lochmann <[email protected]>
  2024-11-14 16:32     ` Re: question on audit columns Greg Sabino Mullane <[email protected]>
  1 sibling, 1 reply; 5+ messages in thread

From: Johannes Lochmann @ 2024-11-14 08:58 UTC (permalink / raw)
  To: [email protected]

... and (3) the values are not updated on manual actions without 
triggers - which might or might not be desirable depending on the intention.

Best,

Johannes

On 9/4/2024 16:36, Adrian Klaver wrote:
> On 9/4/24 06:17, Khan Muhammad Usman wrote:
>> Yes this would be the better approach.
>
> 1) Except the overhead is now shifted to the application, which may or 
> not be better. You are also moving the audit responsibility to the 
> application and the application maintainers and making it application 
> specific. If a new application/client starts hitting the database and 
> it did not get the memo about the audit fields they won't be filled in.
>
> 2) I would recommend setting up a some realistic tests and see if the 
> overhead of the update triggers would be a concern.
>
>
>






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: question on audit columns
  2024-09-04 13:17 Re: question on audit columns Khan Muhammad Usman <[email protected]>
  2024-09-04 14:36 ` Re: question on audit columns Adrian Klaver <[email protected]>
  2024-11-14 08:58   ` Re: question on audit columns Johannes Lochmann <[email protected]>
@ 2024-11-14 16:32     ` Greg Sabino Mullane <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Greg Sabino Mullane @ 2024-11-14 16:32 UTC (permalink / raw)
  To: yudhi s <[email protected]>; +Cc: [email protected]

As far as the application being able to change those fields itself, you can
prevent that via column permissions, by leaving out the four audit columns
and doing something like:

GRANT INSERT (email, widget_count), UPDATE (email, widget_count) ON TABLE
foobar TO PUBLIC;

That way, inserts are guaranteed to use the default values of
current_timestamp() and current_user. And a BEFORE UPDATE trigger ensures
it changes the other two fields via the trigger function only.

Cheers,
Greg

P.S. Also check out https://www.pgaudit.org/ (PGAudit) as an alternative
approach, which puts the information into your Postgres logs, rather than
in the tables themselves.


^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2024-11-14 16:32 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-09-04 13:17 Re: question on audit columns Khan Muhammad Usman <[email protected]>
2024-09-04 14:36 ` Adrian Klaver <[email protected]>
2024-09-04 14:48   ` Tim Clarke <[email protected]>
2024-11-14 08:58   ` Johannes Lochmann <[email protected]>
2024-11-14 16:32     ` Greg Sabino Mullane <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox