mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Fix possible crash during FATAL exit from reindexing.
index.c supposed that it could just use a PG_TRY block to clean up the state associated with an active REINDEX operation. However, that code doesn't run if we do a FATAL exit --- for example, due to a SIGTERM shutdown signal --- while the REINDEX is happening. And that state does get consulted during catalog accesses, which makes it problematic if we do any catalog accesses during shutdown --- for example, to clean up any temp tables created in the session. If this combination of circumstances occurred, we could find ourselves trying to access already-freed memory. In debug builds that'd fairly reliably cause an assertion failure. In production we might often get away with it, but with some bad luck it could cause a core dump. Another possible bad outcome is an erroneous conclusion that an index-to-be-accessed is being reindexed; but it looks like that would be unlikely to have any consequences worse than failing to drop temp tables right away. (They'd still get dropped by the next session that uses that temp schema.) To fix, get rid of the use of PG_TRY here, and instead hook into the transaction abort mechanisms to clean up reindex state. Per bug #16378 from Alexander Lakhin. This has been wrong for a very long time, so back-patch to all supported branches. Discussion: https://postgr.es/m/16378-7a70ca41b3ec2009@postgresql.org
This commit is contained in:
@@ -131,6 +131,8 @@ extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
|
||||
|
||||
extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action);
|
||||
|
||||
extern Oid IndexGetRelation(Oid indexId, bool missing_ok);
|
||||
|
||||
extern void reindex_index(Oid indexId, bool skip_constraint_checks,
|
||||
char relpersistence, int options);
|
||||
|
||||
@@ -145,8 +147,8 @@ extern bool reindex_relation(Oid relid, int flags, int options);
|
||||
|
||||
extern bool ReindexIsProcessingHeap(Oid heapOid);
|
||||
extern bool ReindexIsProcessingIndex(Oid indexOid);
|
||||
extern Oid IndexGetRelation(Oid indexId, bool missing_ok);
|
||||
|
||||
extern void ResetReindexState(int nestLevel);
|
||||
extern Size EstimateReindexStateSpace(void);
|
||||
extern void SerializeReindexState(Size maxsize, char *start_address);
|
||||
extern void RestoreReindexState(void *reindexstate);
|
||||
|
Reference in New Issue
Block a user