aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2025-03-27 13:20:23 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2025-03-27 13:20:23 -0400
commitdb8238da4265a1e381c0b5499cac2518580bb463 (patch)
treeddd089875b15421d6ea128720407922fcaa1d583
parente5cf186277f917c3743f34931b151c22555456d9 (diff)
downloadpostgresql-db8238da4265a1e381c0b5499cac2518580bb463.tar.gz
postgresql-db8238da4265a1e381c0b5499cac2518580bb463.zip
Prevent assertion failure in contrib/pg_freespacemap.
Applying pg_freespacemap() to a relation lacking storage (such as a view) caused an assertion failure, although there was no ill effect in non-assert builds. Add an error check for that case. Bug: #18866 Reported-by: Robins Tharakan <tharakan@gmail.com> Author: Tender Wang <tndrwang@gmail.com> Reviewed-by: Euler Taveira <euler@eulerto.com> Discussion: https://postgr.es/m/18866-d68926d0f1c72d44@postgresql.org Backpatch-through: 13
-rw-r--r--contrib/pg_freespacemap/pg_freespacemap.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/contrib/pg_freespacemap/pg_freespacemap.c b/contrib/pg_freespacemap/pg_freespacemap.c
index b82cab2d97e..c9b794806ba 100644
--- a/contrib/pg_freespacemap/pg_freespacemap.c
+++ b/contrib/pg_freespacemap/pg_freespacemap.c
@@ -11,6 +11,7 @@
#include "access/relation.h"
#include "funcapi.h"
#include "storage/freespace.h"
+#include "utils/rel.h"
PG_MODULE_MAGIC;
@@ -30,6 +31,12 @@ pg_freespace(PG_FUNCTION_ARGS)
rel = relation_open(relid, AccessShareLock);
+ if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("relation \"%s\" does not have storage",
+ RelationGetRelationName(rel))));
+
if (blkno < 0 || blkno > MaxBlockNumber)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),