The database crashes and encounters a PANIC (Segmentation Fault) during query execution or planning when the Postgres planner is evaluating PostGIS spatial predicates.
The following error is observed in the database logs:
PANIC: Unexpected internal error: Master process received signal SIGSEGVThe issue specifically triggers when the Postgres Optimizer is turned off (SET optimizer = off;) and a spatial query is explained or executed:
NOTICE: estimate_selectivity called with null input
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
GPDB 7.8.2
This is caused by a known defect in PostGIS. When the Postgres planner asks PostGIS to estimate the selectivity of a spatial predicate (such as &&), it requires looking up the column's statistics.
If the statistics exist but do not contain a spatial histogram, PostGIS returns a default fallback estimate and incorrectly attempts to free a null pointer. Freeing the null pointer causes a panic and terminates the master process.
Permenant Fix: This defect is targeted to be fixed in release 7.8.4.
Workaround
Use the GPORCA optimizer, which is unaffected by this defect. GPORCA does not call the operator's selectivity function (gserialized_gist_sel()), but rather reads pg_statistic directly and derives its own cardinality.
To apply the workaround, ensure the optimizer is enabled for the affected queries:
Connect to the database.
Run the following command before executing spatial queries: SET optimizer = on;
For more details regarding the upstream PostGIS defect, refer to the following resources: