Closed Skryabind closed 2 years ago
Yeah, I observed such error yesterday. Will fix.
The query itself looks correct, but the postgresql query planner moved the cast to regclass to the join condition. Therefore, it may receive an attempt to search for a knowingly non-existent object. pg_toast_5987783_index is part of postgresql TOAST system, but should be in special schema pg_toast, not in public.
But to be sure it's the same problem, please say:
OFFSET 0
?
SELECT
indexname, indexdef,
pg_catalog.pg_relation_size(indexoid) as idxsize
FROM (
SELECT
indexname, indexdef,
(quote_ident(schemaname) || '.' || quote_ident(indexname))::regclass AS indexoid
FROM pg_catalog.pg_indexes
WHERE
schemaname = 'public' AND
tablename = 'user_subscriptions'/* OFFSET 0*/
) AS sq
LEFT JOIN pg_catalog.pg_constraint ON
conindid = indexoid AND contype IN ('p', 'u', 'x')
ORDER BY idxsize
@Melkij Server version PostgreSQL 13.2 This query gives an error. This is the explain:
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=39.23..39.24 rows=1 width=104)
Sort Key: (pg_relation_size((((quote_ident((n.nspname)::text) || '.'::text) || quote_ident((i.relname)::text)))::regclass, 'main'::text))
-> Merge Join (cost=4.84..39.22 rows=1 width=104)
Merge Cond: (n.oid = c.relnamespace)
Join Filter: (x.indexrelid = i.oid)
-> Nested Loop Left Join (cost=0.27..1868.52 rows=453 width=136)
Join Filter: (pg_constraint.conindid = ((((quote_ident((n.nspname)::text) || '.'::text) || quote_ident((i.relname)::text)))::regclass)::oid)
-> Nested Loop (cost=0.27..83.70 rows=453 width=136)
-> Index Scan using pg_namespace_oid_index on pg_namespace n (cost=0.27..31.03 rows=1 width=68)
Filter: (nspname = 'public'::name)
-> Seq Scan on pg_class i (cost=0.00..48.14 rows=453 width=72)
Filter: (relkind = ANY ('{i,I}'::"char"[]))
-> Materialize (cost=0.00..18.43 rows=120 width=4)
-> Seq Scan on pg_constraint (cost=0.00..17.83 rows=120 width=4)
Filter: (contype = ANY ('{p,u,x}'::"char"[]))
-> Materialize (cost=4.56..18.28 rows=1 width=8)
-> Nested Loop (cost=4.56..18.28 rows=1 width=8)
-> Index Scan using pg_class_relname_nsp_index on pg_class c (cost=0.28..8.30 rows=1 width=8)
Index Cond: (relname = 'user_subscriptions'::name)
Filter: (relkind = ANY ('{r,m,p}'::"char"[]))
-> Bitmap Heap Scan on pg_index x (cost=4.29..9.96 rows=2 width=8)
Recheck Cond: (indrelid = c.oid)
-> Bitmap Index Scan on pg_index_indrelid_index (cost=0.00..4.29 rows=2 width=0)
Index Cond: (indrelid = c.oid)
With the uncommented OFFSET 0 there is no errors.
Should be fixed now
Hi! I successfully run pgcompacttable on different tables separately:
After that I run the utility on full database:
Some tables where optimized successfully, but after some time an error "relation "public.pg_toast_5987783_index" does not exist" started appearing for all tables. Relation pg_toast_5987783_index is the same for all tables. This is the first table the error occurs (table name is classes, maybe it is important):
Now this error appears in any utility run, ex:
The error occurs in this query:
It is interesting that if I change LEFT JOIN to JOIN, query executes without any error. Also if I remove condition
schemaname = 'public'
, query executes without error too. Also if I changecontype IN ('p', 'u', 'x')
tocontype IN ('p', 'u')
, query works too!I don't understand why this error happens, I didn't find any relation or index with the name pg_toast_5987783_index. But in fact that this has been started during pgcompacttable run and probably the utility made something wrong in database.
I've restored the dump made after this error happened on other server, and this query runs without errors on restored database. I dont know how to fix this in production database.