Find the main table for an index or TOAST table

Craig Ringer
Craig Ringer

You have an error relating to an index or a TOAST table and want to know what the main relation associated with it is.

Index

select indexrelid::regclass from pg_index where indexrelid = 'my_table_pkey'::regclass;

The reverse mapping is:

select indexrelid::regclass from pg_index where indrelid = 'my_table'::regclass;

TOAST

You'll need superuser rights because pg_toast isn't directly accessible by normal users.

select oid::regclass from pg_class where reltoastrelid = 'pg_toast.pg_toast_65536'::regclass;

The reverse mapping is:

select reltoastrelid::regclass from pg_class where oid = 'my_table'::regclass;

Was this article helpful?

0 out of 0 found this helpful