From: Jesus Sandoval <meli@mzt.megared.net.mx>
To: pgsql-admin@postgresql.org
Subject: Applictaion data Logging
Date: Tue, 10 Dec 2002 01:53:50 +0000
Message-ID: <3DF5492E.68E749AB@mzt.megared.net.mx> (raw)
References: <E26F84170D88D411B4AA002035AE9F0D03C0A174@lclntmx4.ngco.com>
<005501c2917f$61ca09a0$7c01050a@marcmdelltop>
<13938.1037907911@sss.pgh.pa.us>
<00c101c291a1$9b99b820$7c01050a@marcmdelltop>
<18616.1037923014@sss.pgh.pa.us>
Hi, I will do this programatically but I wished to post this question just to
know if somebody have any suggestion, because I am new to server side functions
or rules or trigger programming.
I want to log any data change in one application, for audit reasons, I created a
table for that purpose the table has the next fields:
id SERIAL -- Primary key
tablename VARCHAR(40) -- Table name that changed
fieldname VARCHAR(40) -- fieldname that changed in the table
user VARCHAR(16) -- User that made the change
timedate TIMESTAMP WITHOUT TIME ZONE -- Timestamp of change
keyvalue TEXT -- The key value of the record that changed
oldcontent TEXT -- the field's content before the change
newcontent TEXT -- the field's new content
I'm programming in Java and using JDBC.
Notes:
1) The program knows the user id that made the change (postgres is not aware of
this user id, because there is one user that connect from the application, after
the connection to postgresql, the applications validate the user id from a
postgresql table, if it is ok, the program continues).
2) In order to know wich record is updated (or inserted or deleted) the keyvalue
is saved in the log record.
3) Maybe newcontent is redundant, because I can check that value in the actual
table, so maybe it can be dropped from this table.
As I said, I plan to do this log from the program, but I think it can be done
with Triggers or rules, but I don't know if it is possibly or how to do the
following.
1) How to pass the user id from the application to postgres.
2) How to save the tablename of the table that is modifying in the logtable, the
same for the fieldname.
3) On one update there may be 2 or more fields (columns) changing, so I need to
store 2 or more records to the logtable, How can I do that.
4) to get the key value of the changed record. One query can change many records
and many changes.
5) Which is best option: Triggers, Rules or application logic???? (none of
them????)
Thanks
Jesus Sandoval
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: meli@mzt.megared.net.mx
Subject: Re: Applictaion data Logging
In-Reply-To: <3DF5492E.68E749AB@mzt.megared.net.mx>
References: <E26F84170D88D411B4AA002035AE9F0D03C0A174@lclntmx4.ngco.com> <005501c2917f$61ca09a0$7c01050a@marcmdelltop> <13938.1037907911@sss.pgh.pa.us> <00c101c291a1$9b99b820$7c01050a@marcmdelltop> <18616.1037923014@sss.pgh.pa.us> <3DF5492E.68E749AB@mzt.megared.net.mx>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox