1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-21 12:05:57 +03:00

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
This commit is contained in:
Tom Lane 2025-03-27 13:20:23 -04:00
parent e5cf186277
commit db8238da42

View File

@ -11,6 +11,7 @@
#include "access/relation.h" #include "access/relation.h"
#include "funcapi.h" #include "funcapi.h"
#include "storage/freespace.h" #include "storage/freespace.h"
#include "utils/rel.h"
PG_MODULE_MAGIC; PG_MODULE_MAGIC;
@ -30,6 +31,12 @@ pg_freespace(PG_FUNCTION_ARGS)
rel = relation_open(relid, AccessShareLock); 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) if (blkno < 0 || blkno > MaxBlockNumber)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),