The list of all the queries

All user-defined TOAST-able types

Query goal: Find user-defined types in case of which the system can use the TOAST technique, i.e., save the value in a compressed form or store it in a automatically-created secondary table, which is hidden from the database user (TOAST table).
Notes about the query: Explanation of the toasting strategy.
  • p (plain): Values must always be stored plain (non-varlena types always use this value).
  • e (external): Values can be stored in a secondary “TOAST” relation (if relation has one, see pg_class.reltoastrelid).
  • m (main): Values can be compressed and stored inline.
  • x (extended): Values can be compressed and/or moved to a secondary relation.
Query type: General (Overview of some aspect of the database.)
Query license: MIT License
Data source: system catalog only
SQL query: Click on query to copy it

SELECT 
n.nspname AS type_schema, 
pt.typname AS type_name,
CASE WHEN pt.typstorage='p' THEN 'plain'
WHEN pt.typstorage='e' THEN 'external'
WHEN pt.typstorage='m' THEN 'main'
WHEN pt.typstorage='x' THEN 'extended'
END AS toasting_strategy,
CASE WHEN pt.typtype='b' AND left(pt.typname,1)<>'_' THEN 'BASE TYPE'
WHEN pt.typtype='b' AND left(pt.typname,1)='_' THEN 'ARRAY TYPE'
WHEN pt.typtype='e' THEN 'ENUMERATION TYPE'
WHEN pt.typtype='c' THEN 'COMPOSITE TYPE'
WHEN pt.typtype='d' THEN 'DOMAIN'
WHEN pt.typtype='r' THEN 'RANGE TYPE' END AS type_type
FROM pg_namespace AS n INNER JOIN pg_authid AS a ON n.nspowner=a.oid
INNER JOIN pg_type AS pt ON n.oid=pt.typnamespace
WHERE (n.nspname ='public' OR a.rolname<>'postgres')
AND pt.typtype IN ('b','d', 'e','r', 'c')
AND pt.typlen = -1
ORDER BY type_type, type_schema, type_name;

Categories where the query belongs to

Category nameCategory description
Data at the database physical levelQueries of this category provide information about the disk usage.
Data typesQueries of this category provide information about the data types and their usage.
TOASTQueries of this category provide information about The Oversized-Attribute Storage Technique.

Reference materials for further reading

Reference
https://postgrespro.com/docs/postgrespro/current/storage-toast
https://wiki.postgresql.org/wiki/TOAST
https://www.postgresql.org/docs/current/storage-toast.html

The list of all the queries