Postgres pg_toast in autovacuum - which table?
Asked Answered
C

2

20

I have an autovacuum process running on pg_toast:

select query, from pg_stat_activity where query like '%autov%';
"autovacuum: VACUUM pg_toast.pg_toast_15404513 "

How do I find out what table/index/whatever this pg_toast pertains to? Or is the autovacuum working on something else?

Cuspidate answered 27/8, 2013 at 2:32 Comment(0)
P
17

I think you'll want something like:

select n.nspname, c.relname 
from pg_class c 
inner join pg_namespace n on c.relnamespace = n.oid
where reltoastrelid = (
    select oid
    from pg_class 
    where relname = 'pg_toast_15404513' 
    and relnamespace = (SELECT n2.oid FROM pg_namespace n2 WHERE n2.nspname = 'pg_toast') )

It'd be nice if Pg reported this in the vacuum command summary.

Pinchcock answered 27/8, 2013 at 3:4 Comment(2)
Is there a way to list real name of all pg_toast_xxx ? thanks.Pumice
@wolf97084, here is query for listing all pg_toast_xxx and their real name select r.relname, t.relname from pg_class r inner join pg_class t on t.reltoastrelid = r.oid;Calomel
T
41

Here's a shorter way:

select 15404513::regclass;

where 15404513 is pg_toast_ suffix.

Tafoya answered 23/4, 2014 at 13:35 Comment(1)
This would return the correct name of the table only if run in the correct DB.Tuneful
P
17

I think you'll want something like:

select n.nspname, c.relname 
from pg_class c 
inner join pg_namespace n on c.relnamespace = n.oid
where reltoastrelid = (
    select oid
    from pg_class 
    where relname = 'pg_toast_15404513' 
    and relnamespace = (SELECT n2.oid FROM pg_namespace n2 WHERE n2.nspname = 'pg_toast') )

It'd be nice if Pg reported this in the vacuum command summary.

Pinchcock answered 27/8, 2013 at 3:4 Comment(2)
Is there a way to list real name of all pg_toast_xxx ? thanks.Pumice
@wolf97084, here is query for listing all pg_toast_xxx and their real name select r.relname, t.relname from pg_class r inner join pg_class t on t.reltoastrelid = r.oid;Calomel

© 2022 - 2024 — McMap. All rights reserved.