patternsqlMinor
Where temp table data goes after creation?
Viewed 0 times
aftertempwheregoesdatatablecreation
Problem
As far as I can understand
But as I have created a temp table immediately files gets created for it inside
So I would appreciate help on several questions.
-
What happens with
a. temp table data if
b. temp table data if
-
Is there any case when not enough
temp_buffers setting serve for storing temp tables data.But as I have created a temp table immediately files gets created for it inside
PGDATA along with the main database.So I would appreciate help on several questions.
-
What happens with
a. temp table data if
temp_buffers is enough to store temp table data?b. temp table data if
temp_buffers is not enough to store temp table data?-
Is there any case when not enough
temp_buffers setting ends up spilling to pgsql_tmp?Solution
Entries in
The data written to these temporary tables will be stored in
If
Is there any case when not enough temp_buffers setting ends up spilling to pgsql_tmp?
No, never. Explicit temporary tables are stored in the regular database directory with the visible
Please do not create or drop temporary tables frequently in postgresql (dozens of times per second). This causes bloat on the system catalog and thus slows down any queries. Temporary tables are not "free" in postgresql.
pg_class, pg_attributes (and other related data in pg_catalog) along with empty related files are always created during every create temp table. I cannot refer to one place in the postgresql source code where this behavior would be clearly visible. File creation is very far from create temp table. It's possible to start reading from hereThe data written to these temporary tables will be stored in
temp_buffers, a special memory structure in the backend private memory. Works like shared_buffers, but much simpler, because we don't care about concurrent access and recovery of such temporary data after a crash.If
temp_buffers is not enough for data - old pages within temp_buffers area will be evicted and written to corresponding relation files.Is there any case when not enough temp_buffers setting ends up spilling to pgsql_tmp?
No, never. Explicit temporary tables are stored in the regular database directory with the visible
t_ prefix in filenames (like $PGDATA/base/13709/t3_226351).Please do not create or drop temporary tables frequently in postgresql (dozens of times per second). This causes bloat on the system catalog and thus slows down any queries. Temporary tables are not "free" in postgresql.
Context
StackExchange Database Administrators Q#305241, answer score: 6
Revisions (0)
No revisions yet.