Avoid crashes on a concurrently dropped schema
Hi,
I noticed two places that can segfault if a schema is dropped while
they run: pg_identify_object(), and schema_to_xml() with the related
SQL/XML functions. Both look up a schema name by OID without holding a
lock on the schema, and dereference the NULL that get_namespace_name()
returns after a concurrent DROP SCHEMA. It's a narrow race and rare in
practice, but any user can hit it, and it takes the cluster through
crash recovery.
0001 makes pg_identify_object() return NULL for the schema, as it
already does for objects that have gone away, so catalog-wide scans
keep working. 0002 makes the single-schema XML functions report
that the schema does not exist, as they do for a nonexistent schema,
and makes database_to_xml* skip it. Both go back to 14.
Thoughts?
Thanks,
Baji Shaik
Attachments:
t254378_10001-Avoid-crash-in-pg_identify_object-on-a-concurrently-.patchapplication/octet-stream; name=0001-Avoid-crash-in-pg_identify_object-on-a-concurrently-.patchDownload+8-6
0002-Avoid-crash-in-schema_to_xml-on-a-concurrently-dropp.patchapplication/octet-stream; name=0002-Avoid-crash-in-schema_to_xml-on-a-concurrently-dropp.patchDownload+33-8
On 25/10/2026 17:40, Baji Shaik wrote:
I noticed two places that can segfault if a schema is dropped while
they run: pg_identify_object(), and schema_to_xml() with the related
SQL/XML functions. Both look up a schema name by OID without holding a
lock on the schema, and dereference the NULL that get_namespace_name()
returns after a concurrent DROP SCHEMA. It's a narrow race and rare in
practice, but any user can hit it, and it takes the cluster through
crash recovery.0001 makes pg_identify_object() return NULL for the schema, as it
already does for objects that have gone away, so catalog-wide scans
keep working. 0002 makes the single-schema XML functions report
that the schema does not exist, as they do for a nonexistent schema,
and makes database_to_xml* skip it. Both go back to 14.
Committed down to v14, thanks!
- Heikki