Recording how a table is used

From: Daniel Gordon <dragongordon(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Recording how a table is used
Date: 2009-06-30 06:47:42
Message-ID: 11c0133d0906292347q4c65cfe2m7b658232d0b13a9f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I'm trying to record the results of a select statement into a separate
table. I need the information selected, the column it was stored in, the
table it was stored in, and the query that selected it. Everything I've
read so far says that triggers can't trigger from select statements, and
they don't have a variable that stores the query it triggered from. I would
be happy with partial solutions since my other option is a complicated perl
script that has to parse the query statement to figure out where it is
looking for the information

Also, my next step is to do the same for as many types of statements as
possible, so if anyone knows how to retrieve the insert, update, or delete
statement sent to the database from inside the trigger, that would be useful
as well.

Here is the table I'm trying to fill, in case it is useful

create table sql_query_data_log (
id serial,
create_ time timestamp DEFAULT now(),
query varchar,
table text,
column text,
data varchar
);

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mario Splivalo 2009-06-30 06:51:26 Re: date_trunc should be called date_round?
Previous Message Craig Ringer 2009-06-30 01:29:02 Re: uniqueness constraint with NULLs