Truncation of mapped catalogs (whether local or shared) leads to server crash - Mailing list pgsql-hackers

From Ashutosh Sharma
Subject Truncation of mapped catalogs (whether local or shared) leads to server crash
Date
Msg-id CAE9k0PkHWqujzyS+Wwyrd+nh7CTL=wBE-Uzp6Hh7KeefjviEsQ@mail.gmail.com
Whole thread Raw
Responses Re: Truncation of mapped catalogs (whether local or shared) leads to server crash
List pgsql-hackers
Hi everyone,

I've noticed that truncating mapped catalogs causes the server to
crash due to an assertion failure. Here are the details:

Executing below commands:

-- set allow_system_table_mods TO on;
-- truncate table pg_type;

Results into a server crash with below backtrace:

...
#2  0x000055736767537d in ExceptionalCondition
(conditionName=0x5573678c5760 "relation->rd_rel->relkind ==
RELKIND_INDEX", fileName=0x5573678c4b28 "relcache.c",
    lineNumber=3896) at assert.c:66
#3  0x0000557367664e31 in RelationSetNewRelfilenumber
(relation=0x7f68240f1d58, persistence=112 'p') at relcache.c:3896
#4  0x000055736715b952 in ExecuteTruncateGuts
(explicit_rels=0x55736989e5b0, relids=0x55736989e600,
relids_logged=0x0, behavior=DROP_RESTRICT, restart_seqs=false,
    run_as_table_owner=false) at tablecmds.c:2146
#5  0x000055736715affa in ExecuteTruncate (stmt=0x55736989f950) at
tablecmds.c:1877
#6  0x0000557367493693 in standard_ProcessUtility
(pstmt=0x55736989fa00, queryString=0x55736989eed0 "truncate table
pg_type;", readOnlyTree=false,
    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x5573698a0330, qc=0x7ffe19367ac0) at utility.c:728

As seen from the backtrace above, the assertion failure occurs in
'RelationSetNewRelfilenumber()' at:

if (RelationIsMapped(relation))
{
    /* This case is only supported for indexes */
    Assert(relation->rd_rel->relkind == RELKIND_INDEX);
}

I would like to know why we are only expecting index tables here and
not the regular catalog tables. For instance, pg_type is a mapped
relation but not of index type, leading to the failure in this case.
Should we consider changing this Assert condition from RELKIND_INDEX
to (RELKIND_INDEX || RELKIND_RELATION)?

Additionally, is it advisable to restrict truncation of the pg_class
table? It's like a kind of circular dependency in case of pg_class
which is not applicable in case of other catalog tables.

--
With Regards,
Ashutosh Sharma.



pgsql-hackers by date:

Previous
From: Alena Rybakina
Date:
Subject: Re: post-freeze damage control
Next
From: Alexander Korotkov
Date:
Subject: Re: Missing docs for new enable_group_by_reordering GUC