I discovered that postgres can run into NULL dereference in FK
validation when the
 the referenced collation's schema is dropped concurrently. The
attached two-session isolation test creates a NOT VALID FK, then
validates it, while another session moves the referenced collation on
column to another schema and drops its old schema. On HEAD, the
backend crashes  with SIGSEGV in ri_GenerateQualCollation, isolation
test tail output:

# @@ -31,6 +31,7 @@
#          PERFORM injection_points_wakeup('ri-generate-qual-collation');
#      END$$;
#
# -s1: NOTICE:  validation failed with SQLSTATE XX000
# -step validate_fk: <... completed>
# -step checked:
# +PQconsumeInput failed: server closed the connection unexpectedly
# + This probably means the server terminated abnormally
# + before or while processing the request.
# +
not ok 1     - ri_collation_schema_drop                  501 ms
# (test process exited with exit code 1)
1..1
# 1 of 1 tests failed.

0001 aims to fix NULL deref by simply checking for NULL. This is
however not very user-friendly, because it will fail DDL with XX000
code. To fix that, check the follow up patch, which takes
AccessShareLock on collation, serializing DDL.

-- 
Best regards,
Kirill Reshke

Attachment: 0001-Handle-missing-collation-namespace-in-RI-queries.patch
Description: Binary data

Attachment: 0002-Test-RI-collation-namespace-drop-with-injection-poin.patch
Description: Binary data

Attachment: followup-0001-Lock-collation-while-building-RI-query.patch
Description: Binary data

Reply via email to