Re: BUG #18866: Running pg_freespace() on views triggers an Abort

Euler Taveira <euler@eulerto.com>

From: "Euler Taveira" <euler@eulerto.com>
To: "Tender Wang" <tndrwang@gmail.com>, "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: tharakan@gmail.com, pgsql-bugs@lists.postgresql.org, "Heikki Linnakangas" <hlinnaka@iki.fi>
Date: 2025-03-26T01:55:52Z
Lists: pgsql-bugs

Attachments

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/

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Prevent assertion failure in contrib/pg_freespacemap.

  2. Don't try to open visibilitymap when analyzing a foreign table