pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #8434: Why does dead lock occur many times ?
11+ messages / 5 participants
[nested] [flat]
* BUG #8434: Why does dead lock occur many times ?
@ 2013-09-04 09:14 katsumata.tomonari@po.ntts.co.jp
0 siblings, 2 replies; 11+ messages in thread
From: katsumata.tomonari@po.ntts.co.jp @ 2013-09-04 09:14 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 8434
Logged by: Tomonari Katsumata
Email address: katsumata.tomonari@po.ntts.co.jp
PostgreSQL version: 9.3rc1
Operating system: RedHatEnterpriseLinux 6.4(x86_64)
Description:
Hi,
I'm testing PostgreSQL 9.3rc1.
Many times updates and selects for update become dead lock situation.
The reproduce is:
1. initializing data
createdb testdb
psql testdb -c "create table t (col1 int, col2 int, col3 text);"
psql testdb -c "insert into t values (1, 4, 'A');"
psql testdb -c "insert into t values (2, 5, 'B');"
psql testdb -c "insert into t values (3, 6, 'C');"
2. executing updates and selects for update
(run below script)
----
#!/bin/sh
./tx1 > /dev/null &
./tx2 > /dev/null &
./tx3 > /dev/null &
wait
----
tx1 is:
----
#!/bin/sh
while :
do
psql testdb << EOF
BEGIN;
UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
COMMIT;
\q
EOF
done
----
tx2 is:
----
#!/bin/sh
while :
do
psql testdb << EOF
BEGIN;
SELECT col1, col2, col3 FROM t WHERE col1 = 3 AND col2 = 6 FOR UPDATE;
UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
COMMIT;
\q
EOF
done
----
tx3 is:
----
#!/bin/sh
while :
do
psql testdb << EOF
BEGIN;
UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
COMMIT;
\q
EOF
done
----
Then, I got below messages.
--------
2013-09-04 15:25:25 JST 29630 5226d254.73be-1 659102 (pgsql, testdb,
[local], psql) LOG: 00000: process 29630 detected deadlock while waiting
for ShareLock on transaction 659103 after 1000.136 ms
2013-09-04 15:25:25 JST 29630 5226d254.73be-2 659102 (pgsql, testdb,
[local], psql) LOCATION: ProcSleep, proc.c:1232
2013-09-04 15:25:25 JST 29630 5226d254.73be-3 659102 (pgsql, testdb,
[local], psql) STATEMENT: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 =
6;
2013-09-04 15:25:25 JST 29630 5226d254.73be-4 659102 (pgsql, testdb,
[local], psql) ERROR: 40P01: deadlock detected
2013-09-04 15:25:25 JST 29630 5226d254.73be-5 659102 (pgsql, testdb,
[local], psql) DETAIL: Process 29630 waits for ShareLock on transaction
659103; blocked by process 29631.
Process 29631 waits for ExclusiveLock on tuple (0,153) of relation
16385 of database 16384; blocked by process 29630.
Process 29630: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
Process 29631: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
2013-09-04 15:25:25 JST 29630 5226d254.73be-6 659102 (pgsql, testdb,
[local], psql) HINT: See server log for query details.
2013-09-04 15:25:25 JST 29630 5226d254.73be-7 659102 (pgsql, testdb,
[local], psql) LOCATION: DeadLockReport, deadlock.c:956
2013-09-04 15:25:25 JST 29630 5226d254.73be-8 659102 (pgsql, testdb,
[local], psql) STATEMENT: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 =
6;
--------
I did not get these messages with PostgreSQL 9.2.4.
Why did I get the dead lock situation with PostgreSQL9.3rc1?
degrading? or I'm missing something?
regards,
------------
Tomonari Katsumata
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-09-19 11:52 OTSUKA Kenji <otsuka.knj@gmail.com>
parent: katsumata.tomonari@po.ntts.co.jp
1 sibling, 1 reply; 11+ messages in thread
From: OTSUKA Kenji @ 2013-09-19 11:52 UTC (permalink / raw)
To: pgsql-bugs; +Cc: katsumata.tomonari@po.ntts.co.jp
Hi,
This issue occurred even on 9.3.0.
I took the following information, and I attached them.
pg_locks.txt ... pg_locks during deadlock
pg_stat_activity.txt ... pg_stat_activity during deadlock
postgresql.log ... PostgreSQL log (including LOCK_DEBUG log)
The OID of the table is 16459.
I run 3 transactions.
One transaction of them executes SELECT FOR UPDATE and UPDATE a row.
And two transactions of them execute only UPDATE the same line.
The results is that all of UPDATE is waiting.
I changed a little bit how to reproduce.
It is as follows.
- Compiling PostgreSQL
Add -DLOCK_DEBUG to CFLAGS
- Changing postgresql.conf following parameters
log_lock_waits = on
deadlock_timeout = 1min # for getting information during deadlock
debug_deadlocks = on
trace_lock_table = 16459
log_line_prefix = '%t [%p] %q(%a) '
logging_collector = on
log_filename = 'postgresql.log'
log_min_messages = info
log_error_verbosity = verbose
- Testing
1. Initializing data
Executing createdb.sh
This creates a table with 2 columns, and insert 1 row.
2. Running the transactions
Executing test.sh
This runs 3 transactions.
2 transactions of them (tx1) are
BEGIN;
UPDATE t SET col2 = 'A' WHERE col1 = 1;
COMMIT;
1 transaction of them (tx2) is
BEGIN;
SELECT * FROM t WHERE col1 = 1 FOR UPDATE;
UPDATE t SET col2 = 'A' WHERE col1 = 1;
COMMIT;
regards,
2013/9/4 <katsumata.tomonari@po.ntts.co.jp>
> The following bug has been logged on the website:
>
> Bug reference: 8434
> Logged by: Tomonari Katsumata
> Email address: katsumata.tomonari@po.ntts.co.jp
> PostgreSQL version: 9.3rc1
> Operating system: RedHatEnterpriseLinux 6.4(x86_64)
> Description:
>
> Hi,
>
>
> I'm testing PostgreSQL 9.3rc1.
> Many times updates and selects for update become dead lock situation.
>
>
> The reproduce is:
> 1. initializing data
> createdb testdb
> psql testdb -c "create table t (col1 int, col2 int, col3 text);"
> psql testdb -c "insert into t values (1, 4, 'A');"
> psql testdb -c "insert into t values (2, 5, 'B');"
> psql testdb -c "insert into t values (3, 6, 'C');"
>
>
> 2. executing updates and selects for update
> (run below script)
> ----
> #!/bin/sh
>
>
> ./tx1 > /dev/null &
> ./tx2 > /dev/null &
> ./tx3 > /dev/null &
>
>
> wait
> ----
>
>
> tx1 is:
> ----
> #!/bin/sh
>
>
> while :
> do
> psql testdb << EOF
> BEGIN;
> UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
> COMMIT;
> \q
> EOF
> done
> ----
>
>
> tx2 is:
> ----
> #!/bin/sh
>
>
> while :
> do
> psql testdb << EOF
> BEGIN;
> SELECT col1, col2, col3 FROM t WHERE col1 = 3 AND col2 = 6 FOR UPDATE;
> UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
> COMMIT;
> \q
> EOF
> done
> ----
>
>
> tx3 is:
> ----
> #!/bin/sh
>
>
> while :
> do
> psql testdb << EOF
> BEGIN;
> UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
> COMMIT;
> \q
> EOF
> done
> ----
>
>
> Then, I got below messages.
> --------
> 2013-09-04 15:25:25 JST 29630 5226d254.73be-1 659102 (pgsql, testdb,
> [local], psql) LOG: 00000: process 29630 detected deadlock while waiting
> for ShareLock on transaction 659103 after 1000.136 ms
> 2013-09-04 15:25:25 JST 29630 5226d254.73be-2 659102 (pgsql, testdb,
> [local], psql) LOCATION: ProcSleep, proc.c:1232
> 2013-09-04 15:25:25 JST 29630 5226d254.73be-3 659102 (pgsql, testdb,
> [local], psql) STATEMENT: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2
> =
> 6;
> 2013-09-04 15:25:25 JST 29630 5226d254.73be-4 659102 (pgsql, testdb,
> [local], psql) ERROR: 40P01: deadlock detected
> 2013-09-04 15:25:25 JST 29630 5226d254.73be-5 659102 (pgsql, testdb,
> [local], psql) DETAIL: Process 29630 waits for ShareLock on transaction
> 659103; blocked by process 29631.
> Process 29631 waits for ExclusiveLock on tuple (0,153) of relation
> 16385 of database 16384; blocked by process 29630.
> Process 29630: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
> Process 29631: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
> 2013-09-04 15:25:25 JST 29630 5226d254.73be-6 659102 (pgsql, testdb,
> [local], psql) HINT: See server log for query details.
> 2013-09-04 15:25:25 JST 29630 5226d254.73be-7 659102 (pgsql, testdb,
> [local], psql) LOCATION: DeadLockReport, deadlock.c:956
> 2013-09-04 15:25:25 JST 29630 5226d254.73be-8 659102 (pgsql, testdb,
> [local], psql) STATEMENT: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2
> =
> 6;
> --------
>
>
> I did not get these messages with PostgreSQL 9.2.4.
>
>
> Why did I get the dead lock situation with PostgreSQL9.3rc1?
> degrading? or I'm missing something?
>
>
> regards,
> ------------
> Tomonari Katsumata
>
>
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>
--
OTSUKA Kenji
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
pg_locks.txt (text/plain, 3.1K) download
testdb=# SELECT * FROM pg_locks;
locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
---------------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-------+------------------+---------+----------
relation | 16458 | 16459 | | | | | | | | 4/1232 | 19671 | RowExclusiveLock | t | t
virtualxid | | | | | 4/1232 | | | | | 4/1232 | 19671 | ExclusiveLock | t | t
relation | 16458 | 16459 | | | | | | | | 3/1404 | 19670 | RowShareLock | t | t
relation | 16458 | 16459 | | | | | | | | 3/1404 | 19670 | RowExclusiveLock | t | t
virtualxid | | | | | 3/1404 | | | | | 3/1404 | 19670 | ExclusiveLock | t | t
relation | 16458 | 16459 | | | | | | | | 5/694 | 19673 | RowExclusiveLock | t | t
virtualxid | | | | | 5/694 | | | | | 5/694 | 19673 | ExclusiveLock | t | t
relation | 16458 | 11090 | | | | | | | | 2/4 | 16248 | AccessShareLock | t | t
virtualxid | | | | | 2/4 | | | | | 2/4 | 16248 | ExclusiveLock | t | t
transactionid | | | | | | 133499 | | | | 4/1232 | 19671 | ShareLock | f | f
tuple | 16458 | 16459 | 0 | 8 | | | | | | 4/1232 | 19671 | ExclusiveLock | t | f
transactionid | | | | | | 133498 | | | | 4/1232 | 19671 | ExclusiveLock | t | f
transactionid | | | | | | 133499 | | | | 3/1404 | 19670 | ExclusiveLock | t | f
tuple | 16458 | 16459 | 0 | 8 | | | | | | 3/1404 | 19670 | ExclusiveLock | f | f
tuple | 16458 | 16459 | 0 | 8 | | | | | | 5/694 | 19673 | ExclusiveLock | f | f
transactionid | | | | | | 133500 | | | | 5/694 | 19673 | ExclusiveLock | t | f
(16 rows)
create.sh (application/x-sh, 126B) download
pg_stat_activity.txt (text/plain, 2.4K) download
testdb=# SELECT * FROM pg_stat_activity;
-[ RECORD 1 ]----+--------------------------------------------------------------
datid | 16458
datname | testdb
pid | 16248
usesysid | 10
usename | tsuka
application_name | psql
client_addr |
client_hostname |
client_port | -1
backend_start | 2013-09-19 19:29:00.685596+09
xact_start | 2013-09-19 19:29:23.117776+09
query_start | 2013-09-19 19:29:23.117776+09
state_change | 2013-09-19 19:29:23.11778+09
waiting | f
state | active
query | SELECT * FROM pg_stat_activity;
-[ RECORD 2 ]----+--------------------------------------------------------------
datid | 16458
datname | testdb
pid | 19670
usesysid | 10
usename | tsuka
application_name | psql
client_addr |
client_hostname |
client_port | -1
backend_start | 2013-09-19 19:29:19.907824+09
xact_start | 2013-09-19 19:29:19.910575+09
query_start | 2013-09-19 19:29:19.916775+09
state_change | 2013-09-19 19:29:19.916776+09
waiting | t
state | active
query | UPDATE /* SELECTandUPDATE */ t SET col2 = 'A' WHERE col1 = 1;
-[ RECORD 3 ]----+--------------------------------------------------------------
datid | 16458
datname | testdb
pid | 19671
usesysid | 10
usename | tsuka
application_name | psql
client_addr |
client_hostname |
client_port | -1
backend_start | 2013-09-19 19:29:19.911065+09
xact_start | 2013-09-19 19:29:19.913637+09
query_start | 2013-09-19 19:29:19.913746+09
state_change | 2013-09-19 19:29:19.913747+09
waiting | t
state | active
query | UPDATE /* onlyUPDATE */ t SET col2 = 'A' WHERE col1 = 1;
-[ RECORD 4 ]----+--------------------------------------------------------------
datid | 16458
datname | testdb
pid | 19673
usesysid | 10
usename | tsuka
application_name | psql
client_addr |
client_hostname |
client_port | -1
backend_start | 2013-09-19 19:29:19.919346+09
xact_start | 2013-09-19 19:29:19.921483+09
query_start | 2013-09-19 19:29:19.921602+09
state_change | 2013-09-19 19:29:19.921603+09
waiting | t
state | active
query | UPDATE /* onlyUPDATE */ t SET col2 = 'A' WHERE col1 = 1;
postgresql.log (application/octet-stream, 30.5K) download
test.sh (application/x-sh, 510B) download
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-09-28 01:39 Tomonari Katsumata <t.katsumata1122@gmail.com>
parent: OTSUKA Kenji <otsuka.knj@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Tomonari Katsumata @ 2013-09-28 01:39 UTC (permalink / raw)
To: OTSUKA Kenji <otsuka.knj@gmail.com>; +Cc: pgsql-bugs; Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
Hi,
Thanks to your info, otsuka-san.
It seems to be related to some changes in
the [Improve concurrency of foreign key locking] commit(*).
(*) commitid : 0ac5ad5134f2769ccbaefec73844f8504c4d6182
Because I could not reproduce "dead lock" before the commit.
And I'm thinking that also this commit is related to BUG#8470.
If so, I hope Alvaro will find the solution for this problem.
Maybe I can't take enough time, but I'll investigate this continuously.
If someone could reproduce this, please share information.
regards,
-------
NTT Software Corporation
Tomonari Katsumata
2013/9/19 OTSUKA Kenji <otsuka.knj@gmail.com>
> Hi,
>
> This issue occurred even on 9.3.0.
> I took the following information, and I attached them.
>
> pg_locks.txt ... pg_locks during deadlock
> pg_stat_activity.txt ... pg_stat_activity during deadlock
> postgresql.log ... PostgreSQL log (including LOCK_DEBUG log)
>
> The OID of the table is 16459.
>
> I run 3 transactions.
> One transaction of them executes SELECT FOR UPDATE and UPDATE a row.
> And two transactions of them execute only UPDATE the same line.
>
> The results is that all of UPDATE is waiting.
>
>
> I changed a little bit how to reproduce.
> It is as follows.
>
> - Compiling PostgreSQL
> Add -DLOCK_DEBUG to CFLAGS
>
> - Changing postgresql.conf following parameters
> log_lock_waits = on
> deadlock_timeout = 1min # for getting information during deadlock
> debug_deadlocks = on
> trace_lock_table = 16459
>
> log_line_prefix = '%t [%p] %q(%a) '
> logging_collector = on
> log_filename = 'postgresql.log'
> log_min_messages = info
> log_error_verbosity = verbose
>
> - Testing
> 1. Initializing data
> Executing createdb.sh
> This creates a table with 2 columns, and insert 1 row.
>
> 2. Running the transactions
> Executing test.sh
> This runs 3 transactions.
>
> 2 transactions of them (tx1) are
> BEGIN;
> UPDATE t SET col2 = 'A' WHERE col1 = 1;
> COMMIT;
>
> 1 transaction of them (tx2) is
> BEGIN;
> SELECT * FROM t WHERE col1 = 1 FOR UPDATE;
> UPDATE t SET col2 = 'A' WHERE col1 = 1;
> COMMIT;
>
> regards,
>
>
>
> 2013/9/4 <katsumata.tomonari@po.ntts.co.jp>
>
> The following bug has been logged on the website:
>>
>> Bug reference: 8434
>> Logged by: Tomonari Katsumata
>> Email address: katsumata.tomonari@po.ntts.co.jp
>> PostgreSQL version: 9.3rc1
>> Operating system: RedHatEnterpriseLinux 6.4(x86_64)
>> Description:
>>
>> Hi,
>>
>>
>> I'm testing PostgreSQL 9.3rc1.
>> Many times updates and selects for update become dead lock situation.
>>
>>
>> The reproduce is:
>> 1. initializing data
>> createdb testdb
>> psql testdb -c "create table t (col1 int, col2 int, col3 text);"
>> psql testdb -c "insert into t values (1, 4, 'A');"
>> psql testdb -c "insert into t values (2, 5, 'B');"
>> psql testdb -c "insert into t values (3, 6, 'C');"
>>
>>
>> 2. executing updates and selects for update
>> (run below script)
>> ----
>> #!/bin/sh
>>
>>
>> ./tx1 > /dev/null &
>> ./tx2 > /dev/null &
>> ./tx3 > /dev/null &
>>
>>
>> wait
>> ----
>>
>>
>> tx1 is:
>> ----
>> #!/bin/sh
>>
>>
>> while :
>> do
>> psql testdb << EOF
>> BEGIN;
>> UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
>> COMMIT;
>> \q
>> EOF
>> done
>> ----
>>
>>
>> tx2 is:
>> ----
>> #!/bin/sh
>>
>>
>> while :
>> do
>> psql testdb << EOF
>> BEGIN;
>> SELECT col1, col2, col3 FROM t WHERE col1 = 3 AND col2 = 6 FOR UPDATE;
>> UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
>> COMMIT;
>> \q
>> EOF
>> done
>> ----
>>
>>
>> tx3 is:
>> ----
>> #!/bin/sh
>>
>>
>> while :
>> do
>> psql testdb << EOF
>> BEGIN;
>> UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 = 6;
>> COMMIT;
>> \q
>> EOF
>> done
>> ----
>>
>>
>> Then, I got below messages.
>> --------
>> 2013-09-04 15:25:25 JST 29630 5226d254.73be-1 659102 (pgsql, testdb,
>> [local], psql) LOG: 00000: process 29630 detected deadlock while waiting
>> for ShareLock on transaction 659103 after 1000.136 ms
>> 2013-09-04 15:25:25 JST 29630 5226d254.73be-2 659102 (pgsql, testdb,
>> [local], psql) LOCATION: ProcSleep, proc.c:1232
>> 2013-09-04 15:25:25 JST 29630 5226d254.73be-3 659102 (pgsql, testdb,
>> [local], psql) STATEMENT: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND
>> col2 =
>> 6;
>> 2013-09-04 15:25:25 JST 29630 5226d254.73be-4 659102 (pgsql, testdb,
>> [local], psql) ERROR: 40P01: deadlock detected
>> 2013-09-04 15:25:25 JST 29630 5226d254.73be-5 659102 (pgsql, testdb,
>> [local], psql) DETAIL: Process 29630 waits for ShareLock on transaction
>> 659103; blocked by process 29631.
>> Process 29631 waits for ExclusiveLock on tuple (0,153) of relation
>> 16385 of database 16384; blocked by process 29630.
>> Process 29630: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 =
>> 6;
>> Process 29631: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND col2 =
>> 6;
>> 2013-09-04 15:25:25 JST 29630 5226d254.73be-6 659102 (pgsql, testdb,
>> [local], psql) HINT: See server log for query details.
>> 2013-09-04 15:25:25 JST 29630 5226d254.73be-7 659102 (pgsql, testdb,
>> [local], psql) LOCATION: DeadLockReport, deadlock.c:956
>> 2013-09-04 15:25:25 JST 29630 5226d254.73be-8 659102 (pgsql, testdb,
>> [local], psql) STATEMENT: UPDATE t SET col3 = 'c' WHERE col1 = 3 AND
>> col2 =
>> 6;
>> --------
>>
>>
>> I did not get these messages with PostgreSQL 9.2.4.
>>
>>
>> Why did I get the dead lock situation with PostgreSQL9.3rc1?
>> degrading? or I'm missing something?
>>
>>
>> regards,
>> ------------
>> Tomonari Katsumata
>>
>>
>>
>>
>> --
>> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-bugs
>>
>
>
>
> --
> OTSUKA Kenji
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>
>
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-09-28 01:47 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Tomonari Katsumata <t.katsumata1122@gmail.com>
0 siblings, 0 replies; 11+ messages in thread
From: Alvaro Herrera @ 2013-09-28 01:47 UTC (permalink / raw)
To: Tomonari Katsumata <t.katsumata1122@gmail.com>; +Cc: OTSUKA Kenji <otsuka.knj@gmail.com>; pgsql-bugs; Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
Hi,
Sorry I hadn't noticed this thread.
Tomonari Katsumata escribió:
> It seems to be related to some changes in
> the [Improve concurrency of foreign key locking] commit(*).
> (*) commitid : 0ac5ad5134f2769ccbaefec73844f8504c4d6182
> Because I could not reproduce "dead lock" before the commit.
Yes, sounds pretty likely.
> And I'm thinking that also this commit is related to BUG#8470.
Yes, I replied to that thread because I suspect the same.
> If so, I hope Alvaro will find the solution for this problem.
I will take a look at this problem next week.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-10-04 17:22 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: katsumata.tomonari@po.ntts.co.jp
1 sibling, 1 reply; 11+ messages in thread
From: Alvaro Herrera @ 2013-10-04 17:22 UTC (permalink / raw)
To: katsumata.tomonari@po.ntts.co.jp; +Cc: pgsql-bugs
I spent a lot of time looking at this issue. Your problem scenario can
be reduced to the following test case:
CREATE TABLE t (a INT);
INSERT INTO t VALUES (1);
The three sessions need to execute the following commands, in this
sequence:
-- Session 1
/* 1 */ BEGIN;
SELECT * FROM t FOR UPDATE;
-- Session 2
/* 2 */ BEGIN;
UPDATE t SET a = 2; -- blocks waiting on S1
-- Session 3
/* 3 */ BEGIN;
UPDATE t SET a = 3; -- blocks
-- this is waiting on S1, but since S2 is also waiting on S1 and will acquire a
-- conflicting lock first, this session will only be released after S2 releases
-- its own lock.
Session 1
/* 4 */ UPDATE t SET a = 4;
COMMIT; -- releases session 2
BEGIN;
SELECT * FROM t FOR UPDATE; -- blocks waiting on S2 (*)
Session 2:
/* 5 */ COMMIT; -- releases session 1
BEGIN;
UPDATE t SET a = 5; -- blocks waiting on S3
Session 1:
/* 6 */ UPDATE t SET a = 6; -- blocks waiting on S3
At this point, all sessions are blocked on their UPDATE commands, and
deadlock is reported. (For debugging, it's useful to set a very large
deadlock_timeout and examine pg_locks, etc.)
The point at which things started to go wrong was where the session 1's
SELECT FOR UPDATE with the (*) was allowed to continue after session 2
commits. In 9.2 that session remains blocked, and instead we release
session 3.
The problem is the handling of following of the update chain during a
lock command; the question is should sessions be blocked waiting for
locks on future versions of the row? They currently don't block, which
is what leads the SELECT FOR UPDATE to continue; but if we make them
block, other things break. I initially toyed with the following patch,
which removes the deadlock the above report and also your original test
case:
inline patch 1: src/backend/access/heap/heapam.c (+5/-8 lines) download inline-1.patch
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -4832,15 +4832,12 @@ l4:
xmax = HeapTupleHeaderGetRawXmax(mytup.t_data);
/*
- * If this tuple is updated and the key has been modified (or
- * deleted), what we do depends on the status of the updating
- * transaction: if it's live, we sleep until it finishes; if it has
- * committed, we have to fail (i.e. return HeapTupleUpdated); if it
- * aborted, we ignore it. For updates that didn't touch the key, we
- * can just plough ahead.
+ * If this tuple is updated, what we do depends on the status of the
+ * updating transaction: if it's live, we sleep until it finishes; if
+ * it has committed, we have to fail (i.e. return HeapTupleUpdated); if
+ * it aborted, we ignore it.
*/
- if (!(old_infomask & HEAP_XMAX_INVALID) &&
- (mytup.t_data->t_infomask2 & HEAP_KEYS_UPDATED))
+ if (!(old_infomask & HEAP_XMAX_INVALID))
{
TransactionId update_xid;
However, the differences in behavior this causes (visible by running the
isolation tests) don't look good to me. It's quite possible that there
are other bugs elsewhere.
Sadly, I have to look at other things now and I won't have time to
research this further until after next week's minor releases; so
whatever we decide to do, if anything, will not be in 9.3.1.
Thanks for the report.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-11-27 16:42 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 2 replies; 11+ messages in thread
From: Alvaro Herrera @ 2013-11-27 16:42 UTC (permalink / raw)
To: katsumata.tomonari@po.ntts.co.jp; +Cc: pgsql-bugs
I think I have figured this out. This code was being too simplistic in
that it was only checking whether there was a key-update or not; but
that, it seems, is not sufficiently fine-grained. If we instead think
in terms of an already-acquired MultiXactStatus, and a new
MultiXactStatus corresponding to the lock we're trying to acquire, we
can decide granularly whether each future version of the tuple can be
locked by us or not. And if not, we can decide whether we need to wait
on the transaction holding the lock, or fail if it already committed.
(There is a funny trick here which is that we represent the held lock
with a MultiXactStatus, even if the lock is only a plain Xid and not a
multi. This doesn't seem a problem to me.)
So I propose the attached patch. This doesn't change the behavior
codified in the existing isolation tests, and it fixes my reduction of
your original test case. (I haven't run your original test case yet,
but I soon will.)
Note: I don't quite like that this patch duplicates some code in
compute_new_xmax_infomask() which determines the MultiXactStatus from
the infomask bits. Not sure what a good refactoring is, though, because
that code just issues a WARNING when the LOCK_ONLY bit is set and no
other lockmode is set; whereas the new code issues an ERROR. It seems
hard to justify doing otherwise in either place, though; and doing
something more complicated doesn't seem warranted for such a corner
case.
Note: this patch doesn't apply to master in isolation. You will need
the patch I mention in
http://www.postgresql.org/message-id/20131125201039.GF6597@eldon.alvh.no-ip.org
even though I haven't posted it yet. Will do so shortly.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
granular-chain-following.patch (text/x-diff, 7.6K) download
*** a/src/backend/access/heap/heapam.c
--- b/src/backend/access/heap/heapam.c
***************
*** 4799,4804 **** l5:
--- 4799,4881 ----
*result_xmax = new_xmax;
}
+ /*
+ * Subroutine for heap_lock_updated_tuple_rec.
+ *
+ * Given an hypothetical multixact status held by the transaction identified
+ * with the given xid, does the current transaction need to wait, fail, or can
+ * it continue if it wanted to acquire a lock of the given mode? "needwait"
+ * is set to true if waiting is necessary; if it can continue, then
+ * HeapTupleMayBeUpdated is returned. In case of a conflict, a different
+ * HeapTupleSatisfiesUpdate return code is returned.
+ *
+ * The held status is said to be hypothetical because it might correspond to a
+ * lock held by a single Xid, i.e. not a real MultiXactId; we express it this
+ * way for simplicity of API.
+ */
+ static HTSU_Result
+ test_lockmode_for_conflict(MultiXactStatus status, TransactionId xid,
+ LockTupleMode mode, bool *needwait)
+ {
+ MultiXactStatus wantedstatus;
+
+ *needwait = false;
+ wantedstatus = get_mxact_status_for_lock(mode, false);
+
+ /*
+ * Note: we *must* check TransactionIdIsInProgress before
+ * TransactionIdDidAbort/Commit; see comment at top of tqual.c for an
+ * explanation.
+ */
+ if (TransactionIdIsCurrentTransactionId(xid))
+ {
+ /*
+ * Updated by our own transaction? Just return failure. This shouldn't
+ * normally happen.
+ */
+ return HeapTupleSelfUpdated;
+ }
+ else if (TransactionIdIsInProgress(xid))
+ {
+ /*
+ * If the locking transaction is running, what we do depends on whether
+ * the lock modes conflict: if they do, then we must wait for it to
+ * finish; otherwise we can fall through to lock this tuple version
+ * without waiting.
+ */
+ if (DoLockModesConflict(LOCKMODE_from_mxstatus(status),
+ LOCKMODE_from_mxstatus(wantedstatus)))
+ {
+ *needwait = true;
+ }
+
+ /*
+ * If we set needwait above, then this value doesn't matter; otherwise,
+ * this value signals to caller that it's okay to proceed.
+ */
+ return HeapTupleMayBeUpdated;
+ }
+ else if (TransactionIdDidAbort(xid))
+ return HeapTupleMayBeUpdated;
+ else if (TransactionIdDidCommit(xid))
+ {
+ /*
+ * If the updating transaction committed, what we do depends on whether
+ * the lock modes conflict: if they do, then we must report error to
+ * caller. But if they don't, we can fall through to lock it.
+ */
+ if (DoLockModesConflict(LOCKMODE_from_mxstatus(status),
+ LOCKMODE_from_mxstatus(wantedstatus)))
+ /* bummer */
+ return HeapTupleUpdated;
+
+ return HeapTupleMayBeUpdated;
+ }
+
+ /* Not in progress, not aborted, not committed -- must have crashed */
+ return HeapTupleMayBeUpdated;
+ }
+
/*
* Recursive part of heap_lock_updated_tuple
***************
*** 4816,4822 **** heap_lock_updated_tuple_rec(Relation rel, ItemPointer tid, TransactionId xid,
Buffer buf;
uint16 new_infomask,
new_infomask2,
! old_infomask;
TransactionId xmax,
new_xmax;
TransactionId priorXmax = InvalidTransactionId;
--- 4893,4900 ----
Buffer buf;
uint16 new_infomask,
new_infomask2,
! old_infomask,
! old_infomask2;
TransactionId xmax,
new_xmax;
TransactionId priorXmax = InvalidTransactionId;
***************
*** 4858,4902 **** l4:
}
old_infomask = mytup.t_data->t_infomask;
xmax = HeapTupleHeaderGetRawXmax(mytup.t_data);
/*
! * If this tuple is updated and the key has been modified (or
! * deleted), what we do depends on the status of the updating
! * transaction: if it's live, we sleep until it finishes; if it has
! * committed, we have to fail (i.e. return HeapTupleUpdated); if it
! * aborted, we ignore it. For updates that didn't touch the key, we
! * can just plough ahead.
*/
! if (!(old_infomask & HEAP_XMAX_INVALID) &&
! (mytup.t_data->t_infomask2 & HEAP_KEYS_UPDATED))
{
! TransactionId update_xid;
! /*
! * Note: we *must* check TransactionIdIsInProgress before
! * TransactionIdDidAbort/Commit; see comment at top of tqual.c for
! * an explanation.
! */
! update_xid = HeapTupleHeaderGetUpdateXid(mytup.t_data);
! if (TransactionIdIsCurrentTransactionId(update_xid))
{
! UnlockReleaseBuffer(buf);
! return HeapTupleSelfUpdated;
! }
! else if (TransactionIdIsInProgress(update_xid))
! {
! LockBuffer(buf, BUFFER_LOCK_UNLOCK);
! /* No LockTupleTuplock here -- see heap_lock_updated_tuple */
! XactLockTableWait(update_xid);
! goto l4;
}
! else if (TransactionIdDidAbort(update_xid))
! ; /* okay to proceed */
! else if (TransactionIdDidCommit(update_xid))
{
! UnlockReleaseBuffer(buf);
! return HeapTupleUpdated;
}
}
--- 4936,5042 ----
}
old_infomask = mytup.t_data->t_infomask;
+ old_infomask2 = mytup.t_data->t_infomask2;
xmax = HeapTupleHeaderGetRawXmax(mytup.t_data);
/*
! * If this tuple version has been updated or locked by some concurrent
! * transaction(s), what we do depends on whether our lock mode
! * conflicts with what those other transactions hold, and also on the
! * status of them.
*/
! if (!(old_infomask & HEAP_XMAX_INVALID))
{
! TransactionId rawxmax;
! bool needwait;
! rawxmax = HeapTupleHeaderGetRawXmax(mytup.t_data);
! if (old_infomask & HEAP_XMAX_IS_MULTI)
{
! int nmembers;
! int i;
! MultiXactMember *members;
!
! nmembers = GetMultiXactIdMembers(rawxmax, &members, false, false);
! for (i = 0; i < nmembers; i++)
! {
! HTSU_Result res;
!
! res = test_lockmode_for_conflict(members[i].status,
! members[i].xid,
! mode, &needwait);
!
! if (needwait)
! {
! LockBuffer(buf, BUFFER_LOCK_UNLOCK);
! XactLockTableWait(members[i].xid);
! pfree(members);
! goto l4;
! }
! if (res != HeapTupleMayBeUpdated)
! {
! UnlockReleaseBuffer(buf);
! pfree(members);
! return res;
! }
! }
! if (members)
! pfree(members);
}
! else
{
! HTSU_Result res;
! MultiXactStatus status;
!
! /*
! * For a non-multi Xmax, we first need to compute the
! * corresponding MultiXactStatus by using the infomask bits.
! */
! if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask))
! {
! if (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask))
! status = MultiXactStatusForKeyShare;
! else if (HEAP_XMAX_IS_SHR_LOCKED(old_infomask))
! status = MultiXactStatusForShare;
! else if (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))
! {
! if (old_infomask2 & HEAP_KEYS_UPDATED)
! status = MultiXactStatusForUpdate;
! else
! status = MultiXactStatusForNoKeyUpdate;
! }
! else
! {
! /*
! * LOCK_ONLY present alone (a pg_upgraded tuple
! * marked as share-locked in the old cluster) shouldn't
! * be seen in the middle of an update chain.
! */
! elog(ERROR, "invalid lock status in tuple");
! }
! }
! else
! {
! /* it's an update, but which kind? */
! if (old_infomask2 & HEAP_KEYS_UPDATED)
! status = MultiXactStatusUpdate;
! else
! status = MultiXactStatusNoKeyUpdate;
! }
!
! res = test_lockmode_for_conflict(status, rawxmax, mode,
! &needwait);
! if (needwait)
! {
! LockBuffer(buf, BUFFER_LOCK_UNLOCK);
! XactLockTableWait(rawxmax);
! goto l4;
! }
! if (res != HeapTupleMayBeUpdated)
! {
! UnlockReleaseBuffer(buf);
! return res;
! }
}
}
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-11-28 00:52 Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 0 replies; 11+ messages in thread
From: Tomonari Katsumata @ 2013-11-28 00:52 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs
Hi Alvaro,
Thank you for finding it out!
I'll test it from now, so please
give me a while time.
regards,
(2013/11/28 1:42), Alvaro Herrera wrote:
> I think I have figured this out. This code was being too simplistic in
> that it was only checking whether there was a key-update or not; but
> that, it seems, is not sufficiently fine-grained. If we instead think
> in terms of an already-acquired MultiXactStatus, and a new
> MultiXactStatus corresponding to the lock we're trying to acquire, we
> can decide granularly whether each future version of the tuple can be
> locked by us or not. And if not, we can decide whether we need to wait
> on the transaction holding the lock, or fail if it already committed.
> (There is a funny trick here which is that we represent the held lock
> with a MultiXactStatus, even if the lock is only a plain Xid and not a
> multi. This doesn't seem a problem to me.)
>
> So I propose the attached patch. This doesn't change the behavior
> codified in the existing isolation tests, and it fixes my reduction of
> your original test case. (I haven't run your original test case yet,
> but I soon will.)
>
> Note: I don't quite like that this patch duplicates some code in
> compute_new_xmax_infomask() which determines the MultiXactStatus from
> the infomask bits. Not sure what a good refactoring is, though, because
> that code just issues a WARNING when the LOCK_ONLY bit is set and no
> other lockmode is set; whereas the new code issues an ERROR. It seems
> hard to justify doing otherwise in either place, though; and doing
> something more complicated doesn't seem warranted for such a corner
> case.
>
> Note: this patch doesn't apply to master in isolation. You will need
> the patch I mention in
>
http://www.postgresql.org/message-id/20131125201039.GF6597@eldon.alvh.no-ip.org
> even though I haven't posted it yet. Will do so shortly.
>
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-11-28 04:00 Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 1 reply; 11+ messages in thread
From: Tomonari Katsumata @ 2013-11-28 04:00 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs
Hi Alvaro
I applied all patches you told me against 93_STABLE.
But I could not build the source with the patches.
It seems your patch use GetMultiXactIdMembers with four arguments,
but the function requires three arguments.
----
nmembers = GetMultiXactIdMembers(rawxmax, &members, false, false);
----
do you have another patch?
Am I missing something?
(2013/11/28 1:42), Alvaro Herrera wrote:
> I think I have figured this out. This code was being too simplistic in
> that it was only checking whether there was a key-update or not; but
> that, it seems, is not sufficiently fine-grained. If we instead think
> in terms of an already-acquired MultiXactStatus, and a new
> MultiXactStatus corresponding to the lock we're trying to acquire, we
> can decide granularly whether each future version of the tuple can be
> locked by us or not. And if not, we can decide whether we need to wait
> on the transaction holding the lock, or fail if it already committed.
> (There is a funny trick here which is that we represent the held lock
> with a MultiXactStatus, even if the lock is only a plain Xid and not a
> multi. This doesn't seem a problem to me.)
>
> So I propose the attached patch. This doesn't change the behavior
> codified in the existing isolation tests, and it fixes my reduction of
> your original test case. (I haven't run your original test case yet,
> but I soon will.)
>
> Note: I don't quite like that this patch duplicates some code in
> compute_new_xmax_infomask() which determines the MultiXactStatus from
> the infomask bits. Not sure what a good refactoring is, though, because
> that code just issues a WARNING when the LOCK_ONLY bit is set and no
> other lockmode is set; whereas the new code issues an ERROR. It seems
> hard to justify doing otherwise in either place, though; and doing
> something more complicated doesn't seem warranted for such a corner
> case.
>
> Note: this patch doesn't apply to master in isolation. You will need
> the patch I mention in
>
http://www.postgresql.org/message-id/20131125201039.GF6597@eldon.alvh.no-ip.org
> even though I haven't posted it yet. Will do so shortly.
>
>
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-11-28 11:22 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
0 siblings, 1 reply; 11+ messages in thread
From: Alvaro Herrera @ 2013-11-28 11:22 UTC (permalink / raw)
To: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>; +Cc: pgsql-bugs
Tomonari Katsumata wrote:
> Hi Alvaro
>
> I applied all patches you told me against 93_STABLE.
> But I could not build the source with the patches.
>
> It seems your patch use GetMultiXactIdMembers with four arguments,
> but the function requires three arguments.
> ----
> nmembers = GetMultiXactIdMembers(rawxmax, &members, false, false);
> ----
>
> do you have another patch?
Sorry, yes. This is the complete series of patches, although I have not
tried them against 9.3 yet.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments: download all (5 files, .tar.gz)
0001-Skip-looking-up-very-old-LOCK_ONLY-MultiXactIds.patch (text/x-diff, 9.9K) download
From ef026a8110f40941741585e07671398beea28f11 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Wed, 27 Nov 2013 17:19:41 -0300
Subject: [PATCH 1/5] Skip looking up very old LOCK_ONLY MultiXactIds
Commit 0ac5ad5134f2 removed an optimization in multixact.c that skipped
fetching members of MultiXactId that were older than our
OldestVisibleMXactId value. The reason this was removed is that it is
possible for multis that contain updates to be older than that value.
However, if the caller is certain that the multi does not contain an
update (because the infomask bits say so), it can pass this info down to
GetMultiXactIdMembers, enabling it to use the old optimization.
Pointed out by Andres Freund in 20131121200517.GM7240@alap2.anarazel.de
---
contrib/pgrowlocks/pgrowlocks.c | 3 ++-
src/backend/access/heap/heapam.c | 20 +++++++++++++-------
src/backend/access/transam/multixact.c | 29 ++++++++++++++++++++++++-----
src/backend/utils/time/tqual.c | 11 ++++++-----
src/include/access/multixact.h | 4 ++--
5 files changed, 47 insertions(+), 20 deletions(-)
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index 636ff05..8d4961c 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -168,7 +168,8 @@ pgrowlocks(PG_FUNCTION_ARGS)
allow_old = !(infomask & HEAP_LOCK_MASK) &&
(infomask & HEAP_XMAX_LOCK_ONLY);
- nmembers = GetMultiXactIdMembers(xmax, &members, allow_old);
+ nmembers = GetMultiXactIdMembers(xmax, &members, allow_old,
+ false);
if (nmembers == -1)
{
values[Atnum_xids] = "{0}";
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index a21f31b..32ef453 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -3987,7 +3987,9 @@ l3:
* the case, HeapTupleSatisfiesUpdate would have returned
* MayBeUpdated and we wouldn't be here.
*/
- nmembers = GetMultiXactIdMembers(xwait, &members, false);
+ nmembers =
+ GetMultiXactIdMembers(xwait, &members, false,
+ HEAP_XMAX_IS_LOCKED_ONLY(infomask));
for (i = 0; i < nmembers; i++)
{
@@ -4008,7 +4010,8 @@ l3:
}
}
- pfree(members);
+ if (members)
+ pfree(members);
}
/*
@@ -4157,7 +4160,9 @@ l3:
* been the case, HeapTupleSatisfiesUpdate would have returned
* MayBeUpdated and we wouldn't be here.
*/
- nmembers = GetMultiXactIdMembers(xwait, &members, false);
+ nmembers =
+ GetMultiXactIdMembers(xwait, &members, false,
+ HEAP_XMAX_IS_LOCKED_ONLY(infomask));
if (nmembers <= 0)
{
@@ -4626,7 +4631,7 @@ l5:
* MultiXactIdExpand if we weren't to do this, so this check is not
* incurring extra work anyhow.
*/
- if (!MultiXactIdIsRunning(xmax))
+ if (!MultiXactIdIsRunning(xmax, HEAP_XMAX_IS_LOCKED_ONLY(old_infomask)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
TransactionIdDidAbort(MultiXactIdGetUpdateXid(xmax,
@@ -5217,7 +5222,7 @@ GetMultiXactIdHintBits(MultiXactId multi, uint16 *new_infomask,
* We only use this in multis we just created, so they cannot be values
* pre-pg_upgrade.
*/
- nmembers = GetMultiXactIdMembers(multi, &members, false);
+ nmembers = GetMultiXactIdMembers(multi, &members, false, false);
for (i = 0; i < nmembers; i++)
{
@@ -5293,7 +5298,7 @@ MultiXactIdGetUpdateXid(TransactionId xmax, uint16 t_infomask)
* Since we know the LOCK_ONLY bit is not set, this cannot be a multi from
* pre-pg_upgrade.
*/
- nmembers = GetMultiXactIdMembers(xmax, &members, false);
+ nmembers = GetMultiXactIdMembers(xmax, &members, false, false);
if (nmembers > 0)
{
@@ -5376,7 +5381,8 @@ Do_MultiXactIdWait(MultiXactId multi, MultiXactStatus status,
int remain = 0;
allow_old = !(infomask & HEAP_LOCK_MASK) && HEAP_XMAX_IS_LOCKED_ONLY(infomask);
- nmembers = GetMultiXactIdMembers(multi, &members, allow_old);
+ nmembers = GetMultiXactIdMembers(multi, &members, allow_old,
+ HEAP_XMAX_IS_LOCKED_ONLY(infomask));
if (nmembers >= 0)
{
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index e3f5cbc..20b0ea2 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -391,7 +391,7 @@ MultiXactIdExpand(MultiXactId multi, TransactionId xid, MultiXactStatus status)
* caller of this function does a check that the multixact is no longer
* running.
*/
- nmembers = GetMultiXactIdMembers(multi, &members, false);
+ nmembers = GetMultiXactIdMembers(multi, &members, false, false);
if (nmembers < 0)
{
@@ -477,7 +477,7 @@ MultiXactIdExpand(MultiXactId multi, TransactionId xid, MultiXactStatus status)
* a pg_upgraded share-locked tuple.
*/
bool
-MultiXactIdIsRunning(MultiXactId multi)
+MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly)
{
MultiXactMember *members;
int nmembers;
@@ -489,7 +489,7 @@ MultiXactIdIsRunning(MultiXactId multi)
* "false" here means we assume our callers have checked that the given
* multi cannot possibly come from a pg_upgraded database.
*/
- nmembers = GetMultiXactIdMembers(multi, &members, false);
+ nmembers = GetMultiXactIdMembers(multi, &members, false, isLockOnly);
if (nmembers < 0)
{
@@ -1029,10 +1029,15 @@ GetNewMultiXactId(int nmembers, MultiXactOffset *offset)
* the value currently known as the next to assign, raise an error. Previously
* these also returned -1, but since this can lead to the wrong visibility
* results, it is dangerous to do that.
+ *
+ * onlyLock must be set to true if caller is certain that the given multi
+ * is used only to lock tuples; can be false without loss of correctness,
+ * but passing a true means we can return quickly without checking for
+ * old updates.
*/
int
GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
- bool allow_old)
+ bool allow_old, bool onlyLock)
{
int pageno;
int prev_pageno;
@@ -1066,6 +1071,19 @@ GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
MultiXactIdSetOldestVisible();
/*
+ * If we know the multi is used only for locking and not for updates,
+ * then we can skip checking if the value is older than our oldest
+ * visible multi. It cannot possibly still be running.
+ */
+ if (onlyLock &&
+ MultiXactIdPrecedes(multi, OldestVisibleMXactId[MyBackendId]))
+ {
+ debug_elog2(DEBUG2, "GetMembers: a locker-only multi is too old");
+ *members = NULL;
+ return -1;
+ }
+
+ /*
* We check known limits on MultiXact before resorting to the SLRU area.
*
* An ID older than MultiXactState->oldestMultiXactId cannot possibly be
@@ -2507,7 +2525,8 @@ pg_get_multixact_members(PG_FUNCTION_ARGS)
multi = palloc(sizeof(mxact));
/* no need to allow for old values here */
- multi->nmembers = GetMultiXactIdMembers(mxid, &multi->members, false);
+ multi->nmembers = GetMultiXactIdMembers(mxid, &multi->members, false,
+ false);
multi->iter = 0;
tupdesc = CreateTemplateTupleDesc(2, false);
diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c
index ed66c49..e0d627b 100644
--- a/src/backend/utils/time/tqual.c
+++ b/src/backend/utils/time/tqual.c
@@ -565,7 +565,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
*/
if ((tuple->t_infomask & (HEAP_XMAX_EXCL_LOCK |
HEAP_XMAX_KEYSHR_LOCK)) &&
- MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple)))
+ MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple), true))
return HeapTupleBeingUpdated;
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID, InvalidTransactionId);
@@ -575,7 +575,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
xmax = HeapTupleGetUpdateXid(tuple);
if (!TransactionIdIsValid(xmax))
{
- if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple)))
+ if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple), false))
return HeapTupleBeingUpdated;
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID, InvalidTransactionId);
@@ -590,7 +590,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
return HeapTupleInvisible; /* updated before scan started */
}
- if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple)))
+ if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple), false))
return HeapTupleBeingUpdated;
if (TransactionIdDidCommit(xmax))
@@ -1158,7 +1158,8 @@ HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin,
*/
if ((tuple->t_infomask & (HEAP_XMAX_EXCL_LOCK |
HEAP_XMAX_KEYSHR_LOCK)) &&
- MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple)))
+ MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple),
+ true))
return HEAPTUPLE_LIVE;
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID, InvalidTransactionId);
@@ -1185,7 +1186,7 @@ HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin,
{
TransactionId xmax;
- if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple)))
+ if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple), false))
{
/* already checked above */
Assert(!HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask));
diff --git a/src/include/access/multixact.h b/src/include/access/multixact.h
index 8a9edde..3572992 100644
--- a/src/include/access/multixact.h
+++ b/src/include/access/multixact.h
@@ -82,10 +82,10 @@ extern MultiXactId MultiXactIdCreate(TransactionId xid1,
extern MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid,
MultiXactStatus status);
extern MultiXactId ReadNextMultiXactId(void);
-extern bool MultiXactIdIsRunning(MultiXactId multi);
+extern bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly);
extern void MultiXactIdSetOldestMember(void);
extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **xids,
- bool allow_old);
+ bool allow_old, bool isLockOnly);
extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
extern void AtEOXact_MultiXact(void);
--
1.7.10.4
0002-Cope-with-heap_fetch-failure-while-locking-an-update.patch (text/x-diff, 1.5K) download
From 2d227750252da8e66849525f7ca5879cd2e0cb7d Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Wed, 27 Nov 2013 17:45:25 -0300
Subject: [PATCH 2/5] Cope with heap_fetch failure while locking an update
chain
The reason for the fetch failure is that the tuple was removed because
it was dead; so the failure is innocuous and can be ignored. Moreover,
there's no need for further work and we can return success to the caller
immediately. EvalPlanQualFetch is doing something very similar to this
already.
Report and test case from Andres Freund in
20131124000203.GA4403@alap2.anarazel.de
---
src/backend/access/heap/heapam.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 32ef453..6d7cd0c 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -4829,7 +4829,16 @@ heap_lock_updated_tuple_rec(Relation rel, ItemPointer tid, TransactionId xid,
ItemPointerCopy(&tupid, &(mytup.t_self));
if (!heap_fetch(rel, SnapshotAny, &mytup, &buf, false, NULL))
- elog(ERROR, "unable to fetch updated version of tuple");
+ {
+ /*
+ * if we fail to find the updated version of the tuple, it's
+ * because it was vacuumed/pruned away after its creator
+ * transaction aborted. So behave as if we got to the end of the
+ * chain, and there's no further tuple to lock: return success to
+ * caller.
+ */
+ return HeapTupleMayBeUpdated;
+ }
l4:
CHECK_FOR_INTERRUPTS();
--
1.7.10.4
0003-Don-t-try-to-set-InvalidXid-as-page-pruning-hint.patch (text/x-diff, 2.0K) download
From 8ce864afd98bc669db856d7c75f0177981a46fd6 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Wed, 27 Nov 2013 17:47:16 -0300
Subject: [PATCH 3/5] Don't try to set InvalidXid as page pruning hint
If a transaction updates/deletes a tuple just before aborting, and a
concurrent transaction tries to prune the page concurrently, the pruner
may see HeapTupleSatisfiesVacuum return HEAPTUPLE_DELETE_IN_PROGRESS,
but a later call to HeapTupleGetUpdateXid() return InvalidXid. This
would cause an assertion failure in development builds, but would be
otherwise Mostly Harmless.
Fix by checking whether the updater Xid is valid before trying to apply
it as page prune point.
Reported by Andres in 20131124000203.GA4403@alap2.anarazel.de
---
src/backend/access/heap/pruneheap.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c
index 3ec10a0..fdfa37c 100644
--- a/src/backend/access/heap/pruneheap.c
+++ b/src/backend/access/heap/pruneheap.c
@@ -479,13 +479,22 @@ heap_prune_chain(Relation relation, Buffer buffer, OffsetNumber rootoffnum,
break;
case HEAPTUPLE_DELETE_IN_PROGRESS:
+ {
+ TransactionId xmax;
+
+ /*
+ * This tuple may soon become DEAD. Update the hint field
+ * so that the page is reconsidered for pruning in future.
+ * If there was a MultiXactId updater, and it aborted after
+ * HTSV checked, then we will get an invalid Xid here.
+ * There is no need for future pruning of the page in that
+ * case, so skip it.
+ */
+ xmax = HeapTupleHeaderGetUpdateXid(htup);
+ if (TransactionIdIsValid(xmax))
+ heap_prune_record_prunable(prstate, xmax);
+ }
- /*
- * This tuple may soon become DEAD. Update the hint field so
- * that the page is reconsidered for pruning in future.
- */
- heap_prune_record_prunable(prstate,
- HeapTupleHeaderGetUpdateXid(htup));
break;
case HEAPTUPLE_LIVE:
--
1.7.10.4
0004-Compare-Xmin-to-previous-Xmax-when-locking-an-update.patch (text/x-diff, 1.9K) download
From 793296739bd38e6166510311b9134e0da7db6e74 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Wed, 27 Nov 2013 17:49:12 -0300
Subject: [PATCH 4/5] Compare Xmin to previous Xmax when locking an update
chain
Not doing so causes us to traverse an update chain that has been broken
by concurrent page pruning. All other code that traverses update chains
uses this check as one of the cases in which to stop iterating, so
replicate it here too. Failure to do so leads to erroneous CLOG,
subtrans or multixact lookups.
Per bug report by J Smith in
CADFUPgc5bmtv-yg9znxV-vcfkb+JPRqs7m2OesQXaM_4Z1JpdQ@mail.gmail.com
diagnosed by Andres Freund.
---
src/backend/access/heap/heapam.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 6d7cd0c..f70e1f7 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -4819,6 +4819,7 @@ heap_lock_updated_tuple_rec(Relation rel, ItemPointer tid, TransactionId xid,
old_infomask;
TransactionId xmax,
new_xmax;
+ TransactionId priorXmax = InvalidTransactionId;
ItemPointerCopy(tid, &tupid);
@@ -4844,6 +4845,18 @@ l4:
CHECK_FOR_INTERRUPTS();
LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
+ /*
+ * Check the tuple XMIN against prior XMAX, if any. If we reached
+ * the end of the chain, we're done, so return success.
+ */
+ if (TransactionIdIsValid(priorXmax) &&
+ !TransactionIdEquals(HeapTupleHeaderGetXmin(mytup.t_data),
+ priorXmax))
+ {
+ UnlockReleaseBuffer(buf);
+ return HeapTupleMayBeUpdated;
+ }
+
old_infomask = mytup.t_data->t_infomask;
xmax = HeapTupleHeaderGetRawXmax(mytup.t_data);
@@ -4944,6 +4957,7 @@ l4:
}
/* tail recursion */
+ priorXmax = HeapTupleHeaderGetUpdateXid(mytup.t_data);
ItemPointerCopy(&(mytup.t_data->t_ctid), &tupid);
UnlockReleaseBuffer(buf);
}
--
1.7.10.4
0005-Use-a-more-granular-approach-to-follow-update-chains.patch (text/x-diff, 7.7K) download
From 447b5325503fca11a413240c15dc1d837d9d8151 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Wed, 27 Nov 2013 17:50:33 -0300
Subject: [PATCH 5/5] Use a more granular approach to follow update chains
Instead of simply checking the KEYS_UPDATED bit, we need to check
whether each lock held on the future version of the tuple conflicts with
the lock we're trying to acquire.
Per bug report #8434 by Tomonari Katsumata
---
src/backend/access/heap/heapam.c | 202 ++++++++++++++++++++++++++++++++------
1 file changed, 171 insertions(+), 31 deletions(-)
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index f70e1f7..6802cbb 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -4799,6 +4799,83 @@ l5:
*result_xmax = new_xmax;
}
+/*
+ * Subroutine for heap_lock_updated_tuple_rec.
+ *
+ * Given an hypothetical multixact status held by the transaction identified
+ * with the given xid, does the current transaction need to wait, fail, or can
+ * it continue if it wanted to acquire a lock of the given mode? "needwait"
+ * is set to true if waiting is necessary; if it can continue, then
+ * HeapTupleMayBeUpdated is returned. In case of a conflict, a different
+ * HeapTupleSatisfiesUpdate return code is returned.
+ *
+ * The held status is said to be hypothetical because it might correspond to a
+ * lock held by a single Xid, i.e. not a real MultiXactId; we express it this
+ * way for simplicity of API.
+ */
+static HTSU_Result
+test_lockmode_for_conflict(MultiXactStatus status, TransactionId xid,
+ LockTupleMode mode, bool *needwait)
+{
+ MultiXactStatus wantedstatus;
+
+ *needwait = false;
+ wantedstatus = get_mxact_status_for_lock(mode, false);
+
+ /*
+ * Note: we *must* check TransactionIdIsInProgress before
+ * TransactionIdDidAbort/Commit; see comment at top of tqual.c for an
+ * explanation.
+ */
+ if (TransactionIdIsCurrentTransactionId(xid))
+ {
+ /*
+ * Updated by our own transaction? Just return failure. This shouldn't
+ * normally happen.
+ */
+ return HeapTupleSelfUpdated;
+ }
+ else if (TransactionIdIsInProgress(xid))
+ {
+ /*
+ * If the locking transaction is running, what we do depends on whether
+ * the lock modes conflict: if they do, then we must wait for it to
+ * finish; otherwise we can fall through to lock this tuple version
+ * without waiting.
+ */
+ if (DoLockModesConflict(LOCKMODE_from_mxstatus(status),
+ LOCKMODE_from_mxstatus(wantedstatus)))
+ {
+ *needwait = true;
+ }
+
+ /*
+ * If we set needwait above, then this value doesn't matter; otherwise,
+ * this value signals to caller that it's okay to proceed.
+ */
+ return HeapTupleMayBeUpdated;
+ }
+ else if (TransactionIdDidAbort(xid))
+ return HeapTupleMayBeUpdated;
+ else if (TransactionIdDidCommit(xid))
+ {
+ /*
+ * If the updating transaction committed, what we do depends on whether
+ * the lock modes conflict: if they do, then we must report error to
+ * caller. But if they don't, we can fall through to lock it.
+ */
+ if (DoLockModesConflict(LOCKMODE_from_mxstatus(status),
+ LOCKMODE_from_mxstatus(wantedstatus)))
+ /* bummer */
+ return HeapTupleUpdated;
+
+ return HeapTupleMayBeUpdated;
+ }
+
+ /* Not in progress, not aborted, not committed -- must have crashed */
+ return HeapTupleMayBeUpdated;
+}
+
/*
* Recursive part of heap_lock_updated_tuple
@@ -4816,7 +4893,8 @@ heap_lock_updated_tuple_rec(Relation rel, ItemPointer tid, TransactionId xid,
Buffer buf;
uint16 new_infomask,
new_infomask2,
- old_infomask;
+ old_infomask,
+ old_infomask2;
TransactionId xmax,
new_xmax;
TransactionId priorXmax = InvalidTransactionId;
@@ -4858,45 +4936,107 @@ l4:
}
old_infomask = mytup.t_data->t_infomask;
+ old_infomask2 = mytup.t_data->t_infomask2;
xmax = HeapTupleHeaderGetRawXmax(mytup.t_data);
/*
- * If this tuple is updated and the key has been modified (or
- * deleted), what we do depends on the status of the updating
- * transaction: if it's live, we sleep until it finishes; if it has
- * committed, we have to fail (i.e. return HeapTupleUpdated); if it
- * aborted, we ignore it. For updates that didn't touch the key, we
- * can just plough ahead.
+ * If this tuple version has been updated or locked by some concurrent
+ * transaction(s), what we do depends on whether our lock mode
+ * conflicts with what those other transactions hold, and also on the
+ * status of them.
*/
- if (!(old_infomask & HEAP_XMAX_INVALID) &&
- (mytup.t_data->t_infomask2 & HEAP_KEYS_UPDATED))
+ if (!(old_infomask & HEAP_XMAX_INVALID))
{
- TransactionId update_xid;
+ TransactionId rawxmax;
+ bool needwait;
- /*
- * Note: we *must* check TransactionIdIsInProgress before
- * TransactionIdDidAbort/Commit; see comment at top of tqual.c for
- * an explanation.
- */
- update_xid = HeapTupleHeaderGetUpdateXid(mytup.t_data);
- if (TransactionIdIsCurrentTransactionId(update_xid))
+ rawxmax = HeapTupleHeaderGetRawXmax(mytup.t_data);
+ if (old_infomask & HEAP_XMAX_IS_MULTI)
{
- UnlockReleaseBuffer(buf);
- return HeapTupleSelfUpdated;
- }
- else if (TransactionIdIsInProgress(update_xid))
- {
- LockBuffer(buf, BUFFER_LOCK_UNLOCK);
- /* No LockTupleTuplock here -- see heap_lock_updated_tuple */
- XactLockTableWait(update_xid);
- goto l4;
+ int nmembers;
+ int i;
+ MultiXactMember *members;
+
+ nmembers = GetMultiXactIdMembers(rawxmax, &members, false, false);
+ for (i = 0; i < nmembers; i++)
+ {
+ HTSU_Result res;
+
+ res = test_lockmode_for_conflict(members[i].status,
+ members[i].xid,
+ mode, &needwait);
+
+ if (needwait)
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ XactLockTableWait(members[i].xid);
+ pfree(members);
+ goto l4;
+ }
+ if (res != HeapTupleMayBeUpdated)
+ {
+ UnlockReleaseBuffer(buf);
+ pfree(members);
+ return res;
+ }
+ }
+ if (members)
+ pfree(members);
}
- else if (TransactionIdDidAbort(update_xid))
- ; /* okay to proceed */
- else if (TransactionIdDidCommit(update_xid))
+ else
{
- UnlockReleaseBuffer(buf);
- return HeapTupleUpdated;
+ HTSU_Result res;
+ MultiXactStatus status;
+
+ /*
+ * For a non-multi Xmax, we first need to compute the
+ * corresponding MultiXactStatus by using the infomask bits.
+ */
+ if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask))
+ {
+ if (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask))
+ status = MultiXactStatusForKeyShare;
+ else if (HEAP_XMAX_IS_SHR_LOCKED(old_infomask))
+ status = MultiXactStatusForShare;
+ else if (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))
+ {
+ if (old_infomask2 & HEAP_KEYS_UPDATED)
+ status = MultiXactStatusForUpdate;
+ else
+ status = MultiXactStatusForNoKeyUpdate;
+ }
+ else
+ {
+ /*
+ * LOCK_ONLY present alone (a pg_upgraded tuple
+ * marked as share-locked in the old cluster) shouldn't
+ * be seen in the middle of an update chain.
+ */
+ elog(ERROR, "invalid lock status in tuple");
+ }
+ }
+ else
+ {
+ /* it's an update, but which kind? */
+ if (old_infomask2 & HEAP_KEYS_UPDATED)
+ status = MultiXactStatusUpdate;
+ else
+ status = MultiXactStatusNoKeyUpdate;
+ }
+
+ res = test_lockmode_for_conflict(status, rawxmax, mode,
+ &needwait);
+ if (needwait)
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ XactLockTableWait(rawxmax);
+ goto l4;
+ }
+ if (res != HeapTupleMayBeUpdated)
+ {
+ UnlockReleaseBuffer(buf);
+ return res;
+ }
}
}
--
1.7.10.4
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-11-29 04:32 Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 11+ messages in thread
From: Tomonari Katsumata @ 2013-11-29 04:32 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
Hi Alvaro,
>> do you have another patch?
>
> Sorry, yes. This is the complete series of patches, although I have not
> tried them against 9.3 yet.
>
Thank you.
I could apply them against 93_STABLE and build it.
(commitID: d32e8387bac15ad353029c259e832f78d456c7a8)
deadlock did not occur with my test case.
It seems these patches resolve my problem.
If it doesn't have any other problems,
would you commit them for next release(9.3.2)?
FYI:
These patch doesn't resolve bug#8470 yet.
I could reproduce the problem on patched PostgreSQL.
regards,
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: BUG #8434: Why does dead lock occur many times ?
@ 2013-11-29 12:47 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
0 siblings, 0 replies; 11+ messages in thread
From: Alvaro Herrera @ 2013-11-29 12:47 UTC (permalink / raw)
To: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>; +Cc: pgsql-bugs
Tomonari Katsumata wrote:
> Hi Alvaro,
>
> >> do you have another patch?
> >
> > Sorry, yes. This is the complete series of patches, although I have not
> > tried them against 9.3 yet.
> >
> Thank you.
> I could apply them against 93_STABLE and build it.
> (commitID: d32e8387bac15ad353029c259e832f78d456c7a8)
>
> deadlock did not occur with my test case.
> It seems these patches resolve my problem.
>
> If it doesn't have any other problems,
> would you commit them for next release(9.3.2)?
Yes, it's already committed for 9.3.2. There are a bunch of other fixes
related to multixact which I intend to commit soon too.
> FYI:
> These patch doesn't resolve bug#8470 yet.
> I could reproduce the problem on patched PostgreSQL.
Yeah, I tested that too, but that problem is not related. I also tested
it with the fix to another performance problem which I posted as
http://www.postgresql.org/message-id/20131127222435.GC5513@eldon.alvh.no-ip.org
but that's not it either. It really requires a completely separate
optimization.
Thanks,
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 11+ messages in thread
end of thread, other threads:[~2013-11-29 12:47 UTC | newest]
Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-09-04 09:14 BUG #8434: Why does dead lock occur many times ? katsumata.tomonari@po.ntts.co.jp
2013-09-19 11:52 ` OTSUKA Kenji <otsuka.knj@gmail.com>
2013-09-28 01:39 ` Tomonari Katsumata <t.katsumata1122@gmail.com>
2013-09-28 01:47 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-04 17:22 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-11-27 16:42 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-11-28 00:52 ` Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
2013-11-28 04:00 ` Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
2013-11-28 11:22 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-11-29 04:32 ` Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
2013-11-29 12:47 ` Alvaro Herrera <alvherre@2ndquadrant.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox