SQL state in log_line_prefix

Started by Guillaume Smetalmost 17 years ago9 messageshackers
Jump to latest
#1Guillaume Smet
guillaume.smet@gmail.com

Hi -hackers,

A customer of us recently wanted to separate user errors from system
errors as different teams are working on these 2 types of errors and
while they might want to ignore user errors (bad-written SQL queries
and so on), they want to be sure system errors are analyzed carefully.

A good way to differentiate the 2 types of errors is to use the SQL state.

Currently, the only way to have the SQL state in the standard log file
is to do verbose logging which is, well..., verbose.

I attached a patch which allows to add the SQL state code into the
log_line_prefix. I used %e (as in error) as %s is already used.

Any comment?

--
Guillaume

Attachments:

postgresql-log_line_prefix-sql_state.difftext/x-patch; charset=US-ASCII; name=postgresql-log_line_prefix-sql_state.diffDownload+31-22
#2Guillaume Smet
guillaume.smet@gmail.com
In reply to: Guillaume Smet (#1)
Re: SQL state in log_line_prefix

On Sun, May 10, 2009 at 2:32 PM, Guillaume Smet
<guillaume.smet@gmail.com> wrote:

I attached a patch which allows to add the SQL state code into the
log_line_prefix. I used %e (as in error) as %s is already used.

Patch added to the next commit fest page.

--
Guillaume

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Guillaume Smet (#1)
Re: SQL state in log_line_prefix

Guillaume Smet wrote:

Hi -hackers,

A customer of us recently wanted to separate user errors from system
errors as different teams are working on these 2 types of errors and
while they might want to ignore user errors (bad-written SQL queries
and so on), they want to be sure system errors are analyzed carefully.

A good way to differentiate the 2 types of errors is to use the SQL state.

Currently, the only way to have the SQL state in the standard log file
is to do verbose logging which is, well..., verbose.

I attached a patch which allows to add the SQL state code into the
log_line_prefix. I used %e (as in error) as %s is already used.

Any comment?

If we're going to do this I think it needs to be added to CSV log output
too.

cheers

andrew

#4Guillaume Smet
guillaume.smet@gmail.com
In reply to: Andrew Dunstan (#3)
Re: SQL state in log_line_prefix

On Sun, May 10, 2009 at 3:29 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

If we're going to do this I think it needs to be added to CSV log output
too.

AFAICS, it's already done for the CSV output hence my "the only way to
have the SQL state in the *standard* log file".

Did I miss something?

Thanks for your feedback.

--
Guillaume

#5Andrew Dunstan
andrew@dunslane.net
In reply to: Guillaume Smet (#4)
Re: SQL state in log_line_prefix

Guillaume Smet wrote:

On Sun, May 10, 2009 at 3:29 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

If we're going to do this I think it needs to be added to CSV log output
too.

AFAICS, it's already done for the CSV output hence my "the only way to
have the SQL state in the *standard* log file".

Did I miss something?

Oh, you're right. Sorry for the noise.

cheers

andrew

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Guillaume Smet (#1)
Re: SQL state in log_line_prefix

Guillaume Smet <guillaume.smet@gmail.com> writes:

A customer of us recently wanted to separate user errors from system
errors as different teams are working on these 2 types of errors and
while they might want to ignore user errors (bad-written SQL queries
and so on), they want to be sure system errors are analyzed carefully.

A good way to differentiate the 2 types of errors is to use the SQL state.

This might or might not be worth doing, but it seems pretty nearly
entirely useless for the claimed purpose. What is your division between
"user errors" and "system errors", and how will the SQLSTATE help you
make that?

regards, tom lane

#7Guillaume Smet
guillaume.smet@gmail.com
In reply to: Tom Lane (#6)
Re: SQL state in log_line_prefix

On Sun, May 10, 2009 at 4:07 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

This might or might not be worth doing, but it seems pretty nearly
entirely useless for the claimed purpose. What is your division between
"user errors" and "system errors", and how will the SQLSTATE help you
make that?

We use http://www.postgresql.org/docs/8.3/interactive/errcodes-appendix.html
to sort the errors.

For example:
Class 22 — Data Exception -> user
Class 53 — Insufficient Resources -> system
Class XX — Internal Error -> system

It's not perfect but it's the best way we found to classify them at the moment.

--
Guillaume

#8Peter Eisentraut
peter_e@gmx.net
In reply to: Guillaume Smet (#1)
Re: SQL state in log_line_prefix

On Sunday 10 May 2009 15:32:26 Guillaume Smet wrote:

I attached a patch which allows to add the SQL state code into the
log_line_prefix. I used %e (as in error) as %s is already used.

Committed.

#9Guillaume Smet
guillaume.smet@gmail.com
In reply to: Peter Eisentraut (#8)
Re: SQL state in log_line_prefix

On Fri, Jul 3, 2009 at 9:14 PM, Peter Eisentraut<peter_e@gmx.net> wrote:

On Sunday 10 May 2009 15:32:26 Guillaume Smet wrote:

I attached a patch which allows to add the SQL state code into the
log_line_prefix. I used %e (as in error) as %s is already used.

Committed.

Thanks Peter.

--
Guillaume