better logging on the backend (was: Re: When running with autocommit false only the first BEGIN)

From: Vadim Nasardinov <vadimn(at)redhat(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: better logging on the backend (was: Re: When running with autocommit false only the first BEGIN)
Date: 2004-11-23 14:25:30
Message-ID: 200411230925.30941@vadim.nasardinov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Tuesday 23 November 2004 07:18, Oliver Jowett wrote:
> Dave Cramer wrote:
> > That certainly doesn't seem acceptable. As Barry points out people
> > will really be in the dark when their code doesn't work.
>
> There's nothing much the driver can do about it other than not using
> the new features of V3. This needs a server-side fix.

Can some kind of statement logging be implemented on the client side?

Or do you think there isn't much to be gained by this beyond whatever
functionality is already provided by proxying JDBC drivers like P6Spy
(http://p6spy.sf.net)?

> We could make BEGIN/COMMIT/ROLLBACK more visible at the (small) cost
> of an extra Parse on each execution.

I'm not sure if you need an extra parse. I'd be happy to have the
backend log a (semi-) unique statement ID for each statement it
executes. If a statement is reused, its unique ID allows me to find
its prior occurrences in the log. It then becomes a matter of having
an intelligent log viewer or post-processor, one that shouldn't be too
hard to write.

Additionally, another thing that could be _really_ useful is the
ability to send an arbitrary message to be logged on the backend side
along with each statement. For instance, you can log the Java thread
name, so you can map statements to threads later on. Another example
would be mapping each statement from the back end log to the
corresponding Java stack trace on the client side. This could be done
by

(a) capturing the current stack trace on the client side via
org.postgresql.Driver.debug(uniqueID + ": " + p_sql,
new Exception());

or some such.

(b) sending uniqueID to the backend along with the statement.

Thoughts?

Vadim

------------------------------------------------------------------------------

P.S. BTW, Driver#log(String,Exception) currently drops the stack
trace on the floor. All it does is

public static void debug(String msg, Exception ex)
{
if (logDebug)
{
DriverManager.println(msg);
if (ex != null)
{
DriverManager.println(ex.toString());
}
}
}

Would it make more sense to do something like this:

public static void debug(String msg, Exception ex)
{
if (logDebug)
{
DriverManager.println(msg);
if (ex != null)
{
ex.printStackTrace(DriverManager.getLogWriter());
}
}
}

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2004-11-23 15:09:51 Re: [JDBC] Strange server error with current 8.0beta driver
Previous Message Oliver Jowett 2004-11-23 12:18:05 Re: When running with autocommit false only the first BEGIN