From 226261f387fd8b44420ad03298ef09d83571f9b1 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Wed, 3 Apr 2024 09:19:25 +0200 Subject: Add error codes to some PANIC/FATAL errors reports This adds errcodes to a set of PANIC and FATAL errors in xlog.c and relcache.c, which previously had no errcode at all set, in order to make fleetwide analysis of errorlogs easier. There are many more ereport/elogs left which could benefit from having an errcode but this at least makes a dent in the issue. Author: Nazir Bilal Yavuz Discussion: https://postgr.es/m/CAN55FZ1k8LgLEqncPGmz_fWnrobV6bjABOTH4tOWta6xNcPQig@mail.gmail.com --- src/backend/utils/cache/relcache.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/backend/utils/cache/relcache.c') diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 1f419c2a6dd..3fe74dabd00 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -4211,8 +4211,10 @@ RelationCacheInitializePhase3(void) htup = SearchSysCache1(RELOID, ObjectIdGetDatum(RelationGetRelid(relation))); if (!HeapTupleIsValid(htup)) - elog(FATAL, "cache lookup failed for relation %u", - RelationGetRelid(relation)); + ereport(FATAL, + errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg_internal("cache lookup failed for relation %u", + RelationGetRelid(relation))); relp = (Form_pg_class) GETSTRUCT(htup); /* @@ -4345,7 +4347,9 @@ load_critical_index(Oid indexoid, Oid heapoid) LockRelationOid(indexoid, AccessShareLock); ird = RelationBuildDesc(indexoid, true); if (ird == NULL) - elog(PANIC, "could not open critical system index %u", indexoid); + ereport(PANIC, + errcode(ERRCODE_DATA_CORRUPTED), + errmsg_internal("could not open critical system index %u", indexoid)); ird->rd_isnailed = true; ird->rd_refcnt = 1; UnlockRelationOid(indexoid, AccessShareLock); @@ -6527,7 +6531,9 @@ write_relcache_init_file(bool shared) */ magic = RELCACHE_INIT_FILEMAGIC; if (fwrite(&magic, 1, sizeof(magic), fp) != sizeof(magic)) - elog(FATAL, "could not write init file"); + ereport(FATAL, + errcode_for_file_access(), + errmsg_internal("could not write init file: %m")); /* * Write all the appropriate reldescs (in no particular order). @@ -6628,7 +6634,9 @@ write_relcache_init_file(bool shared) } if (FreeFile(fp)) - elog(FATAL, "could not write init file"); + ereport(FATAL, + errcode_for_file_access(), + errmsg_internal("could not write init file: %m")); /* * Now we have to check whether the data we've so painstakingly @@ -6678,9 +6686,13 @@ static void write_item(const void *data, Size len, FILE *fp) { if (fwrite(&len, 1, sizeof(len), fp) != sizeof(len)) - elog(FATAL, "could not write init file"); + ereport(FATAL, + errcode_for_file_access(), + errmsg_internal("could not write init file: %m")); if (len > 0 && fwrite(data, 1, len, fp) != len) - elog(FATAL, "could not write init file"); + ereport(FATAL, + errcode_for_file_access(), + errmsg_internal("could not write init file: %m")); } /* -- cgit v1.2.3