Re: [HACKERS] Deadlock with pg_dump?

Lists: pgsql-hackerspgsql-patches
From: Chris Campbell <chris(at)bignerdranch(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Deadlock with pg_dump?
Date: 2006-10-26 20:45:02
Message-ID: 800AD8C1-A5B8-4735-806D-F253FAC3E8C4@bignerdranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

We're getting deadlock error messages in the production database logs
during times of inactivity, where the only other thing using the
database (we think) is the every-15-minutes pg_dump process. There
are still database connections up-and-running from unused Hibernate
Java processes, but they Shouldn't Be doing anything (and shouldn't
be holding locks, etc).

The deadlock error message looks like this:

ERROR: deadlock detected
DETAIL: Process 1120 waits for ShareLock on transaction 5847116;
blocked by process 1171.
Process 1171 waits for ExclusiveLock on tuple (6549,28) of relation
37637 of database 37574; blocked by process 1120.

Relation 37636 is the users table (schema attached).

Process 1120 was running an UPDATE query and changing a single row in
the users table. The users table does have foreign keys to 4 other
tables. Is it possible that those foreign key constraints acquire
locks in a different order than pg_dump (as it's SELECTing from the
tables), and it's hitting at *just* the right time to cause a deadlock?

I've tried to reproduce it on a test machine by running pgbench
(after adding foreign keys to the pgbench tables) and pg_dump in
tight loops in two concurrent shell scripts, but no deadlock.

Any ideas on how to track this down?

Under what conditions does a process acquire a ShareLock on another
transaction?

Thanks!

- Chris

