Notice Configuration

No Lock Timeout

No lock_timeout is configured, meaning queries can wait indefinitely for locks instead of failing fast.

What is this issue?

The lock_timeout setting specifies how long to wait for a lock before
giving up. Without a timeout:

- Queries wait forever for locked resources
- DDL operations (ALTER TABLE) block until locks are available
- Blocking chains pile up waiting sessions
- Application threads are tied up waiting

A lock_timeout allows "fail fast" behavior where blocked operations
error immediately, allowing the application to retry or handle gracefully.

Why it matters

Cascading Blocks

Waiting queries pile up, exhausting connections

Application Hangs

Threads/processes stuck waiting for locks

DDL Risk

Schema changes can wait hours for locks

Poor User Experience

Users see hanging requests instead of errors

How PG Pilot detects it

```sql
SELECT name, setting, unit
FROM pg_settings
WHERE name = 'lock_timeout';
```

How to fix it

1

Set a reasonable default

30 seconds to 1 minute is common:

ALTER SYSTEM SET lock_timeout = '30s';
SELECT pg_reload_conf();
2

Use shorter timeouts for DDL

Fail fast for schema changes:

SET lock_timeout = '5s';
ALTER TABLE users ADD COLUMN new_col text;
RESET lock_timeout;
3

Application retry logic

Handle lock timeouts gracefully:

begin
  execute_query
rescue ActiveRecord::LockWaitTimeout
  sleep(rand * 2)
  retry
end

Prevention

  • Set a default lock_timeout
  • Use short timeouts for DDL
  • Implement retry logic in applications
  • Monitor blocking with PG Pilot

Related Issues

Related Features

PostgreSQL Documentation