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…
PostgreSQL 13.12, released on August 10, 2023, fixed a bug that caused some Block Range Indexes (BRIN indexes) to miss rows with NULL values. A BRIN index stores summaries for groups of nearby table pages rather than a separate entry for every row. If a summary failed to record that a group of pages held NULL values, PostgreSQL could skip those pages during a NULL search and miss matching rows. When you update PostgreSQL, you fix the server code for future index work, and when you reindex, PostgreSQL rebuilds the summaries already stored in affected indexes.
PostgreSQL 13.12 also fixed CVE-2023-39417, a vulnerability that let attackers inject SQL through certain scripts in trusted, third-party extensions. If your database still runs PostgreSQL 13, you should find and rebuild any BRIN indexes used to search for NULL values. Because PostgreSQL 13 has reached end of life, you also need to plan a migration to a supported major version.
BRIN indexes work best on large tables where a column's values follow the physical order of the rows, such as timestamps in a table that mostly receives new inserts. PostgreSQL reads those page summaries to decide which groups of pages to inspect and which ones to skip. Because a scan relies on those summaries, an inaccurate summary can cause PostgreSQL to skip pages that hold matching rows. You can read more about how this structure works in the BRIN introduction.
In version 13.12, the PostgreSQL team fixed bugs in how BRIN handles empty ranges, ranges containing only NULL values, and merged summaries for all-NULL ranges. Those bugs could leave a summary without a record that a range held NULL values. The release notes recommend reindexing BRIN indexes that support NULL searches. When you update the server, you fix the underlying behavior for future writes, but you still have to rebuild affected indexes so PostgreSQL replaces any bad summaries stored by an earlier version. Both the 13.12 release notes and the release announcement narrow this advice to BRIN indexes used to search for NULL values; they do not say that every BRIN index was affected.
Start by listing your BRIN indexes:
SELECT schemaname, tablename, indexname, indexdef
FROM pg_indexes
WHERE indexdef ILIKE '%USING brin%'
ORDER BY schemaname, tablename, indexname;
This query lists every BRIN index in your database, but it cannot tell you which ones support IS NULL queries or which ones hold faulty summaries. Check your application queries, workload records, and query plans to find the indexes used for NULL searches, and prioritize those.
Rebuild each affected index by name:
REINDEX INDEX schema_name.index_name;
If you are working on a production table that must keep accepting writes, PostgreSQL 13 also supports:
REINDEX INDEX CONCURRENTLY schema_name.index_name;
Run REINDEX INDEX when you can schedule a maintenance window that blocks writes to the table. If you cannot block writes, run REINDEX INDEX CONCURRENTLY instead. With the concurrent option, PostgreSQL lets writes continue, but it takes longer and scans the table twice. It also waits for relevant in-flight transactions to finish and uses extra CPU, memory, and I/O. You cannot run a concurrent reindex inside a transaction block, and PostgreSQL allows only one concurrent index build on a table at a time. The REINDEX documentation covers these limits in detail.
Upgrade to a release that includes the fix before you rebuild anything. Once the server is updated, list your BRIN indexes, identify the ones used for NULL searches, and reindex them. Watch the command output and your monitoring while the rebuilds run, then verify that your NULL queries return the expected rows. According to the release notes, databases already running PostgreSQL 13.x did not require a dump and restore for the 13.12 minor update.
You install PostgreSQL extensions with CREATE EXTENSION, which creates the extension's database objects. If an extension is marked as trusted, a user with the database-level CREATE privilege can install it without superuser access. Inside an extension script, placeholders like @extowner@ and @extschema@ represent the extension owner and target schema. The CREATE EXTENSION documentation explains how trusted extensions and installation work.
CVE-2023-39417 stemmed from unsafe substitution of schema or owner names inside quoted parts of an extension script. In 13.12, PostgreSQL disallowed those substitutions whenever a name contains a quote, backslash, or dollar sign. According to the PostgreSQL security advisory, an attack required two conditions: a vulnerable trusted extension that was not bundled with PostgreSQL had to be installed, and the attacker needed the database-level CREATE privilege. If both conditions held, the attacker could execute code as the bootstrap superuser. The advisory notes that no bundled extension was vulnerable.
Because PostgreSQL blocks this substitution path in the server itself, you did not need to edit individual extensions to stop this specific attack. That said, the server fix does not guarantee that every third-party extension script is safe. You should still review where your extensions come from, check what permissions they have, and compare your setup against the advisory's attack conditions.
PostgreSQL 13 reached end of life on November 13, 2025, with version 13.23 as its final release. Under the project's versioning policy, each major version receives five years of support. If you still run 13.12, your server is missing all later PostgreSQL 13 security and bug fixes. Even if you upgrade to 13.23, the PostgreSQL project no longer provides ongoing support for version 13.
Treat the 13.12 changes as past remediation. Upgrade past 13.12 so your server has the BRIN and extension fixes, then plan your migration to a supported major version. When you reindex, PostgreSQL refreshes stored BRIN summaries, but that step does not replace server updates or bring an end-of-life release back into support.
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