From: Euler Taveira <euler@eulerto.com>
To: Tender Wang <tndrwang@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: tharakan@gmail.com, pgsql-bugs@lists.postgresql.org, "Heikki Linnakangas" <hlinnaka@iki.fi>
Subject: Re: BUG #18866: Running pg_freespace() on views triggers an Abort
Date: Tue, 25 Mar 2025 22:55:52 -0300
Message-ID: <b6ea023a-703d-4afa-8561-9e867db1b5f0@app.fastmail.com> (raw)
In-Reply-To: <CAHewXNm8rkn9Vu-WhmMQMJS2hSqztbJO1cRv5-+Rp99+k43aJw@mail.gmail.com>
References: <18866-d68926d0f1c72d44@postgresql.org>
<CAHewXNk6uX0VBROmoMrnKs_AOzbAQo+i9pouUiYj01y50HZRSw@mail.gmail.com>
<1280897.1742920635@sss.pgh.pa.us>
<CAHewXNm8rkn9Vu-WhmMQMJS2hSqztbJO1cRv5-+Rp99+k43aJw@mail.gmail.com>
On Tue, Mar 25, 2025, at 10:18 PM, Tender Wang wrote:
> Thanks for the advice. Please see the attached patch.
Your patch needs some adjustments. There is no need to include pg_class.h. I
don't like the proposed error message. I prefer saying the relation cannot be
opened because that's what will happen if it reaches this code path. This is an
existing message so no need for translation. The output will be like:
postgres=# SELECT pg_freespace('f', 0);
ERROR: cannot open relation "f"
DETAIL: This operation is not supported for foreign tables.
postgres=# SELECT pg_freespace('pg_roles', 0);
ERROR: cannot open relation "pg_roles"
DETAIL: This operation is not supported for views.
postgres=# SELECT pg_freespace('pg_class', 0);
pg_freespace
--------------
7520
(1 row)
I'm attaching a patch that includes these modifications.
--
Euler Taveira
EDB https://www.enterprisedb.com/Attachments:fsm.patch (text/x-patch, 845B) downloaddiff --git a/contrib/pg_freespacemap/pg_freespacemap.c b/contrib/pg_freespacemap/pg_freespacemap.cindex 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),
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: euler@eulerto.com, tndrwang@gmail.com, tgl@sss.pgh.pa.us, hlinnaka@iki.fi
Subject: Re: BUG #18866: Running pg_freespace() on views triggers an Abort
In-Reply-To: <b6ea023a-703d-4afa-8561-9e867db1b5f0@app.fastmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox