fsm.patch

text/x-patch

Filename: fsm.patch
Type: text/x-patch
Part: 0
Message: Re: BUG #18866: Running pg_freespace() on views triggers an Abort

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
contrib/pg_freespacemap/pg_freespacemap.c 8 0
diff --git a/contrib/pg_freespacemap/pg_freespacemap.c b/contrib/pg_freespacemap/pg_freespacemap.c
index 565167aaef0..49eea2823b9 100644
--- a/contrib/pg_freespacemap/pg_freespacemap.c
+++ b/contrib/pg_freespacemap/pg_freespacemap.c
@@ -11,6 +11,7 @@
 #include "access/relation.h"
 #include "fmgr.h"
 #include "storage/freespace.h"
+#include "utils/rel.h"
 
 PG_MODULE_MAGIC;
 
@@ -30,6 +31,13 @@ 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("cannot open relation \"%s\"",
+						RelationGetRelationName(rel)),
+				 errdetail_relkind_not_supported(rel->rd_rel->relkind)));
+
 	if (blkno < 0 || blkno > MaxBlockNumber)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),