Skip to content

Commit 4623d71

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 d66997d commit 4623d71

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

contrib/pg_freespacemap/pg_freespacemap.c

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

1516
PG_MODULE_MAGIC_EXT(
1617
.name = "pg_freespacemap",
@@ -33,6 +34,13 @@ pg_freespace(PG_FUNCTION_ARGS)
3334

3435
rel = relation_open(relid, AccessShareLock);
3536

37+
if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
38+
ereport(ERROR,
39+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
40+
errmsg("relation \"%s\" does not have storage",
41+
RelationGetRelationName(rel)),
42+
errdetail_relkind_not_supported(rel->rd_rel->relkind)));
43+
3644
if (blkno < 0 || blkno > MaxBlockNumber)
3745
ereport(ERROR,
3846
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),

0 commit comments

Comments
 (0)