11
Special schemas
Temporary tables
exist for the duration of the session or transaction
not logged (no recovery after a crash)
do not utilize the shared buffer cache
pg_temp_N schema
created automatically for temporary tables
pg_temp: a link to a specific temporary schema for the session
if not explicitly included in the path, implicitly included as the very first one
at the end of the session, all objects of the temporary schema are dropped;
the schema itself remains and is reused for other sessions
PostgreSQL can work with temporary tables. Temporary tables store data
that should only be available to the current session and only for as long as
the session is active (or even for the duration of a single transaction within
the session).
Temporary tables are unlogged. This means that if a crash occurs, the table
contents will be lost. Additionally, temporary table pages are never stored in
the shared buffer cache, residing in the internal memory of their backend
process instead. Thanks to that, temporary tables can be accessed a bit
more quickly than regular ones.
Temporary tables are organized using schemas. When a session is started,
a temporary schema named pg_temp_N (pg_temp_1, pg_temp_2, etc.) is
created for it. It can be accessed by the name pg_temp (without a number,
because the name will always refer to the temporary schema specific for the
session).
If pg_temp is not specified in the path, it is searched before all others.
Otherwise, you can specify its position in the path explicitly, like with
pg_catalog.
After the session ends, all objects belonging to the temporary schema are
dropped, and the schema itself remains to be reused later on.
There are other special schemas, more technical in nature.