Summary:
The TestPgStatUserTablesPersistence test was failing on macOS due to a NULL value being returned for the last_analyze column in the pg_stat_user_tables view. This indicated a failure in the persistence and restoration of PostgreSQL's statistics across restarts.
**Root Cause Analysis:**
The investigation revealed that the PostgreSQL process was not undergoing a clean shutdown on macOS. The test was configured to perform an unsafe shutdown by sending a SIGKILL to the yb-tserver process.
On Linux, an unsafe shutdown of the parent yb-tserver still results in a SIGINT being sent to the child postmaster process. This triggers a fast shutdown where the postmaster process sends SIGTERM to child PostgreSQL process(es). This allows for the proper flushing of statistics to disk before termination. This behavior is explicitly handled by setting a parent death signal (pdeathsig) using prctl via the YB_PG_PDEATHSIG environment variable.
On macOS, the prctl system call is not available. Consequently, when the parent yb-tserver is killed, the child PostgreSQL process is terminated abruptly without receiving a shutdown signal, preventing it from saving its statistics.
**Resolution:**
The fix modifies the test to perform a safe shutdown (SafeShutdown::kTrue) by default. To retain the original intent of testing the pdeathsig mechanism, the test will now only perform an unsafe shutdown (SafeShutdown::kFalse) when prctl is available (i.e., on Linux systems, detected via HAVE_SYS_PRCTL_H). This conditional logic isolates the platform-specific behavior while ensuring the primary test case is robust and platform-agnostic.
Jira: DB-17889
Test Plan: Jenkins
Reviewers: kramanathan, smishra
Reviewed By: kramanathan
Subscribers: yql
Differential Revision: https://phorge.dev.yugabyte.com/D45937