The goal is to get the table and column which are "using" a sequence, and the query I've come up with is this:
select attrelid::regclass::text, attname
from pg_attribute
where pg_get_serial_sequence(attrelid::regclass::text, attname) = 'public.websession_idcntr_seq';
It's inefficient so any other suggestions are also welcome, but the problem at hand is that this breaks with the following error:
ERROR: permission denied for schema pg_toast
So the next thing I did was try to avoid pg_toast:
select attrelid::regclass::text, attname
from pg_attribute
join pg_class tbl on tbl.oid = pg_attribute.attrelid
join pg_namespace nsp on tbl.relnamespace = nsp.oid
where
nsp.nspname != 'pg_toast'
and pg_get_serial_sequence(attrelid::regclass::text, attname) = 'public.websession_idcntr_seq';
That also fails with exactly the same message.
I have no intention of doing anything with the pg_toast schema, and I can't run this under a superuser account. (EDIT: And I can't modify permissions to get around that).
Why doesn't the workaround with nspname != 'pg_toast'
work?
Is there a better way to do this whole operation?