Attachment Content-Type Size
schema.txt text/plain 1.3 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chris Campbell <chris(at)bignerdranch(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2006-10-26 21:21:26
Message-ID: 25632.1161897686@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> ERROR: deadlock detected
> DETAIL: Process 1120 waits for ShareLock on transaction 5847116;
> blocked by process 1171.
> Process 1171 waits for ExclusiveLock on tuple (6549,28) of relation
> 37637 of database 37574; blocked by process 1120.

> Relation 37636 is the users table (schema attached).

> Process 1120 was running an UPDATE query and changing a single row in
> the users table.

And what was 1171 doing? I really doubt that either of these could have
been pg_dump.

Given that you appear to be running 8.1 (tut-tut for not saying), it
really shouldn't be a foreign key problem either. I'm betting these
are just flat out conflicting updates of the same row(s).

regards, tom lane


From: Chris Campbell <chris(at)bignerdranch(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2006-10-26 22:11:59
Message-ID: B02948E2-6FC5-485F-B9F6-51F35246EEA5@bignerdranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Oct 26, 2006, at 17:21, Tom Lane wrote:

> And what was 1171 doing? I really doubt that either of these could
> have
> been pg_dump.

I know that process 1120 is a Java client (Hibernate) running an
UPDATE query, but I have no idea what 1171 is. I doubt that 1171 was
pg_dump, but when we turn off the pg_dump cron jobs (for 12-ish
hours), the deadlocks go away. We usually see 5 or 6 deadlocks spread
throughout the day. That's not definitive evidence, of course, but
it's certainly curious.

> Given that you appear to be running 8.1 (tut-tut for not saying), it
> really shouldn't be a foreign key problem either. I'm betting these
> are just flat out conflicting updates of the same row(s).

Yeah, 8.1.3. Sorry about the omission.

Is there additional logging information I can turn on to get more
details? I guess I need to see exactly what locks both processes
hold, and what queries they were running when the deadlock occurred?
Is that easily done, without turning on logging for *all* statements?

Thanks!

- Chris


From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: Chris Campbell <chris(at)bignerdranch(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2006-10-26 22:29:11
Message-ID: 20061026222911.GR26892@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, Oct 26, 2006 at 06:11:59PM -0400, Chris Campbell wrote:
> On Oct 26, 2006, at 17:21, Tom Lane wrote:
>
> >And what was 1171 doing? I really doubt that either of these could
> >have
> >been pg_dump.
>
> I know that process 1120 is a Java client (Hibernate) running an
> UPDATE query, but I have no idea what 1171 is. I doubt that 1171 was
> pg_dump, but when we turn off the pg_dump cron jobs (for 12-ish
> hours), the deadlocks go away. We usually see 5 or 6 deadlocks spread
> throughout the day. That's not definitive evidence, of course, but
> it's certainly curious.

I seem to remember something funny about hibernate and locking, though I
can't recall any details right now... but searching the archives might
provide insight.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chris Campbell <chris(at)bignerdranch(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2006-10-26 22:45:08
Message-ID: 26690.1161902708@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> Is there additional logging information I can turn on to get more
> details? I guess I need to see exactly what locks both processes
> hold, and what queries they were running when the deadlock occurred?
> Is that easily done, without turning on logging for *all* statements?

log_min_error_statement = error would at least get you the statements
reporting the deadlocks, though not what they're conflicting against.
Still, if you're seeing multiple occurrences per day, that would
probably let you build up a good picture of all the involved operations
over a couple of days.

[ Memo to hackers: why is it that log_min_error_statement = error
isn't the default? ]

Unless your applications are issuing actual LOCK TABLE commands, it's
really hard to see how pg_dump could be involved. It doesn't take
anything stronger than AccessShareLock, and shouldn't be holding any
tuple-level locks at all.

regards, tom lane


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2006-10-26 23:23:12
Message-ID: 20061026232312.GH31183@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:

> [ Memo to hackers: why is it that log_min_error_statement = error
> isn't the default? ]

I think it default to panic because it's the way to disable the feature,
which was the easiest sell when the feature was introduced. I'm all for
lowering it to error.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: Chris Campbell <chris(at)bignerdranch(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2006-10-27 00:27:31
Message-ID: 7B2C5768-D380-4EFC-98D9-D8B53B6CB1D0@bignerdranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Oct 26, 2006, at 18:45, Tom Lane wrote:

> log_min_error_statement = error would at least get you the statements
> reporting the deadlocks, though not what they're conflicting against.

Would it be possible (in 8.3, say) to log the conflicting backend's
current statement (from pg_stat_activity, perhaps)? I guess the
conflicting backend would currently be waiting for a lock, so its
current query (before releasing the lock) is the one we want.

Thanks!

- Chris


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Chris Campbell" <chris(at)bignerdranch(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Deadlock with pg_dump?
Date: 2006-10-30 20:49:57
Message-ID: 1162241397.11568.335.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, 2006-10-26 at 18:45 -0400, Tom Lane wrote:
> Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> > Is there additional logging information I can turn on to get more
> > details? I guess I need to see exactly what locks both processes
> > hold, and what queries they were running when the deadlock occurred?
> > Is that easily done, without turning on logging for *all* statements?
>
> log_min_error_statement = error would at least get you the statements
> reporting the deadlocks, though not what they're conflicting against.

Yeh, we need a much better locking logger for performance analysis.

We really need to dump the whole wait-for graph for deadlocks, since
this might be more complex than just two statements involved. Deadlocks
ought to be so infrequent that we can afford the log space to do this -
plus if we did this it would likely lead to fewer deadlocks.

For 8.3 I'd like to have a log_min_duration_lockwait (secs) parameter
that would allow you to dump the wait-for graph for any data-level locks
that wait too long, rather than just those that deadlock. Many
applications experience heavy locking because of lack of holistic
design. That will also show up the need for other utilities to act
CONCURRENTLY, if possible.

> [ Memo to hackers: why is it that log_min_error_statement = error
> isn't the default? ]

For production systems where we expect fewer ERRORs, each one is
important, so this would be a good default.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chris Campbell <chris(at)bignerdranch(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2006-11-21 04:40:15
Message-ID: 24865.1164084015@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> On Oct 26, 2006, at 17:21, Tom Lane wrote:
>> And what was 1171 doing? I really doubt that either of these could
>> have been pg_dump.

> I know that process 1120 is a Java client (Hibernate) running an
> UPDATE query, but I have no idea what 1171 is. I doubt that 1171 was
> pg_dump, but when we turn off the pg_dump cron jobs (for 12-ish
> hours), the deadlocks go away. We usually see 5 or 6 deadlocks spread
> throughout the day. That's not definitive evidence, of course, but
> it's certainly curious.

FWIW, we recently found a deadlock risk that's likely to be triggered in
situations involving multiple updates and foreign keys. I still don't
see any connection to pg_dump, but otherwise it seems like it might be
related to your problem. Try this patch:
http://archives.postgresql.org/pgsql-committers/2006-11/msg00121.php

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2007-02-14 03:19:15
Message-ID: 200702140319.l1E3JFc07136@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Simon Riggs wrote:
> On Thu, 2006-10-26 at 18:45 -0400, Tom Lane wrote:
> > Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> > > Is there additional logging information I can turn on to get more
> > > details? I guess I need to see exactly what locks both processes
> > > hold, and what queries they were running when the deadlock occurred?
> > > Is that easily done, without turning on logging for *all* statements?
> >
> > log_min_error_statement = error would at least get you the statements
> > reporting the deadlocks, though not what they're conflicting against.
>
> Yeh, we need a much better locking logger for performance analysis.
>
> We really need to dump the whole wait-for graph for deadlocks, since
> this might be more complex than just two statements involved. Deadlocks
> ought to be so infrequent that we can afford the log space to do this -
> plus if we did this it would likely lead to fewer deadlocks.
>
> For 8.3 I'd like to have a log_min_duration_lockwait (secs) parameter
> that would allow you to dump the wait-for graph for any data-level locks
> that wait too long, rather than just those that deadlock. Many
> applications experience heavy locking because of lack of holistic
> design. That will also show up the need for other utilities to act
> CONCURRENTLY, if possible.

Old email, but I don't see how our current output is not good enough?

test=> lock a;
ERROR: deadlock detected
DETAIL: Process 6855 waits for AccessExclusiveLock on relation 16394 of
database 16384; blocked by process 6795.
Process 6795 waits for AccessExclusiveLock on relation 16396 of database
16384; blocked by process 6855.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Deadlock with pg_dump?
Date: 2007-02-19 19:38:41
Message-ID: 1171913921.25938.353.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Tue, 2007-02-13 at 22:19 -0500, Bruce Momjian wrote:
> Simon Riggs wrote:
> > On Thu, 2006-10-26 at 18:45 -0400, Tom Lane wrote:
> > > Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> > > > Is there additional logging information I can turn on to get more
> > > > details? I guess I need to see exactly what locks both processes
> > > > hold, and what queries they were running when the deadlock occurred?
> > > > Is that easily done, without turning on logging for *all* statements?
> > >
> > > log_min_error_statement = error would at least get you the statements
> > > reporting the deadlocks, though not what they're conflicting against.
> >
> > Yeh, we need a much better locking logger for performance analysis.
> >
> > We really need to dump the whole wait-for graph for deadlocks, since
> > this might be more complex than just two statements involved. Deadlocks
> > ought to be so infrequent that we can afford the log space to do this -
> > plus if we did this it would likely lead to fewer deadlocks.
> >
> > For 8.3 I'd like to have a log_min_duration_lockwait (secs) parameter
> > that would allow you to dump the wait-for graph for any data-level locks
> > that wait too long, rather than just those that deadlock. Many
> > applications experience heavy locking because of lack of holistic
> > design. That will also show up the need for other utilities to act
> > CONCURRENTLY, if possible.
>
> Old email, but I don't see how our current output is not good enough?
>
> test=> lock a;
> ERROR: deadlock detected
> DETAIL: Process 6855 waits for AccessExclusiveLock on relation 16394 of
> database 16384; blocked by process 6795.
> Process 6795 waits for AccessExclusiveLock on relation 16396 of database
> 16384; blocked by process 6855.

This detects deadlocks, but it doesn't detect lock waits.

When I wrote that it was previous experience driving me. Recent client
experience has highlighted the clear need for this. We had a lock wait
of 50 hours because of an RI check; thats the kind of thing I'd like to
show up in the logs somewhere.

Lock wait detection can be used to show up synchronisation points that
have been inadvertently designed into an application, so its a useful
tool in investigating performance issues.

I have a patch implementing the logging as agreed with Tom, will post to
patches later tonight.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, <pgsql-patches(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-19 22:29:40
Message-ID: 1171924180.25938.447.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2007-02-19 at 19:38 +0000, Simon Riggs wrote:
> On Tue, 2007-02-13 at 22:19 -0500, Bruce Momjian wrote:
> > Simon Riggs wrote:
> > > On Thu, 2006-10-26 at 18:45 -0400, Tom Lane wrote:
> > > > Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> > > > > Is there additional logging information I can turn on to get more
> > > > > details? I guess I need to see exactly what locks both processes
> > > > > hold, and what queries they were running when the deadlock occurred?
> > > > > Is that easily done, without turning on logging for *all* statements?
> > > >
> > > > log_min_error_statement = error would at least get you the statements
> > > > reporting the deadlocks, though not what they're conflicting against.
> > >
> > > Yeh, we need a much better locking logger for performance analysis.
> > >
> > > We really need to dump the whole wait-for graph for deadlocks, since
> > > this might be more complex than just two statements involved. Deadlocks
> > > ought to be so infrequent that we can afford the log space to do this -
> > > plus if we did this it would likely lead to fewer deadlocks.
> > >
> > > For 8.3 I'd like to have a log_min_duration_lockwait (secs) parameter
> > > that would allow you to dump the wait-for graph for any data-level locks
> > > that wait too long, rather than just those that deadlock. Many
> > > applications experience heavy locking because of lack of holistic
> > > design. That will also show up the need for other utilities to act
> > > CONCURRENTLY, if possible.
> >
> > Old email, but I don't see how our current output is not good enough?
> >
> > test=> lock a;
> > ERROR: deadlock detected
> > DETAIL: Process 6855 waits for AccessExclusiveLock on relation 16394 of
> > database 16384; blocked by process 6795.
> > Process 6795 waits for AccessExclusiveLock on relation 16396 of database
> > 16384; blocked by process 6855.
>
> This detects deadlocks, but it doesn't detect lock waits.
>
> When I wrote that it was previous experience driving me. Recent client
> experience has highlighted the clear need for this. We had a lock wait
> of 50 hours because of an RI check; thats the kind of thing I'd like to
> show up in the logs somewhere.
>
> Lock wait detection can be used to show up synchronisation points that
> have been inadvertently designed into an application, so its a useful
> tool in investigating performance issues.
>
> I have a patch implementing the logging as agreed with Tom, will post to
> patches later tonight.

Patch for discussion, includes doc entries at top of patch, so its
fairly clear how it works.

Output is an INFO message, to allow this to trigger
log_min_error_statement when it generates a message, to allow us to see
the SQL statement that is waiting. This allows it to generate a message
prior to the statement completing, which is important because it may not
ever complete, in some cases, so simply logging a list of pids won't
always tell you what the SQL was that was waiting.

Other approaches are possible...

Comments?

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com

Attachment Content-Type Size
log_lock_waits.v1.patch text/x-patch 13.9 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 18:34:01
Message-ID: 200702261834.l1QIY1M24204@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


I am a little concerned about a log_* setting that is INFO. I understand
why you used INFO (for log_min_error_messages), but INFO is inconsistent
with the log* prefix, and by default INFO doesn't appear in the log
file.

So, by default, the INFO is going to go to the user terminal, and not to
the logfile.

Ideas?

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

Simon Riggs wrote:
> On Mon, 2007-02-19 at 19:38 +0000, Simon Riggs wrote:
> > On Tue, 2007-02-13 at 22:19 -0500, Bruce Momjian wrote:
> > > Simon Riggs wrote:
> > > > On Thu, 2006-10-26 at 18:45 -0400, Tom Lane wrote:
> > > > > Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> > > > > > Is there additional logging information I can turn on to get more
> > > > > > details? I guess I need to see exactly what locks both processes
> > > > > > hold, and what queries they were running when the deadlock occurred?
> > > > > > Is that easily done, without turning on logging for *all* statements?
> > > > >
> > > > > log_min_error_statement = error would at least get you the statements
> > > > > reporting the deadlocks, though not what they're conflicting against.
> > > >
> > > > Yeh, we need a much better locking logger for performance analysis.
> > > >
> > > > We really need to dump the whole wait-for graph for deadlocks, since
> > > > this might be more complex than just two statements involved. Deadlocks
> > > > ought to be so infrequent that we can afford the log space to do this -
> > > > plus if we did this it would likely lead to fewer deadlocks.
> > > >
> > > > For 8.3 I'd like to have a log_min_duration_lockwait (secs) parameter
> > > > that would allow you to dump the wait-for graph for any data-level locks
> > > > that wait too long, rather than just those that deadlock. Many
> > > > applications experience heavy locking because of lack of holistic
> > > > design. That will also show up the need for other utilities to act
> > > > CONCURRENTLY, if possible.
> > >
> > > Old email, but I don't see how our current output is not good enough?
> > >
> > > test=> lock a;
> > > ERROR: deadlock detected
> > > DETAIL: Process 6855 waits for AccessExclusiveLock on relation 16394 of
> > > database 16384; blocked by process 6795.
> > > Process 6795 waits for AccessExclusiveLock on relation 16396 of database
> > > 16384; blocked by process 6855.
> >
> > This detects deadlocks, but it doesn't detect lock waits.
> >
> > When I wrote that it was previous experience driving me. Recent client
> > experience has highlighted the clear need for this. We had a lock wait
> > of 50 hours because of an RI check; thats the kind of thing I'd like to
> > show up in the logs somewhere.
> >
> > Lock wait detection can be used to show up synchronisation points that
> > have been inadvertently designed into an application, so its a useful
> > tool in investigating performance issues.
> >
> > I have a patch implementing the logging as agreed with Tom, will post to
> > patches later tonight.
>
> Patch for discussion, includes doc entries at top of patch, so its
> fairly clear how it works.
>
> Output is an INFO message, to allow this to trigger
> log_min_error_statement when it generates a message, to allow us to see
> the SQL statement that is waiting. This allows it to generate a message
> prior to the statement completing, which is important because it may not
> ever complete, in some cases, so simply logging a list of pids won't
> always tell you what the SQL was that was waiting.
>
> Other approaches are possible...
>
> Comments?
>
> --
> Simon Riggs
> EnterpriseDB http://www.enterprisedb.com
>

[ Attachment, skipping... ]

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, <pgsql-patches(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 19:01:24
Message-ID: 1172516484.3760.346.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2007-02-26 at 13:34 -0500, Bruce Momjian wrote:

> I am a little concerned about a log_* setting that is INFO. I understand
> why you used INFO (for log_min_error_messages), but INFO is inconsistent
> with the log* prefix, and by default INFO doesn't appear in the log
> file.

Yeh, LOG would be most appropriate, but thats not possible.

log_min_messages allows only DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1,
INFO, NOTICE and WARNING for non-error states.

Possibly DEBUG1?

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 19:11:23
Message-ID: 4826.1172517083@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
> Yeh, LOG would be most appropriate, but thats not possible.

You have not given any good reason for that.

> log_min_messages allows only DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1,
> INFO, NOTICE and WARNING for non-error states.

I don't think you understand quite how the log message priority works...

regards, tom lane


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, <pgsql-patches(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 19:19:49
Message-ID: 1172517590.3760.366.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2007-02-26 at 14:11 -0500, Tom Lane wrote:
> "Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
> > Yeh, LOG would be most appropriate, but thats not possible.
>
> You have not given any good reason for that.

The idea of the patch is that it generates a log message which then
invokes log_min_error_statement so that the SQL statement is displayed.
LOG is not on the list of options there, otherwise I would use it.

The reason for behaving like this is so that a message is generated
while the statement is still waiting, rather than at the end. As I
mentioned in the submission, you may not like that behaviour; I'm in two
minds myself, but I'm trying to get to the stage of having useful
information come out of the server when we have long lock waits.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 19:28:26
Message-ID: 5030.1172518106@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
> The idea of the patch is that it generates a log message which then
> invokes log_min_error_statement so that the SQL statement is displayed.
> LOG is not on the list of options there, otherwise I would use it.

As I said, you don't understand how the logging priority control works.
LOG *is* the appropriate level for stuff intended to go to the server log.

regards, tom lane


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, <pgsql-patches(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 19:31:49
Message-ID: 1172518309.3760.375.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2007-02-26 at 14:28 -0500, Tom Lane wrote:
> "Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
> > The idea of the patch is that it generates a log message which then
> > invokes log_min_error_statement so that the SQL statement is displayed.
> > LOG is not on the list of options there, otherwise I would use it.
>
> As I said, you don't understand how the logging priority control works.
> LOG *is* the appropriate level for stuff intended to go to the server log.

Please look at the definition of log_min_error_statement, so you
understand where I'm coming from.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 19:52:03
Message-ID: 5346.1172519523@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
> On Mon, 2007-02-26 at 14:28 -0500, Tom Lane wrote:
>> "Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
>>> The idea of the patch is that it generates a log message which then
>>> invokes log_min_error_statement so that the SQL statement is displayed.
>>> LOG is not on the list of options there, otherwise I would use it.
>>
>> As I said, you don't understand how the logging priority control works.
>> LOG *is* the appropriate level for stuff intended to go to the server log.

> Please look at the definition of log_min_error_statement, so you
> understand where I'm coming from.

I *have* read the definition of log_min_error_statement. (The SGML docs
are wrong btw, as a quick look at the code shows that LOG is an accepted
value.)

The real issue here is that send_message_to_server_log just does

if (edata->elevel >= log_min_error_statement && debug_query_string != NULL)

to determine whether to log the statement, whereas arguably it should be
using a test like is_log_level_output --- that is, the priority ordering
for log_min_error_statement should be like log_min_messages not like
client_min_messages. We've discussed that before in another thread, but
it looks like nothing's been done yet. In any case, if you're unhappy
with the code's choice of whether to emit the STATEMENT part of a log
message, some changes here are what's indicated, not bizarre choices of
elevel for individual messages.

regards, tom lane


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Chris Campbell" <chris(at)bignerdranch(dot)com>, <pgsql-patches(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 20:05:07
Message-ID: 1172520307.3760.384.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2007-02-26 at 14:52 -0500, Tom Lane wrote:
> "Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
> > On Mon, 2007-02-26 at 14:28 -0500, Tom Lane wrote:
> >> "Simon Riggs" <simon(at)2ndquadrant(dot)com> writes:
> >>> The idea of the patch is that it generates a log message which then
> >>> invokes log_min_error_statement so that the SQL statement is displayed.
> >>> LOG is not on the list of options there, otherwise I would use it.
> >>
> >> As I said, you don't understand how the logging priority control works.
> >> LOG *is* the appropriate level for stuff intended to go to the server log.
>
> > Please look at the definition of log_min_error_statement, so you
> > understand where I'm coming from.
>
> I *have* read the definition of log_min_error_statement. (The SGML docs
> are wrong btw, as a quick look at the code shows that LOG is an accepted
> value.)

OK, I should have looked passed the manual.

> The real issue here is that send_message_to_server_log just does
>
> if (edata->elevel >= log_min_error_statement && debug_query_string != NULL)
>
> to determine whether to log the statement, whereas arguably it should be
> using a test like is_log_level_output --- that is, the priority ordering
> for log_min_error_statement should be like log_min_messages not like
> client_min_messages. We've discussed that before in another thread, but
> it looks like nothing's been done yet.

Hopefully not with me? Don't remember that.

> In any case, if you're unhappy
> with the code's choice of whether to emit the STATEMENT part of a log
> message, some changes here are what's indicated, not bizarre choices of
> elevel for individual messages.

Well, I would have chosen LOG if I thought it was available.

I'll do some more to the patch.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 20:10:49
Message-ID: 200702262010.l1QKAnn15959@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Simon Riggs wrote:
> On Mon, 2007-02-26 at 13:34 -0500, Bruce Momjian wrote:
>
> > I am a little concerned about a log_* setting that is INFO. I understand
> > why you used INFO (for log_min_error_messages), but INFO is inconsistent
> > with the log* prefix, and by default INFO doesn't appear in the log
> > file.
>
> Yeh, LOG would be most appropriate, but thats not possible.
>
> log_min_messages allows only DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1,
> INFO, NOTICE and WARNING for non-error states.
>
> Possibly DEBUG1?

This highlights a problem we have often had with LOG output where we
also want the query.

I think there are two possible approaches. First, we could add a new
bitmap value like LOG_STATEMENT to ereport when we want the statement
with the log line:

ereport (LOG | LOG_STATEMENT, ...)

(or a new LOG_WITH_STATEMENT log level) and a new GUC like
"log_include_statement" that would control the output of statements for
certain GUC parameters, and we document with GUC values it controls.

A simpler idea would be to unconditionally include the query in the
errdetail() of the actual LOG ereport.

This is not the first GUC that has needed this. We had this issue with
"log_temp_files", which we just added, and the only suggested solution
was to use log_statement = 'all'. Either of these ideas above would be
useful for this as well.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-02-26 20:15:43
Message-ID: 5698.1172520943@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> This is not the first GUC that has needed this.

Exactly. I think that we simply made a mistake in the initial
implementation of log_min_error_statement: we failed to think about
whether it should use client or server priority ordering, and the
easy-to-code behavior was the wrong one.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-01 02:06:15
Message-ID: 200703010206.l2126FY01384@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > This is not the first GUC that has needed this.
>
> Exactly. I think that we simply made a mistake in the initial
> implementation of log_min_error_statement: we failed to think about
> whether it should use client or server priority ordering, and the
> easy-to-code behavior was the wrong one.

I have coded up the following patch which places LOG just above ERROR in
log_min_error_statement.

It also adds the new log level LOG_NO_STATEMENT, which is used only for
internal use by ereport() calls that should not print the statement.
This is particularly useful so log_statemant and
log_min_duration_statement do not print the statement twice.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/pgpatches/log_min text/x-diff 11.6 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-01 05:45:54
Message-ID: 15832.1172727954@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> I have coded up the following patch which places LOG just above ERROR in
> log_min_error_statement.

LOG_NO_STATEMENT? What *are* you thinking? The kindest word I can find
for this is "baroque".

What I had in mind was a one-line patch:

if (edata->elevel >= log_min_error_statement && debug_query_string != NULL)

becomes

if (is_log_level_output(edata->elevel, log_min_error_statement) && debug_query_string != NULL)

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-01 14:06:41
Message-ID: 200703011406.l21E6fe28790@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > I have coded up the following patch which places LOG just above ERROR in
> > log_min_error_statement.
>
> LOG_NO_STATEMENT? What *are* you thinking? The kindest word I can find
> for this is "baroque".
>
> What I had in mind was a one-line patch:
>
> if (edata->elevel >= log_min_error_statement && debug_query_string != NULL)
>
> becomes
>
> if (is_log_level_output(edata->elevel, log_min_error_statement) && debug_query_string != NULL)

What are *you* thinking? Yes, that patch has that line, but
log_statement and log_min_duration_statement is going to trigger
log_min_error_statement so you are going to get the statement printed
twice. LOG_NO_STATEMENT fixes that.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-01 19:17:20
Message-ID: 12779.1172776640@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> What are *you* thinking? Yes, that patch has that line, but
> log_statement and log_min_duration_statement is going to trigger
> log_min_error_statement so you are going to get the statement printed
> twice.

What's wrong with that? If a statement triggers two different log
entries, and both are subject to being annotated with the statement text
according to log_min_error_statement, I would expect them both to be
annotated. Doing otherwise will probably break automated log analysis
tools.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-02 18:35:41
Message-ID: 200703021835.l22IZfu03867@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > What are *you* thinking? Yes, that patch has that line, but
> > log_statement and log_min_duration_statement is going to trigger
> > log_min_error_statement so you are going to get the statement printed
> > twice.
>
> What's wrong with that? If a statement triggers two different log
> entries, and both are subject to being annotated with the statement text
> according to log_min_error_statement, I would expect them both to be
> annotated. Doing otherwise will probably break automated log analysis
> tools.

Are people going to be happy that log_statement and
log_min_duration_statement output the statement twice?

test=> SHOW log_min_error_statement;
log_min_error_statement
-------------------------
error
(1 row)

test=> SET log_statement = 'all';
SET
test=> SELECT 1;
?column?
----------
1
(1 row)

Server log has:

LOG: statement: SELECT 1;
STATEMENT: SELECT 1;

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-02 18:51:32
Message-ID: 15421.1172861492@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Are people going to be happy that log_statement and
> log_min_duration_statement output the statement twice?

If those are the only cases you're worried about, a far simpler solution
is to clear debug_query_string before instead of after emitting those
log messages.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-02 20:20:27
Message-ID: 200703022020.l22KKRQ00125@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Are people going to be happy that log_statement and
> > log_min_duration_statement output the statement twice?
>
> If those are the only cases you're worried about, a far simpler solution
> is to clear debug_query_string before instead of after emitting those
> log messages.

I am concerned about setting debug_query_string to NULL, calling
ereport(), and then resetting it might cause problems because of cases
where ereport might want to access debug_query_string for other uses,
for cases where ereport doesn't return to the reset code (but I assume
that is handled), and for cases like pgmonitor that would stop a
backend, read debug_query_string, and disconnect.

I can create a global variable to control this, but the new elog level
seemed cleaner.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-02 20:55:05
Message-ID: 16441.1172868905@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> I can create a global variable to control this, but the new elog level
> seemed cleaner.

What I don't like about the proposed patch is that it's nonorthogonal.
I see no reason to suppose that LOG is the only possible elevel for
which it might be interesting to suppress the STATEMENT: field.

Perhaps the best thing would be to define an additional ereport
auxiliary function, say errprintstmt(bool), that could set a flag
in the current elog stack entry to control suppression of STATEMENT.
This would mean you couldn't determine the behavior when using elog(),
but that's not supposed to be used for user-facing messages anyway.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-02 22:05:41
Message-ID: 200703022205.l22M5fi29939@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > I can create a global variable to control this, but the new elog level
> > seemed cleaner.
>
> What I don't like about the proposed patch is that it's nonorthogonal.
> I see no reason to suppose that LOG is the only possible elevel for
> which it might be interesting to suppress the STATEMENT: field.

True.

> Perhaps the best thing would be to define an additional ereport
> auxiliary function, say errprintstmt(bool), that could set a flag
> in the current elog stack entry to control suppression of STATEMENT.
> This would mean you couldn't determine the behavior when using elog(),
> but that's not supposed to be used for user-facing messages anyway.

One idea I had was to set the high-bit of elevel to control whether we
want to suppress statement logging, but I think errprintstmt() might be
best. I don't understand the ereport stack well enough to add this
functionality, though. What should I look for?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-02 22:37:33
Message-ID: 17338.1172875053@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Tom Lane wrote:
>> Perhaps the best thing would be to define an additional ereport
>> auxiliary function, say errprintstmt(bool), that could set a flag
>> in the current elog stack entry to control suppression of STATEMENT.
>> This would mean you couldn't determine the behavior when using elog(),
>> but that's not supposed to be used for user-facing messages anyway.

> One idea I had was to set the high-bit of elevel to control whether we
> want to suppress statement logging, but I think errprintstmt() might be
> best. I don't understand the ereport stack well enough to add this
> functionality, though. What should I look for?

It wouldn't really be any different from errcode(), but if you want
I'll do it.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-02 22:46:40
Message-ID: 200703022246.l22Mkeo10707@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Tom Lane wrote:
> >> Perhaps the best thing would be to define an additional ereport
> >> auxiliary function, say errprintstmt(bool), that could set a flag
> >> in the current elog stack entry to control suppression of STATEMENT.
> >> This would mean you couldn't determine the behavior when using elog(),
> >> but that's not supposed to be used for user-facing messages anyway.
>
> > One idea I had was to set the high-bit of elevel to control whether we
> > want to suppress statement logging, but I think errprintstmt() might be
> > best. I don't understand the ereport stack well enough to add this
> > functionality, though. What should I look for?
>
> It wouldn't really be any different from errcode(), but if you want
> I'll do it.

If you would just add the infrastructure I can add the LOG part.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-02 23:38:54
Message-ID: 22134.1172878734@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Tom Lane wrote:
>> It wouldn't really be any different from errcode(), but if you want
>> I'll do it.

> If you would just add the infrastructure I can add the LOG part.

OK, I applied a patch that covers the same territory as your patch of
Wednesday evening. I didn't do anything about Simon's original patch
--- I assume that needs some rework now.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Deadlock with pg_dump?
Date: 2007-03-03 02:40:54
Message-ID: 200703030240.l232esI14731@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Tom Lane wrote:
> >> It wouldn't really be any different from errcode(), but if you want
> >> I'll do it.
>
> > If you would just add the infrastructure I can add the LOG part.
>
> OK, I applied a patch that covers the same territory as your patch of
> Wednesday evening. I didn't do anything about Simon's original patch
> --- I assume that needs some rework now.

Thanks. I will rework Simon's.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2007-03-03 02:43:54
Message-ID: 200703030243.l232hs815187@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


I will rework this before application to use LOG level.

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

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

Simon Riggs wrote:
> On Mon, 2007-02-19 at 19:38 +0000, Simon Riggs wrote:
> > On Tue, 2007-02-13 at 22:19 -0500, Bruce Momjian wrote:
> > > Simon Riggs wrote:
> > > > On Thu, 2006-10-26 at 18:45 -0400, Tom Lane wrote:
> > > > > Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> > > > > > Is there additional logging information I can turn on to get more
> > > > > > details? I guess I need to see exactly what locks both processes
> > > > > > hold, and what queries they were running when the deadlock occurred?
> > > > > > Is that easily done, without turning on logging for *all* statements?
> > > > >
> > > > > log_min_error_statement = error would at least get you the statements
> > > > > reporting the deadlocks, though not what they're conflicting against.
> > > >
> > > > Yeh, we need a much better locking logger for performance analysis.
> > > >
> > > > We really need to dump the whole wait-for graph for deadlocks, since
> > > > this might be more complex than just two statements involved. Deadlocks
> > > > ought to be so infrequent that we can afford the log space to do this -
> > > > plus if we did this it would likely lead to fewer deadlocks.
> > > >
> > > > For 8.3 I'd like to have a log_min_duration_lockwait (secs) parameter
> > > > that would allow you to dump the wait-for graph for any data-level locks
> > > > that wait too long, rather than just those that deadlock. Many
> > > > applications experience heavy locking because of lack of holistic
> > > > design. That will also show up the need for other utilities to act
> > > > CONCURRENTLY, if possible.
> > >
> > > Old email, but I don't see how our current output is not good enough?
> > >
> > > test=> lock a;
> > > ERROR: deadlock detected
> > > DETAIL: Process 6855 waits for AccessExclusiveLock on relation 16394 of
> > > database 16384; blocked by process 6795.
> > > Process 6795 waits for AccessExclusiveLock on relation 16396 of database
> > > 16384; blocked by process 6855.
> >
> > This detects deadlocks, but it doesn't detect lock waits.
> >
> > When I wrote that it was previous experience driving me. Recent client
> > experience has highlighted the clear need for this. We had a lock wait
> > of 50 hours because of an RI check; thats the kind of thing I'd like to
> > show up in the logs somewhere.
> >
> > Lock wait detection can be used to show up synchronisation points that
> > have been inadvertently designed into an application, so its a useful
> > tool in investigating performance issues.
> >
> > I have a patch implementing the logging as agreed with Tom, will post to
> > patches later tonight.
>
> Patch for discussion, includes doc entries at top of patch, so its
> fairly clear how it works.
>
> Output is an INFO message, to allow this to trigger
> log_min_error_statement when it generates a message, to allow us to see
> the SQL statement that is waiting. This allows it to generate a message
> prior to the statement completing, which is important because it may not
> ever complete, in some cases, so simply logging a list of pids won't
> always tell you what the SQL was that was waiting.
>
> Other approaches are possible...
>
> Comments?
>
> --
> Simon Riggs
> EnterpriseDB http://www.enterprisedb.com
>

[ Attachment, skipping... ]

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Chris Campbell <chris(at)bignerdranch(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deadlock with pg_dump?
Date: 2007-03-03 18:49:32
Message-ID: 200703031849.l23InW315428@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


I have applied a modified version of this patch, attached. I trimmed
down the description of log_lock_waits to be more concise, and moved the
idea of using this to tune deadlock_timeout to the deadlock_timeout
section of the manual.

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

Simon Riggs wrote:
> On Mon, 2007-02-19 at 19:38 +0000, Simon Riggs wrote:
> > On Tue, 2007-02-13 at 22:19 -0500, Bruce Momjian wrote:
> > > Simon Riggs wrote:
> > > > On Thu, 2006-10-26 at 18:45 -0400, Tom Lane wrote:
> > > > > Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> > > > > > Is there additional logging information I can turn on to get more
> > > > > > details? I guess I need to see exactly what locks both processes
> > > > > > hold, and what queries they were running when the deadlock occurred?
> > > > > > Is that easily done, without turning on logging for *all* statements?
> > > > >
> > > > > log_min_error_statement = error would at least get you the statements
> > > > > reporting the deadlocks, though not what they're conflicting against.
> > > >
> > > > Yeh, we need a much better locking logger for performance analysis.
> > > >
> > > > We really need to dump the whole wait-for graph for deadlocks, since
> > > > this might be more complex than just two statements involved. Deadlocks
> > > > ought to be so infrequent that we can afford the log space to do this -
> > > > plus if we did this it would likely lead to fewer deadlocks.
> > > >
> > > > For 8.3 I'd like to have a log_min_duration_lockwait (secs) parameter
> > > > that would allow you to dump the wait-for graph for any data-level locks
> > > > that wait too long, rather than just those that deadlock. Many
> > > > applications experience heavy locking because of lack of holistic
> > > > design. That will also show up the need for other utilities to act
> > > > CONCURRENTLY, if possible.
> > >
> > > Old email, but I don't see how our current output is not good enough?
> > >
> > > test=> lock a;
> > > ERROR: deadlock detected
> > > DETAIL: Process 6855 waits for AccessExclusiveLock on relation 16394 of
> > > database 16384; blocked by process 6795.
> > > Process 6795 waits for AccessExclusiveLock on relation 16396 of database
> > > 16384; blocked by process 6855.
> >
> > This detects deadlocks, but it doesn't detect lock waits.
> >
> > When I wrote that it was previous experience driving me. Recent client
> > experience has highlighted the clear need for this. We had a lock wait
> > of 50 hours because of an RI check; thats the kind of thing I'd like to
> > show up in the logs somewhere.
> >
> > Lock wait detection can be used to show up synchronisation points that
> > have been inadvertently designed into an application, so its a useful
> > tool in investigating performance issues.
> >
> > I have a patch implementing the logging as agreed with Tom, will post to
> > patches later tonight.
>
> Patch for discussion, includes doc entries at top of patch, so its
> fairly clear how it works.
>
> Output is an INFO message, to allow this to trigger
> log_min_error_statement when it generates a message, to allow us to see
> the SQL statement that is waiting. This allows it to generate a message
> prior to the statement completing, which is important because it may not
> ever complete, in some cases, so simply logging a list of pids won't
> always tell you what the SQL was that was waiting.
>
> Other approaches are possible...
>
> Comments?
>
> --
> Simon Riggs
> EnterpriseDB http://www.enterprisedb.com
>

[ Attachment, skipping... ]

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/rtmp/diff text/x-diff 15.5 KB