18
Local Cache
Temporary Tables
visible to only one session, so there is no point in using shared cache
exist within one session, so their loss in a crash is acceptable
Features
no locks required
memory is allocated on demand within temp_buffers
standard eviction algorithm
buffer ring mechanism is not used
Temporary tables are an exception to the general rule. Since temporary data
is visible to only one process, there is no need for them in the shared buffer
cache. Moreover, temporary data exist only within one session, so it does
not need to be protected against failures.
A lightweight local cache is used for temporary data.
Since the local cache is accessible to only one process, it does not require
locks. Memory is allocated on demand (within the limit set by the
temp_buffers parameter), since temporary tables are not used in all
sessions. The local cache uses a standard eviction algorithm.
At the physical level, temporary tables are stored similarly to regular tables.
The temp_tablespaces parameter specifies the tablespaces where
temporary objects (temporary tables and their indexes) will be created when
CREATE command does not explicitly specify a tablespace.
The temp_tablespaces parameter value can contain a list of tablespace
names. When this list contains more than one name, PostgreSQL randomly
selects one from the list when creating each temporary object. However, for
subsequent objects created within the same transaction, the tablespaces are
sorted sequentially. If the list contains an empty string (default value),
PostgreSQL will use the default tablespace for the current database.