How PostgreSQL 14.9 Handles Partitioned Index Validation
In PostgreSQL, a partitioned table stores its rows in separate tables called partitions. A partitioned index is a parent index that represents…
If PostgreSQL crashes while a query runs SELECT ... FOR UPDATE, check the server version first. PostgreSQL 9.1.15 fixed a specific crash bug that happened during concurrent updates under the READ COMMITTED isolation level. That old defect does not mean SELECT FOR UPDATE is prone to crashing, and it does not explain every crash that happens during row locking.
READ COMMITTED is PostgreSQL’s default transaction isolation level. Under this level, each command sees data that other transactions committed before the command started. When a locking query waits for another transaction to update a row, PostgreSQL may need to check the updated row again once the lock clears. PostgreSQL 9.1.15 fixed a memory error that occurred during that recheck. If your server runs PostgreSQL 9.1, you should migrate to a supported major version. If your server runs a different version, check the logs and crash evidence before blaming this old bug.
The PostgreSQL 9.1.15 release notes describe a use-after-free bug during EvalPlanQual processing. A use-after-free happens when software tries to access memory it has already released. EvalPlanQual is how PostgreSQL rechecks a row after a concurrent transaction changes it while another query is waiting.
According to the notes, queries that locked or updated rows recently changed by another transaction could crash under READ COMMITTED. The notes do not include a minimal reproducer or point to one specific query shape that triggers the bug. If one of your transactions was waiting for a row lock when the server crashed, that detail is worth noting, but a similar wait or crash alone does not prove this bug caused it.
For example, Session A might update a row and leave its transaction open:
-- Session A
BEGIN;
UPDATE inventory
SET quantity = quantity - 1
WHERE id = 42;
While Session A stays open, Session B requests a lock on the same row:
-- Session B
SELECT *
FROM inventory
WHERE id = 42
FOR UPDATE;
Session B waits for Session A to finish. If Session A commits, PostgreSQL may need to read the newer row version and recheck the query condition. This example shows the concurrency path involved in the historical fix, though it is not a reproducer for the defect itself.
The same 9.1.15 notes list two separate SELECT FOR UPDATE issues that returned wrong results when a query scanned a table and its inherited child tables. One involved partial indexes - indexes that cover only rows matching a condition - on child tables. The other could return a row twice while skipping other rows. Those result-handling bugs were separate from the use-after-free crash.
If you see “9.3” on the documentation page, that number refers to the manual version. PostgreSQL 9.1.15 is the release that contained the fix.
A slow SELECT FOR UPDATE does not necessarily mean you have hit a bug. PostgreSQL makes your query wait when another transaction holds a row lock that blocks it. Deadlocks work differently. When transactions wait on each other in a cycle, PostgreSQL detects the circular wait and aborts one transaction so the others can move forward. Neither a lock wait nor a deadlock is a backend process crash. You can read how PostgreSQL handles these cases in the row-locking and deadlock documentation.
Start by checking your exact server version:
SELECT version();
Next, figure out what actually happened. If the query is still running, find which transaction holds the lock and how long it has been open. If PostgreSQL returned an error and aborted the transaction, record the error message and the surrounding transaction details. If a database connection dropped unexpectedly or a server process restarted, check PostgreSQL’s server log along with any crash report from your operating system or service manager.
If you suspect a crash, save the SQL statement, the transaction’s isolation level, the log entries from around the incident, and whether another session was updating or locking the same row. You can use these details to tell the 9.1.15 defect apart from other causes. The release notes also list unrelated crash fixes, so a crash on a 9.1.15 server does not automatically mean row locking caused it.
If your server runs a PostgreSQL 9.1 release earlier than 9.1.15, it lacks this fix. Even though PostgreSQL 9.1.15 patched the crash, you should not stop at 9.1.15. PostgreSQL 9.1 is unsupported, and its final release was 9.1.24. The 9.1.24 release notes include additional fixes, and the project’s 9.1 security status confirms that 9.1 no longer receives security patches. Plan a migration to a supported major version and follow the upgrade instructions for your target release.
According to the 9.1.15 notes, you did not need to dump and restore your database when updating from one 9.1 release to another. That only applies within the 9.1 series. When you move to a new major version, you need a separate upgrade plan.
If your server runs a different major version, do not treat the 9.1.15 fix as your diagnosis. Confirm the version you have deployed, check its official release notes and support status, and investigate the incident evidence. PostgreSQL’s versioning policy explains how long the project supports each major version and recommends running the latest minor release for a supported major version.
Keep transactions that acquire row locks short. Commit or roll back promptly, and avoid holding a transaction open while your application waits for user input or slow external work. When your code locks several rows, lock them in a consistent order so you reduce the risk of deadlocks. These habits cut down on lock contention and deadlocks, though they do not repair a server-side memory bug. For more on how locking works, see how PostgreSQL locks rows with SELECT FOR UPDATE.
If you want a query to fail immediately instead of waiting for a locked row, add NOWAIT so PostgreSQL returns an error when it cannot acquire the lock. Current PostgreSQL versions also support SKIP LOCKED, which tells PostgreSQL to skip rows that another transaction has locked. This works well for some queue-like workloads. Because SKIP LOCKED omits rows that another transaction holds, it gives your query an intentionally incomplete view and cannot replace ordinary row locking in general. Both options change how your query handles contention, but neither fixes the 9.1.15 crash defect. Check the current SELECT documentation for the syntax and behavior your version supports.
You should not rely on changing the transaction isolation level to work around this historical crash. The release notes say the defect occurred under READ COMMITTED, but they do not recommend switching to another isolation level as a fix. Pick an isolation level that fits your application’s correctness requirements, and upgrade to a supported server version to fix server defects.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com