Logging statements and parameter values

From: Ted Powell <ted(at)theplace(dot)enposte(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Logging statements and parameter values
Date: 2006-01-27 06:01:47
Message-ID: 20060127060147.GA4795@theplace.enposte.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Our development group needs to have the option of logging all SQL
statements including substituted parameter values. Getting output in the
form:
... WHERE contact.login_con = $1 AND company.login_co = $2

was no problem, but nothing that I tried turning on in the config file
yielded values for $1 and $2.

Digging into the source for 8.1.1 brought me to this code in
.../backend/tcop/postgres.c (lines 1449+)

/* We need to output the parameter values someday */
if (log_statement == LOGSTMT_ALL)
ereport(LOG,
(errmsg("statement: <BIND> %s", portal_name)));

/*
* Fetch parameters, if any, and store in the portal's memory context.
*/
if (numParams > 0)

It seems to me that a point near the bottom of the loop over parameters
(1564+)
params[i].kind = PARAM_NUM;
params[i].id = i + 1;
params[i].ptype = ptype;
params[i].isnull = isNull;

i++;
}

(params[i].value is set in a couple of places higher up in the loop)
would be a good place to log each parameter, but...

Has this not been done simply because nobody has gotten around to it, or
are there pitfalls? Although I've been using PostgreSQL for several years,
this is my first venture into its source code beyond watching it build.

Also, the Datum params[i].value, does it necessarily hold displayable
text, even when its content is the output of a binary input converter?
Is there a utility log routine somewhere that I can simply feed a
Datum to?

--
Ted Powell <ted(at)psg(dot)com> http://psg.com/~ted/
GPL code ... It's the difference between
owning your own home and just renting. --PJ

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2006-01-27 06:01:48 Re: Hey!!!
Previous Message Matthew T. O'Connor 2006-01-27 03:48:11 Re: VACUUM Question

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Hallgren 2006-01-27 09:56:25 Re: Adding a --quiet option to initdb
Previous Message Matthew T. O'Connor 2006-01-27 03:48:11 Re: VACUUM Question