21

In postgres log:

2016-12-23 15:28:14 +07 [17281-351 trns: 4280939, vtrns: 3/20] postgres@deadlocks HINT:  See server log for query details.
2016-12-23 15:28:14 +07 [17281-352 trns: 4280939, vtrns: 3/20] postgres@deadlocks CONTEXT:  while locking tuple (0,79) in relation "account"
2016-12-23 15:28:14 +07 [17281-353 trns: 4280939, vtrns: 3/20] postgres@deadlocks STATEMENT:  SELECT id FROM account where id=$1 for update;

when I provoke a deadlock I can see text: tuple (0,79).

As I know, a tuple just is several rows in table. But I don't understand what (0,79) means. I have only 2 rows in table account, it's just play and self-learning application.

So what does (0,79) means?

Hayate
  • 653
  • 1
  • 9
  • 25
  • 2
    A tuple is a **single** row consisting of several columns. A table with two rows has two tuples. –  Dec 23 '16 at 11:05

1 Answers1

17

This is the data type of the system column ctid. A tuple ID is a pair (block number, tuple index within block) that identifies the physical location of the row within its table.

read https://www.postgresql.org/docs/current/static/datatype-oid.html

It means block number 0, row index 79

also read http://rachbelaid.com/introduction-to-postgres-physical-storage/

also run SELECT id,ctid FROM account where id=$1 with right $1 to check out...

Vao Tsun
  • 47,234
  • 13
  • 100
  • 132
  • 1
    Yep, found this in postgres sources: https://github.com/postgres/postgres/blob/55c3391d1e6a201b5b891781d21fe682a8c64fe6/src/backend/storage/lmgr/lmgr.c#L725 – Hayate Dec 23 '16 at 10:52