vacuum deadlock

--0014852d2193248042047ed74ac9
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I am using PostgreSQL 8.3.7.
autovacuum is enabled in postgresql.conf

I got a deadlock while vacuuming all databases with vacuumdb command.

vacuumdb: vacuuming of database "mydb" failed: ERROR: deadlock detected
DETAIL: Process 1294 waits for AccessExclusiveLock on relation 2662 of
database ; blocked by process 1807.
Process 1807 waits for AccessShareLock on relation 1259 of database 16389;
blocked by process 1294.

I think, because of this lock, deleting a large table (15 million records)
was taking too much time
How can I know the name of the relations 2662 and 1259?

Do you have any ide about the problem and solution?


Thanks in advance.

--0014852d2193248042047ed74ac9
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,<br><br>I am using PostgreSQL 8.3.7.<br>autovacuum is enabled in postgre=
sql.conf<br><br>I got=A0 a deadlock while vacuuming all databases with vacu=
umdb command.<br><br>vacuumdb: vacuuming of database "mydb" faile=
d: ERROR:=A0 deadlock detected<br>
DETAIL:=A0 Process 1294 waits for AccessExclusiveLock on relation 2662 of d=
atabase =A0=A0=A0 ; blocked by process 1807.<br>Process 1807 waits for Acce=
ssShareLock on relation 1259 of database 16389; blocked by process 1294.<br=
><br>
I think, because of this lock, deleting a large table (15 million records) =
was taking too much time<br>How can I know the name of the relations 2662 a=
nd 1259?<br><br>Do you have any ide about the problem and solution?<br>
<br><br>Thanks in advance.<br>

--0014852d2193248042047ed74ac9--
Ibrahim Harrani [ Fr, 05 Februar 2010 10:43 ] [ ID #2031390 ]

Re: vacuum deadlock

--001636c5a68373379d047ede6b02
Content-Type: text/plain; charset=ISO-8859-1

Hi Yeb,

Thanks for your reply.
As far as I know, pg_class_oid_index and pg_class are postgresql internal
relations.

Normally, there is not application that directly using those relations.
How should I map this lock issue on this relations to my application side?
On which cases those are locked and used by applications?


Thanks

On Fri, Feb 5, 2010 at 2:36 PM, Yeb Havinga <yebhavinga [at] gmail.com> wrote:

> Ibrahim Harrani wrote:
>
>> Hi,
>>
>> I am using PostgreSQL 8.3.7.
>> autovacuum is enabled in postgresql.conf
>>
>> I got a deadlock while vacuuming all databases with vacuumdb command.
>>
>> vacuumdb: vacuuming of database "mydb" failed: ERROR: deadlock detected
>> DETAIL: Process 1294 waits for AccessExclusiveLock on relation 2662 of
>> database ; blocked by process 1807.
>> Process 1807 waits for AccessShareLock on relation 1259 of database 16389;
>> blocked by process 1294.
>>
>> I think, because of this lock, deleting a large table (15 million records)
>> was taking too much time
>> How can I know the name of the relations 2662 and 1259?
>>
> postgres=# select oid,relname from pg_class where oid in (2662,1259);
> oid | relname ------+--------------------
> 2662 | pg_class_oid_index
> 1259 | pg_class
> (2 rows)
>
> Do you have any ide about the problem and solution?
>>
> It would be interesting to know what are the processes 1807 and 1294. Once
> that is known, try to avoid executing both processes concurrently.
>
> regards
> Yeb Havinga
>
>

--001636c5a68373379d047ede6b02
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Yeb,<br><br> Thanks for your reply.<br>As far as I know, pg_class_oid_in=
dex and pg_class are postgresql internal relations.<br><br>Normally, there=
is not application that directly using those relations.<br>How should I ma=
p this lock issue on this relations to my application side?<br>
On which cases those are locked and used by applications?<br><br><br>Thanks=
<br><br><div class=3D"gmail_quote">On Fri, Feb 5, 2010 at 2:36 PM, Yeb Havi=
nga <span dir=3D"ltr"><<a href=3D"mailto:yebhavinga [at] gmail.com">yebhaving=
a [at] gmail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class=3D"im"=
>Ibrahim Harrani wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I am using PostgreSQL 8.3.7.<br>
autovacuum is enabled in postgresql.conf<br>
<br>
I got =A0a deadlock while vacuuming all databases with vacuumdb command.<br=
>
<br>
vacuumdb: vacuuming of database "mydb" failed: ERROR: =A0deadlock=
detected<br>
DETAIL: =A0Process 1294 waits for AccessExclusiveLock on relation 2662 of d=
atabase =A0 =A0 ; blocked by process 1807.<br>
Process 1807 waits for AccessShareLock on relation 1259 of database 16389; =
blocked by process 1294.<br>
<br>
I think, because of this lock, deleting a large table (15 million records) =
was taking too much time<br>
How can I know the name of the relations 2662 and 1259?<br>
</blockquote></div>
postgres=3D# select oid,relname from pg_class where oid in (2662,1259);<br>
oid =A0| =A0 =A0 =A0relname =A0 =A0 =A0------+--------------------<br>
2662 | pg_class_oid_index<br>
1259 | pg_class<br>
(2 rows)<div class=3D"im"><br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Do you have any ide about the problem and solution?<br>
</blockquote></div>
It would be interesting to know what are the processes 1807 and 1294. Once =
that is known, try to avoid executing both processes concurrently.<br>
<br>
regards<br><font color=3D"#888888">
Yeb Havinga<br>
<br>
</font></blockquote></div><br>

--001636c5a68373379d047ede6b02--
Ibrahim Harrani [ Fr, 05 Februar 2010 19:14 ] [ ID #2031392 ]

Re: vacuum deadlock

Ibrahim Harrani <ibrahim.harrani [at] gmail.com> wrote:
> Yeb Havinga <yebhavinga [at] gmail.com> wrote:
>> Ibrahim Harrani wrote:

>>> I am using PostgreSQL 8.3.7.
>>> autovacuum is enabled in postgresql.conf
>>>
>>> I got a deadlock while vacuuming all databases with vacuumdb
>>> command.
>>>
>>> vacuumdb: vacuuming of database "mydb" failed: ERROR: deadlock
>>> detected
>>> DETAIL: Process 1294 waits for AccessExclusiveLock on relation
>>> 2662 of database ; blocked by process 1807.
>>> Process 1807 waits for AccessShareLock on relation 1259 of
>>> database 16389; blocked by process 1294.
>>>
>>> I think, because of this lock, deleting a large table (15
>>> million records) was taking too much time
>>> How can I know the name of the relations 2662 and 1259?
>>>
>> postgres=# select oid,relname from pg_class where oid in
>> (2662,1259);
>> oid | relname ------+--------------------
>> 2662 | pg_class_oid_index
>> 1259 | pg_class
>> (2 rows)

> As far as I know, pg_class_oid_index and pg_class are postgresql
> internal relations.
>
> Normally, there is not application that directly using those
> relations.
> How should I map this lock issue on this relations to my
> application side?
> On which cases those are locked and used by applications?

Are you creating temporary tables somehow during this process, like
within functions (including trigger functions)?

Can you test the delete with autovacuum disabled?

When you say "deleting a large table" do you mean, dropping the
table, deleting all rows from the table, or deleting some of the
rows from the table?

If you could show the actual delete statement and all information
about the table(s) involved, including indexes, triggers, and
foreign keys, that might help.

-Kevin

--
Sent via pgsql-admin mailing list (pgsql-admin [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Kevin Grittner [ Fr, 05 Februar 2010 19:47 ] [ ID #2031393 ]

Re: vacuum deadlock

Ibrahim Harrani <ibrahim.harrani [at] gmail.com> writes:
> I got a deadlock while vacuuming all databases with vacuumdb command.

> vacuumdb: vacuuming of database "mydb" failed: ERROR: deadlock detected
> DETAIL: Process 1294 waits for AccessExclusiveLock on relation 2662 of
> database ; blocked by process 1807.
> Process 1807 waits for AccessShareLock on relation 1259 of database 16389;
> blocked by process 1294.

vacuumdb -f you mean? An ordinary vacuum wouldn't be trying to take
AccessExclusiveLock.

It might be that you have an instance of a failure that was identified
just a couple weeks ago:
http://archives.postgresql.org/pgsql-committers/2010-01/msg0 0199.php

regards, tom lane

--
Sent via pgsql-admin mailing list (pgsql-admin [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Tom Lane [ Sa, 06 Februar 2010 07:11 ] [ ID #2031504 ]

Re: vacuum deadlock

--000e0ce0af6e1b89180480baa6d8
Content-Type: text/plain; charset=ISO-8859-1

Hi,

Yes, I am trying to full vacuum.

I think, I found the problem. There were more then 10 million records which
my scripts trying to delete at night from a table while other processes were
adding new entries to same table.
Delete can't finish in the day, and script tries to delete the table again
in next night via crontab
then this cause to dead lock?

SQL query: "delete from mytable where createtime < now - '10 days';


We added 1K limit option to delete query in a for loop. Now I can delete all
entries but slowly

DELETE FROM mytable WHERE id = any (array(SELECT id FROM mytable WHERE
createtime < NOW() - INTERVAL '10 day' LIMIT 1000))

I am planning to partion(day based) this large table, then I will simply
drop the tables after certain days.

Do you have any other suggestion?

Thanks.

On Sat, Feb 6, 2010 at 8:11 AM, Tom Lane <tgl [at] sss.pgh.pa.us> wrote:

> Ibrahim Harrani <ibrahim.harrani [at] gmail.com> writes:
> > I got a deadlock while vacuuming all databases with vacuumdb command.
>
> > vacuumdb: vacuuming of database "mydb" failed: ERROR: deadlock detected
> > DETAIL: Process 1294 waits for AccessExclusiveLock on relation 2662 of
> > database ; blocked by process 1807.
> > Process 1807 waits for AccessShareLock on relation 1259 of database
> 16389;
> > blocked by process 1294.
>
> vacuumdb -f you mean? An ordinary vacuum wouldn't be trying to take
> AccessExclusiveLock.
>
> It might be that you have an instance of a failure that was identified
> just a couple weeks ago:
> http://archives.postgresql.org/pgsql-committers/2010-01/msg0 0199.php
>
> regards, tom lane
>

--000e0ce0af6e1b89180480baa6d8
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,<br><br>Yes,=A0 I am trying to full vacuum.<br><br>I think, I=A0 found t=
he problem. There were more then 10 million records which my scripts trying=
to delete at night from a table while other processes were adding new entr=
ies to same table.<br>
Delete can't finish in the day, and script tries to delete the table ag=
ain in next night via crontab<br>then this cause to dead lock?<br><br>SQL q=
uery: "delete from mytable where createtime < now - '10 days=
9;;<br>
<br><br>We added 1K limit option to delete query in a for loop. Now I can d=
elete all entries but slowly=A0 <br><br>DELETE FROM mytable WHERE id =3D an=
y (array(SELECT id FROM mytable WHERE createtime < NOW() - INTERVAL '=
;10 day'=A0 LIMIT 1000))<br>
<br>I am planning to partion(day based) this large table, then I will simpl=
y drop the tables after certain days.<br><br>Do you have any other suggesti=
on?<br><br>Thanks.<br><br><div class=3D"gmail_quote">On Sat, Feb 6, 2010 at=
8:11 AM, Tom Lane <span dir=3D"ltr"><<a href=3D"mailto:tgl [at] sss.pgh.pa.u=
s">tgl [at] sss.pgh.pa.us</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class=3D"im"=
>Ibrahim Harrani <<a href=3D"mailto:ibrahim.harrani [at] gmail.com">ibrahim.h=
arrani [at] gmail.com</a>> writes:<br>

> I got =A0a deadlock while vacuuming all databases with vacuumdb comman=
d.<br>
<br>
> vacuumdb: vacuuming of database "mydb" failed: ERROR: =A0dea=
dlock detected<br>
> DETAIL: =A0Process 1294 waits for AccessExclusiveLock on relation 2662=
of<br>
> database =A0 =A0 ; blocked by process 1807.<br>
> Process 1807 waits for AccessShareLock on relation 1259 of database 16=
389;<br>
> blocked by process 1294.<br>
<br>
</div>vacuumdb -f you mean? =A0An ordinary vacuum wouldn't be trying to=
take<br>
AccessExclusiveLock.<br>
<br>
It might be that you have an instance of a failure that was identified<br>
just a couple weeks ago:<br>
<a href=3D"http://archives.postgresql.org/pgsql-committers/2010-01/msg00199=
..php" target=3D"_blank">http://archives.postgresql.org/pgsql-commi tters/201=
0-01/msg00199.php</a><br>
<br>
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0regards, tom lane<br>
</blockquote></div><br>

--000e0ce0af6e1b89180480baa6d8--
Ibrahim Harrani [ Mo, 01 März 2010 11:24 ] [ ID #2033681 ]
Datenbanken » gmane.comp.db.postgresql.admin » vacuum deadlock

Vorheriges Thema: severely wierd problem & PgSQL log analyzer
Nächstes Thema: db recovery after hd crash (could not open relation 1663/16385/16400: