Skip to content

Supabase and PostgresDatabase and Postgresreference

Postgres lock queue behind ACCESS EXCLUSIVE, lock_timeout and PgBouncer

An ALTER TABLE needs an ACCESS EXCLUSIVE lock, which conflicts with every other lock mode, including the ACCESS SHARE that a SELECT takes.1 The migration therefore waits for every reader that is already running, and Postgres puts the waiting request in the lock’s queue, where requests that conflict with it are granted in order of arrival.2 This page measures what that queue does to the readers behind it, to PostgREST and to a transaction-mode PgBouncer, what lock_timeout bounds when a migration has several statements, whether the stack recovers by itself afterwards, and which migration shape keeps the damage small.

TL;DR

  • A reader holding ACCESS SHARE blocked nobody: in the 5 s blocker-only window every request answered 200 in all three hold20 repetitions. Once the ALTER was waiting behind it, every later reader on both paths queued, with 0 answers per second ended inside the 20 s wait (LQ02).
  • Both PgBouncer pools of 10 filled within a second: cl_waiting 10 and sv_active 10 for both login roles, maxwait up to 19 s, and 21 Postgres backends waiting for the lock (the ALTER plus 10 per role). PostgREST answered 504 PGRST003 after its 10 s pool acquisition timeout, 181 to 182 times in the 20 s wait; the first 504 came 11 to 11.1 s after the ALTER started (LQ02).
  • Everything answered again within about a second of the commit: requests sent in the second the ALTER committed had a p95 of 295 ms (PostgREST) and 5 ms (the role path), and none of the 600 PostgREST and 300 role requests sent after the end failed (LQ02).
  • lock_timeout T limits each statement’s wait for its lock, not the migration. In a transaction of K ALTER statements on K tables, the first table’s lock is held to the end, so readers of the first table were blocked about K x T: 5,100 ms at K = 3, T = 2,000 ms, with waits staged at 0.85 T and no timeout firing (LQ01).
  • A 250 ms lock_timeout with a retry loop committed about when one shot did (5, 3 and 1 s against 5, 2.5 and 1 s) and held the readers’ longest latency to 222, 212 and 217 ms on PostgREST against 4,963, 2,480 and 960 ms for the one shot (LQ04).
  • No wedge reproduced: every arm recovered with no restart. The longest lingering failure was PostgREST’s 503 PGRST002 for 12.3 to 12.7 s after the lock cleared, with PgBouncer’s query_timeout at 5 s and Postgres at max_connections 40 (LQ03).
  • SET lock_timeout outside a transaction through a transaction-mode pool with one server connection reached the next client (3 of 3 read 1234ms); SET LOCAL did not (3 of 3 read 0) (LQ04).
Long readerACCESS SHARE, blocks nobodyALTER TABLE waitsfor ACCESS EXCLUSIVEEvery later reader queuesbehind the ALTERPgBouncer pools fillcl_waiting 10, sv_active 10PostgREST pool waits 10 s,then 504 PGRST003Reader ends, ALTER commits,queue drains in about 1 s

The same chain as text:

  1. A long reader holds ACCESS SHARE and blocks nobody.
  2. The ALTER asks for ACCESS EXCLUSIVE and waits for the reader.
  3. Every later reader conflicts with the waiting request and queues behind it.
  4. The PgBouncer pools fill with queued readers, 10 per login role.
  5. PostgREST waits 10 s for a pool connection, then answers 504 PGRST003.
  6. When the reader ends the ALTER commits and the queue drains in about a second.
SituationChoiceWhy
A single-statement migration on a table that is read all the timeSET LOCAL lock_timeout of a few hundred milliseconds in a retry loop250 ms with retries held the longest reader stall to about the timeout; one shot stalled readers for the whole wait (LQ04)
A migration of K statements in one transactionSize the blocking as K x T, or split into one transaction per statementReaders of the first table waited 5,100 ms at K = 3, T = 2 s with no timeout firing (LQ01)
You cannot bound the waitPut a statement_timeout on the reader roles to bound how long one reader holds a connectionIt cut each reader after 3 s but the pools still saturated and PostgREST still returned PGRST003 (LQ02)
SET of a session setting through a transaction poolerSET LOCAL inside the transactionSET reached the next client on the same server connection 3 of 3 times (LQ04)
The pooler seems stuck after a lock clearedWait about 13 s before restartingEvery arm recovered with no restart; the slowest took 12.3 to 12.7 s (LQ03)

A migration of K ALTER TABLE ... ADD COLUMN statements in one transaction, each on its own table, with lock_timeout T. Per cell: Postgres 17.11 alone with no pooler and no load, K tables, K blockers (each an open transaction that read its table, so it holds ACCESS SHARE), K probe sessions (one per table, select count(*) every 20 ms), and the migration on its own connection. The stagger pattern releases blocker i at 0.85 x T x i after the migration starts, so statement i waits about 0.85 T and no timeout can fire; last does the same for blockers 1 to K-1 and never releases blocker K, so statement K times out. The 0.85 factor is this module’s choice, a margin of 15% of T against jitter. “Longest reader block” is the largest probe latency in the repetition, a lower bound when the probe loop itself stalled. Selected rows (the artifact has all 30 cells), three repetitions each:

VariantPatternKT msOutcomeMigration wall msLongest reader block on table 1, msOn table K, ms
session (SET)stagger12000committed x31704 / 1705 / 17031699 / 1694 / 16781699 / 1694 / 1678
sessionstagger22000committed x33406 / 3414 / 34213401 / 3395 / 33821695 / 1707 / 1694
sessionstagger32000committed x35104 / 5132 / 51045100 / 5113 / 50801695 / 1712 / 1670
local (SET LOCAL)stagger32000committed x35102 / 5112 / 51035082 / 5109 / 50681660 / 1705 / 1688
multi-lockstagger31000committed x32567 / 2554 / 25522542 / 2538 / 2527851 / 818 / 845
stmt (statement_timeout)stagger3100057014, committed, committed3150 / 2561 / 25553109 / 2546 / 25341397 / 854 / 804
multi-stmtstagger31000committed x32561 / 2554 / 25552551 / 2540 / 2543826 / 850 / 829
locallast2100055P03 x31856 / 1861 / 18541845 / 1853 / 1848984 / 987 / 989
locallast3200055P03 x35405 / 5406 / 54075384 / 5392 / 54041997 / 1977 / 1997
stmtlast3200057014 x35406 / 5409 / 54225389 / 5391 / 53501977 / 1992 / 2000
lt-lt-st (lock_timeout 1000, statement_timeout 3000)last1100055P03 x31007 / 1010 / 1005980 / 985 / 997980 / 985 / 997
lt-st-lt (statement_timeout 1000, lock_timeout 3000)last1100057014 x31077 / 1032 / 1488975 / 976 / 1316975 / 976 / 1316

Variants: session is SET lock_timeout then the statements one by one; local is BEGIN; SET LOCAL lock_timeout; ...; stmt is SET statement_timeout only; multi-lock and multi-stmt send one simple-query message begin; alter; alter; ...; commit after the SET.

  • Nothing in the stagger rows timed out, and readers of the first table were blocked about as long as the whole migration. K = 3, T = 2,000 ms committed after 5104 / 5132 / 5104 ms with SET and 5102 / 5112 / 5103 ms with SET LOCAL; the first table’s probe saw 5100 / 5113 / 5080 ms and 5082 / 5109 / 5068 ms. The last table’s readers saw 1695 / 1712 / 1670 ms. A lock_timeout of 2 s that never fired left readers of table 1 waiting about 2.5 times its value, and the figure grows with K.
  • When the last statement does time out, the readers of table 1 were blocked for almost the whole migration, not for T. K = 3, T = 2,000 ms, SET LOCAL: 55P03 after 5405 / 5406 / 5407 ms, readers of table 1 blocked 5384 / 5392 / 5404 ms, readers of table 3 blocked 1997 / 1977 / 1997 ms (the last statement’s own wait, against T = 2,000 ms).
  • statement_timeout without any lock_timeout behaves the same per statement and fails with SQLSTATE 57014 instead of 55P03. Sent as one simple-query message, K = 3 statements under a 1,000 ms statement_timeout committed after 2561 / 2554 / 2555 ms, so the timeout was not applied to the message as a whole, which matches the documented wording on server 17.11.3
  • lock_timeout sent as one multi-statement message behaved like the statement-by-statement SET LOCAL cells (K = 3, T = 1,000 ms: 2567 / 2554 / 2552 ms).
  • After COMMIT the session still read lock_timeout 1s or 2s where it had been set with SET (3 of 3 in each session cell) and 0 where it had been set with SET LOCAL (3 of 3 in each local cell).
  • With lock_timeout 1,000 ms and statement_timeout 3,000 ms the error was 55P03 after 1007 / 1010 / 1005 ms; with statement_timeout 1,000 ms and lock_timeout 3,000 ms it was 57014 after 1077 / 1032 / 1488 ms. The documentation says a lock_timeout equal to or above a nonzero statement_timeout is rather pointless.3

One cell failed: stmt stagger K = 3, T = 1,000 ms, repetition 1 ended in 57014 after 3150 ms where the cell expected a commit (repetitions 2 and 3 committed after 2561 and 2555 ms). Statement 3 started at about 1,704 ms, so its timeout was due at about 2,704 ms; its blocker was due to release at 2,550 ms, 154 ms earlier, and the error reached the client at 3,150 ms, 446 ms after the timeout was due. The reading, an inference not separated: the client process stalled, the release timer ran more than 154 ms late and the error was read late, on a host at load average 15 to 40. Other cells show smaller stalls of the same kind, for example local K = 1, T = 2,000 ms, repetitions 2 and 3 committing after 2,050 and 2,111 ms where 1,700 was expected. Not measured in LQ01: row-level locks, DDL (data definition language) other than ADD COLUMN, a statement that waits for locks on more than one object, a table rewrite, the hosted platform’s role settings, any pooler.

The queue behind a waiting ACCESS EXCLUSIVE (LQ02)

Section titled “The queue behind a waiting ACCESS EXCLUSIVE (LQ02)”

Timeline per arm, in seconds from the start of the load: load alone to 12; a blocker (select count(*), pg_sleep(25) from lq_items, ACCESS SHARE for 25 s) from 12; the ALTER (alter table lq_items add column, metadata only) at 17; the blocker ends at 37 and the ALTER commits then; 30 s of load after the ALTER ends. Arms: control (no blocker, no ALTER), hold20 (no lock_timeout, the ALTER waits 20 s), lt2s (SET LOCAL lock_timeout 2 s, the blocker keeps running), and hold20-st3 (as hold20, with statement_timeout 3 s on the roles anon and app_reader; anon 3 s is the hosted default recorded in the lab’s data-api-capacity DC03a). Three repetitions per figure, run B.

  • Blocker only. In the 5 s blocker-only window every request answered 200 in all three hold20 repetitions (PostgREST 200:101 x 3, PgBouncer role 200:51 x 3), and the same in the other arms.
  • With the ALTER waiting, readers queued on both paths. In hold20, 0 / 0 / 0 PostgREST answers per second and 0 / 0 / 0 PgBouncer-role answers per second ended inside the 20 s wait. PostgREST requests sent during the wait: 200:219 504 PGRST003:181, 200:218 504 PGRST003:182, 200:218 504 PGRST003:182. The 200s ended when the ALTER committed, after up to 19982 / 19989 / 19984 ms. The first 504 ended 11.1 / 11.1 / 11 s after the ALTER started (acquisition timeout 10 s). PgBouncer-role requests sent during the wait: 200:200 x 3, p50 9939 / 9944 / 9955 ms, longest 19933 / 19929 / 19935 ms; none failed, they waited. The control arm in the same run answered 200 for every request, longest 50 / 55 / 27 ms (PostgREST) and 19 / 27 / 18 ms (role).
  • PostgREST’s answer for a request that could not get a pool connection was HTTP (Hypertext Transfer Protocol) 504 with code PGRST003 and the message “Timed out acquiring connection from connection pool.” The v14 errors page lists PGRST003 as 504 and PGRST001 and PGRST002 as 503, so a pool timeout is a 504 on 14.18.4
  • Pool saturation in hold20: PgBouncer SHOW POOLS (1 s samples) read cl_waiting 10 / 10 / 10 and sv_active 10 / 10 / 10 for both login roles, maxwait up to 19 / 19 / 19 s (authenticator) and 18 / 18 / 18 s (app_reader); Postgres had 21 backends waiting for the lock in every repetition (the ALTER and 10 per role) of 22 client backends. PostgREST’s own gauge pgrst_db_pool_waiting read at most 5 / 3 / 4 while about 180 requests were waiting, so on this PostgREST it did not show the queue (in hold20-st3 it read 123 / 1 / 120).
  • Recovery with no restart: requests sent in the second the ALTER committed had a p95 of 295 ms (PostgREST) and 5 ms (role), and 6 ms and 3 ms in the next second. cl_waiting was 0 at 10 and 30 s, lock waiters 0, and no request failed among the 600 PostgREST and 300 role requests sent after the end. The 20 requests per path at the end all answered. The same held in the other arms and repetitions.
  • lt2s: the ALTER failed 55P03 after 2 s (alter_wall_s 2 x 3). Readers sent in those 2 s all answered 200, PostgREST p50 966 / 969 / 970 ms and longest 1957 / 1958 / 1977 ms, role longest 1907 / 1904 / 1905 ms, no errors. The pools still filled inside the 2 s (authenticator cl_waiting 10 / 10 / 10; app_reader 10 / 10 / 1), with 20 / 20 / 20 backends waiting for the lock. The blocker kept running to 37 s and readers were unaffected by it.
  • hold20-st3: with statement_timeout 3 s the readers holding a server connection were cancelled: 500 57014 60 x 3 on PostgREST and pg 57014 60 x 3 on the role path (message “canceling statement due to statement timeout”), the first one 3 / 3 / 3 s (PostgREST) and 3.1 s (role) after the ALTER started. The pools still saturated (cl_waiting 10 for both roles, 21 lock waiters), PostgREST still returned 504 PGRST003 137 / 137 / 138 times against 181 to 182 without the statement timeout, and requests waited up to 14908 / 14082 / 13324 ms (PostgREST) and 13930 / 13935 / 13930 ms (role). The reading, with the order of hand-over not traced: each cancelled statement frees a server connection that the next queued client takes and waits on in turn.

A lock_timeout of 2 s bounded the reader stall to 2 s; a statement_timeout on the reader roles bounded how long one reader holds a connection and did not stop the queue. This repeats on a local stack what the lab’s data-api-capacity experiment recorded on a managed project with a lock held by a session (DC18, 2026-10-27, managed Small at 500 requests a second and 4XL at 1,500, a 30 s ACCESS EXCLUSIVE lock: 0 successful responses a second for its first 25 s and recovery 44.9 s and 19.8 s after it ended, derived from the backlog).5 The differences are the cause (a waiting ALTER here, a held LOCK there), the pool sizes (10 and 20 here) and the rates (20 and 10 a second here), so the recovery times are not compared. The same page records a 12.6 s lock giving 60 x 500 57014 on anon reads and no aborted pooled connection (DC06); see Supabase Data API (application programming interface) connection pool and capacity.

Not measured in LQ02: writes through PostgREST, other lock modes, a waiting ALTER that is granted and then runs for seconds (ADD COLUMN here holds ACCESS EXCLUSIVE for milliseconds), pool sizes other than 20 and 10, and a hosted project.

Same stack, load and timeline as LQ02 with a 30 s ALTER wait (blocker 33 s), PgBouncer query_wait_timeout 10 s (SHOW CONFIG read back per arm), Postgres max_connections 40, and per-arm client behaviour. Nothing is restarted inside an arm; after the load stops each arm sends 20 requests per path through fresh connections and reads PgBouncer’s SHOW SERVERS and SHOW CLIENTS and the Postgres backend count. Arms: qwt10-patient (client timeout 60 s, 90 s of load after the ALTER), qwt10-impatient3s (client timeout 3 s: an HTTP request is aborted, a pool client destroys its connection with the query still running; 45 s after), qwt10-impatient3s-login1 (the same with server_login_retry 1 s, default 15), and qt5-patient (PgBouncer query_timeout 5 s, patient clients, 45 s after).6 Three repetitions each; “after” means requests sent after the ALTER ended.

ArmPostgREST during the waitPgBouncer-role path during the waitAfter the ALTER ended
qwt10-patient504 PGRST003 366 / 365 / 366, 503 PGRST001 17 / 19 / 19, 200 217 / 216 / 215; first error 10.5 / 10.9 / 10.9 s after the ALTER startedpg 08P01 query_wait_timeout 20 x 3, 200 280 x 3PostgREST 200:1800 x 3 and role 200:900 x 3: no failure
qwt10-impatient3stimeout 546 / 546 / 545, 200 54 / 54 / 55pg 53300 too many clients 257 / 257 / 247, timeout 43 / 43 / 53PostgREST no failure; role 53300 45 / 45 / 45 sent after, last 4.5 / 4.5 / 4.5 s after the end
qwt10-impatient3s-login1timeout 544 / 548 / 54653300 275 x 3, timeout 25 x 3PostgREST no failure; role 53300 9 / 1 / 8, last 0.9 / 0.1 / 0.8 s after the end
qt5-patient503 PGRST002 377 / 368 / 369, 503 PGRST001 219 / 229 / 226pg 53300 258 / 263 / 257, pg 08P01 query_timeout 26 / 22 / 28, pg 08P01 16 / 15 / 15PostgREST 503 PGRST002 246 / 254 / 253 sent after, last 12.3 / 12.7 / 12.6 s after the end; role 53300 59 / 60 / 58, last 5.9 / 6 / 5.8 s after
  • In every arm and repetition PgBouncer cl_waiting was 0 for both roles 10 s and 30 s after the ALTER ended, Postgres had 0 backends waiting for a lock, and the 20 final requests per path all answered (final_rest_ok_of_20 and final_pool_ok_of_20 are 20 in all 12 results). No arm needed a restart to answer again.
  • qwt10-patient: PgBouncer disconnected waiting clients after 10 s, 20 per role per repetition (log lines closing: query_wait_timeout 20 per role, matching pg 08P01 query_wait_timeout 20 on the role path); PostgREST’s PGRST001 (“Database client error. Retrying the connection.”) 17 to 19 times is the same cut-off seen from PostgREST’s pool.
  • Abandoned queries piled up on Postgres. Backends waiting for the lock peaked at 35 and total backends at 36 in all 6 impatient repetitions and in the 3 qt5-patient repetitions, where PgBouncer, not the client, gives up on the query (max_connections 40, 3 reserved for superusers), against 21 and 22 with patient clients (pool 10 per role plus the ALTER). In the impatient arm the surplus 14 is derived from 35 - 1 - 10 - 10 and fits PgBouncer’s log, 24 lines of closing: client disconnect while server was not ready in each of the 6 impatient repetitions: PgBouncer closes the server connection of an abandoned client and opens a replacement, and the abandoned query keeps waiting in Postgres. Its login errors then read server login has been failing, cached error: remaining connection slots are reserved for roles with the SUPERUSER attribute, 302 / 302 / 292 log lines in qwt10-impatient3s. After the lock cleared, backends read 11 at 10 s and 11 to 12 at 30 s in that arm (20 with patient clients, 2 and 3 in qt5-patient).
  • server_login_retry: with the default 15 s the role path kept failing 4.5 s after the ALTER ended in 3 of 3 (45 failed requests sent after, the same count each time); with 1 s it failed 0.1 to 0.9 s after in 3 of 3 (1 to 9 requests). PgBouncer’s log shows server login failed 2 / 2 / 2 times with the default and 25 / 24 / 25 times with 1 s during the arm. The lever moves the post-lock error window; why the default’s window is 4.5 s and not 15 s was not separated.
  • qt5-patient is the longest lingering failure: PostgREST kept answering 503 PGRST002 (“Could not query the database for the schema cache. Retrying.”) for 12.3 / 12.7 / 12.6 s after the ALTER ended, each answer within tens of milliseconds, then answered 200 with no action taken (all 20 requests a second failing until second 42, all ok from 43). The PostgREST connection-pool page says it “will retry forever with exponential backoff, with a maximum backoff time of 32 seconds between retries”.7 The reading, a hypothesis only: the schema-cache retry schedule spanned the end of the lock. PostgREST’s log (level error here), the retry times and db-channel-enabled true were not measured.

One result failed: LQ03-qwt10-impatient3s-login1-r1, “PgBouncer clients still waiting in the last 5 s”. Its samples read cl_waiting 0 for every second from 31 to 70 s, 1 at second 71 (authenticator, sv_active 1) and 0 at 72 to 74, with PostgREST’s per-second p95 at 790 ms in the same stretch and host load average 7.8 before and 12.7 after. The reading is a one-second host or harness stall that the end-of-run check caught, not state left behind. Recorded as a fail and not retried.

Wedge: not reproduced. Tried, all with no restart: a lock held 30 s against PgBouncer cutting waiting clients (query_wait_timeout 10 s); clients that abandon queries (3 s) so that Postgres reaches max_connections; PgBouncer’s own query_timeout 5 s against both paths with Postgres at max_connections; and the default server_login_retry 15 s against 1 s. The report that motivated the arm lasted until a restart; nothing here lasted past 12.7 s. Not tried: Supavisor (the hosted pooler’s code is not PgBouncer’s), a lock held for minutes, server_lifetime or server_idle_timeout changes, max_client_conn exhaustion, PgBouncer session mode, an application that retries failed requests, any hosted project.

A short lock_timeout with a retry loop (LQ04)

Section titled “A short lock_timeout with a retry loop (LQ04)”

Long readers (select count(*), pg_sleep(6) from lq_items, 2 s gap, so an ACCESS SHARE holder 75% of the time) run under the LQ02 load. The migration starts when the current long reader has run 1, 3.5 and 5 s (repetitions 1, 2 and 3: 5, 2.5 and 1 s still to go). The same three phases in every arm; the phases were chosen, not sampled.

ArmAttemptsTime to commit, sEach failed attempt waited, msLongest reader latency, PostgREST / role, msRequests slow (over 1.5 s) or failed in the window
oneshot1 / 1 / 15 / 2.5 / 1none; the one attempt waited 5008 / 2509 / 10064963 / 2480 / 960 and 4913 / 2413 / 910PostgREST 71 / 21 / 0, role 35 / 10 / 0
retry-250ms6 / 4 / 25 / 3 / 1251 to 252 (55P03)222 / 212 / 217 and 171 / 163 / 1650 / 0 / 0 on both paths
retry-1000ms3 / 2 / 25 / 2.5 / 21001 to 1007 (55P03)975 / 965 / 967 and 923 / 913 / 9150 / 0 / 0 on both paths
  • One shot stalled readers for the whole wait: PostgREST requests sent during it had p50 2507 / 1249 / 460 ms, none failed, and both PgBouncer pools filled (cl_waiting 10 / 10 / 9 for the authenticator role, 10 / 10 / 0 for the other).
  • The retry loop got the lock about when the long reader ended: 5 / 3 / 1 s (250 ms timeout) and 5 / 2.5 / 2 s (1,000 ms) after the first attempt, against the one shot’s 5 / 2.5 / 1 s. Readers’ longest latency stayed within about the timeout (222 ms against 250 ms; 975 ms against 1,000 ms) and readers kept being answered during the retry window (PostgREST rest_ok_ended_per_s_in_block 19.9 x 3 at 250 ms; 16 / 15.9 / 19.9 at 1,000 ms; the arrival rate is 20).
  • The 1,000 ms timeout filled the authenticator pool in repetitions 1 and 3 (cl_waiting max 10 and 9); the 250 ms timeout did not show waiting clients in the 1 s samples (0 x 3), which is not evidence that none waited, since a 250 ms wait can fall between two samples.
  • LQ04-set-leak (PgBouncer pool size 1 for the role, so two clients share one server connection): a client that ran SET lock_timeout = '1234ms' outside a transaction and disconnected left the next client reading 1234ms (3 of 3); after BEGIN; SET LOCAL lock_timeout = '1234ms'; COMMIT the next client read 0 (3 of 3). The PgBouncer documentation says server_reset_query is not used with transaction pooling.6
  • The retry loop cost nothing in time to commit beyond the next attempt boundary (repetition 2 of retry-250ms: 3 s against 2.5 s) and cut the readers’ longest stall from the long reader’s remainder (5, 2.5 and 1 s) to about the timeout. Each failed attempt is a 55P03 that the migration runner must treat as retryable.

Not measured in LQ04: jittered backoff, a loop with a total deadline, a long reader that does not end inside the attempt budget (40 attempts), DDL that needs a table rewrite, SET through Supavisor, and a hosted project.

  • Any hosted project, Supavisor, and the platform’s role settings. The 8 s lock_timeout and statement_timeout that the lab recorded on the hosted authenticator role were not set in this rig.
  • Writes through PostgREST, other lock modes, row-level locks, and DDL other than ADD COLUMN.
  • A lock held for minutes, other pool sizes than 10 per role and 20 in PostgREST, and PostgREST’s log and retry times during recovery.
  • Application-side retries of failed requests during the stall.
  • Latencies below a second sit inside host noise: load average 8.4 to 40.3 in run A and 1.5 to 13.7 in run B on the same 10-CPU VM. Each arm’s figures are read against its own run, not across runs.
  • “Longest reader block” and “longest latency” are the maxima over a repetition, so one stalled probe loop moves them; the failed LQ01 cell and the failed LQ03 result are those stalls, recorded as fails.
  • Request counts such as 504 PGRST003:181 are requests sent during the 20 s wait, by the open-loop generator at 20 a second; they scale with the rate, the wait and the 10 s acquisition timeout.
  • Three repetitions per arm; the phases in LQ04 were chosen, not sampled, so the retry arms are demonstrations of the shape rather than an estimate of its distribution.
PracticeEvidenceModule
Retry DDL under a short SET LOCAL lock_timeout250 ms with retries: readers’ longest latency 222, 212 and 217 ms against 4,963, 2,480 and 960 ms for one shot; 0 slow or failed requests against up to 71LQ04
Treat 55P03 from the migration as retryableEach failed attempt waited 251 to 252 ms and then failed 55P03; the loop committed about when the long reader endedLQ04
Budget K x T of blocking for a K-statement migration, or split itK = 3, T = 2,000 ms: readers of table 1 blocked 5,100 ms with no timeout firingLQ01
Use SET LOCAL, not SET, through a transaction poolerSET lock_timeout left 1234ms for the next client 3 of 3; SET LOCAL left 0 3 of 3LQ04, LQ01
Do not rely on a reader statement_timeout to protect the pools from a waiting ALTERIt cancelled 60 readers per path in 3 s and the pools still saturated: cl_waiting 10, 21 lock waiters, PGRST003 137 to 138LQ02
Look for the long reader behind the waiting ALTERA holder of ACCESS SHARE blocked nobody (every request 200 in the blocker-only window); once the ALTER queued, 0 answers per second ended inside the waitLQ02
Read PGRST003 after 10 s as a pool wait, not a database outage504 PGRST003 first appeared 11 to 11.1 s after the ALTER started, with acquisition timeout 10 sLQ02
Wait out about 13 s of PGRST002 after a lock clears before restarting the poolerqt5-patient: 12.3 to 12.7 s of 503 PGRST002, then 200 with no action; no arm needed a restartLQ03
Set client timeouts above the longest expected lock wait3 s client timeouts left 35 backends waiting of 36 and 53300 too many clients 257 / 257 / 247 on the role path, against 21 and 22 backends and no 53300 with patient clients (query_wait_timeout 10 s in both)LQ03
Lower server_login_retry to shorten the post-lock error window1 s ended the post-lock 53300 window 0.1 to 0.9 s after the lock against 4.5 s with the default 15 s, at 25 server login failed log lines against 2LQ03

The experiment is experiments/lock-queue in supabase-lab. It needs Docker, bun, and the three images (pinned by digest in lib/stack.ts).

make probe # all four modules, about 45 minutes, writes evidence/<ts>/
make probe ONLY=LQ01 # one module
LQ_TIME_SCALE=0.3 LQ_REPS=1 make probe ONLY=LQ02 # a smoke run of shortened phases
make facts # measurements of the newest run as markdown
ClaimStatusHow it was checked
lock_timeout bounds each statement; readers of table 1 blocked about K x Tmeasured, 30 cells x 3 repetitions, run A, one failed cellLQ01, run A facts
A waiting ALTER queues every later reader on PostgREST and PgBouncer; recovery within about 1 s of commitmeasured, 4 arms x 3 repetitions, run BLQ02, run B facts
No wedge; PostgREST PGRST002 for 12.3 to 12.7 s in the query_timeout armmeasured, 4 arms x 3 repetitions, one result failed on a host stall; the schema-cache retry reading is a hypothesisLQ03, run B facts
250 ms retry loop against one shot; SET leaks, SET LOCAL does notmeasured, 3 arms x 3 repetitions plus the leak probe; the phases were chosenLQ04, run B facts
Waiting requests join a queue and conflicting requests are granted in order of arrival; ACCESS EXCLUSIVE is the only mode that blocks a plain SELECTdocumented21doc-read 2026-12-03 and again for this page; the lock manager README at REL_17_STABLE
lock_timeout applies to each lock acquisition attempt; statement_timeout applies to each statement of a simple-query messagedocumented3; consistent with LQ01doc-read 2026-12-03 and again for this page
The hosted pooler’s behaviournot measuredSupavisor not in the rig

No docs-versus-runtime disagreement was found, so nothing was filed upstream.

ModuleExperimentTestArtifact
LQ01lock-queuelq01-lock-timeout.tsrun-2026-12-03T06-14-25-696Z
LQ02lock-queuelq02-queue-behind.tsrun-2026-12-03T07-02-34-708Z
LQ03lock-queuelq03-pooler-recovery.tsrun-2026-12-03T07-02-34-708Z
LQ04lock-queuelq04-safe-migration.tsrun-2026-12-03T07-02-34-708Z
DC18 (cited, not run here)data-api-capacitynot re-read for this pageRUNLOG
  1. PostgreSQL Global Development Group, “Explicit Locking,” PostgreSQL 17 Documentation. https://www.postgresql.org/docs/17/explicit-locking.html ↩ ↩2

  2. PostgreSQL Global Development Group, “src/backend/storage/lmgr/README,” postgres/postgres, tag REL_17_STABLE. https://github.com/postgres/postgres/blob/REL_17_STABLE/src/backend/storage/lmgr/README ↩ ↩2

  3. PostgreSQL Global Development Group, “Client Connection Defaults,” PostgreSQL 17 Documentation, lock_timeout and statement_timeout. https://www.postgresql.org/docs/17/runtime-config-client.html ↩ ↩2 ↩3

  4. PostgREST, “Errors,” PostgREST v14 Documentation. https://docs.postgrest.org/en/v14/references/errors.html ↩

  5. erfianugrah, “supabase-lab, data-api-capacity RUNLOG (DC18, 2026-10-27),” GitHub, commit aa4ccf8e. https://github.com/erfianugrah/supabase-lab/blob/aa4ccf8e1f5d57b306173bb976e2575da1db429f/experiments/data-api-capacity/RUNLOG.md ↩

  6. PgBouncer, “Configuration,” PgBouncer documentation, query_wait_timeout, query_timeout, server_login_retry and server_reset_query. https://www.pgbouncer.org/config.html ↩ ↩2

  7. PostgREST, “Connection Pool,” PostgREST v14 Documentation. https://docs.postgrest.org/en/v14/references/connection_pool.html ↩