Skip to content

Commit db8238d

Browse files
committed
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
1 parent e5cf186 commit db8238d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

contrib/pg_freespacemap/pg_freespacemap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "access/relation.h"
1212
#include "funcapi.h"
1313
#include "storage/freespace.h"
14+
#include "utils/rel.h"
1415

1516
PG_MODULE_MAGIC;
1617

@@ -30,6 +31,12 @@ pg_freespace(PG_FUNCTION_ARGS)
3031

3132
rel = relation_open(relid, AccessShareLock);
3233

34+
if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
35+
ereport(ERROR,
36+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
37+
errmsg("relation \"%s\" does not have storage",
38+
RelationGetRelationName(rel))));
39+
3340
if (blkno < 0 || blkno > MaxBlockNumber)
3441
ereport(ERROR,
3542
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),

0 commit comments

Comments
 (0)