Thread: log database changes - a design problem?

log database changes - a design problem?

From
Luca Ferrari
Date:
Hi all,
I've got my database on which I'm building a Java application. Since I'd like
to store information about who inserted and updated a specified record, I
placed in my main tables a few additional fields to store such information:
CREATE TABLE myTable(
....
    insertUser varchar(30),
    insertDate date,
    updateUser varchar(30),
    updateDate date,
    FOREIGN KEY insertUser REFERENCES users(username),
    FOREIGN KEY updateUser REFERENCES users(username)
);

where 'users' is a table that stores the usernames allowed to connect thru my
application. This solution works, of course, but as you can imagine is quite
boring to insert into each sql statement values for this additional fields,
and even if I can set-up default values, this can be error prone.
After a while, in order to get a little debug level on my application, I
started logging into a table the sql query that each user/client has
executed. This to understand why and which query can be wrong, which client
version has issued it, from which, etc. So I've got a kind of backtrace of
changes in the database disregarding the above additional fields. Even if
this log is more difficult to consult than the above additional fields (I
need to search within the sql statement string), I was wondering to remove
such additional fields.
Here comes my question: how can I catch user changes to each record in the
database without be bored with user/date details? Anyone can suggest me  a
smart solution and/or database design? Anyone has already found such kind of
problem?

Thanks,
Luca

Re: log database changes - a design problem?

From
Martijn van Oosterhout
Date:
On Thu, Nov 23, 2006 at 08:53:28AM +0100, Luca Ferrari wrote:
> Hi all,
> I've got my database on which I'm building a Java application. Since I'd like
> to store information about who inserted and updated a specified record, I
> placed in my main tables a few additional fields to store such information:

<snip>

> Here comes my question: how can I catch user changes to each record in the
> database without be bored with user/date details? Anyone can suggest me  a
> smart solution and/or database design? Anyone has already found such kind of
> problem?

Sounds like something a trigger would be good for.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

Re: log database changes - a design problem?

From
Andreas Kretschmer
Date:
Luca Ferrari <fluca1978@infinito.it> schrieb:

> Here comes my question: how can I catch user changes to each record in the
> database without be bored with user/date details? Anyone can suggest me  a
> smart solution and/or database design? Anyone has already found such kind of
> problem?

Perhaps is this a solution for you:
http://pgfoundry.org/projects/tablelog/


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°