aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/relcache.c
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2024-04-03 09:19:25 +0200
committerDaniel Gustafsson <dgustafsson@postgresql.org>2024-04-03 09:19:25 +0200
commit226261f387fd8b44420ad03298ef09d83571f9b1 (patch)
treedf760321ed16c192ca930863e37164f689e7383f /src/backend/utils/cache/relcache.c
parentc627d944e6c2620fb3b28f2e4b27e19212f84045 (diff)
downloadpostgresql-226261f387fd8b44420ad03298ef09d83571f9b1.tar.gz
postgresql-226261f387fd8b44420ad03298ef09d83571f9b1.zip
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 <byavuz81@gmail.com> Discussion: https://postgr.es/m/CAN55FZ1k8LgLEqncPGmz_fWnrobV6bjABOTH4tOWta6xNcPQig@mail.gmail.com
Diffstat (limited to 'src/backend/utils/cache/relcache.c')
-rw-r--r--src/backend/utils/cache/relcache.c26
1 files changed, 19 insertions, 7 deletions
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"));
}
/*