# The PostgreSQL update waiting on a lock

The database accepts connections, but the application update times out. Find
the blocking transaction and restore access to the synthetic inventory row
without changing its data or granting broader privileges.

## Before you begin

Use a disposable machine with Bash, Python 3, Docker and Docker Compose.
The lab creates `breakfix-dbops-03`, an internal Docker network and a named
database volume. It publishes no host ports and creates no cloud resources.
Docker may download PostgreSQL 17. Authentication is intentionally insecure;
never use these settings or this project name for real workloads. Other users
with Docker access can reach the lab database.

Setup refuses existing project resources. Teardown checks container
ownership before deleting this lab's containers, network and database volume.
The synthetic blocking transaction sleeps for up to one hour.

## Investigate

```sh
./setup.sh
docker compose -p breakfix-dbops-03 ps
docker compose -p breakfix-dbops-03 exec db psql -X -U lab_admin -d lab
```

In the lab database, inspect `pg_stat_activity`, `pg_locks` and the
`inventory` table. Compare the blocking session with the application role
`lab_writer`. Investigate the timeout using a short `lock_timeout`; do not
change the table or disable the application. This lab's blocker is disposable;
in production, identify the owner and transaction impact before terminating a
session.

After recovery, run `./verify.sh` and `./teardown.sh`. Verification checks
the original rows and performs a bounded update as `lab_writer` in a
rolled-back transaction. Teardown deletes the synthetic database volume.
