Thread: what causes new temp schemas to be created
When a temp table is created I see a pg_temp_NNN (for example pg_temp_3, pg_toast_temp_3) schemas created when/why are additional temp schemas created( pg_temp_4/pg_toast_temp_4)? Ted
On Mon, Jul 10, 2023 at 7:18 AM Ted Toth <txtoth@gmail.com> wrote:
When a temp table is created I see a pg_temp_NNN (for example
pg_temp_3, pg_toast_temp_3) schemas created when/why are additional
temp schemas created( pg_temp_4/pg_toast_temp_4)?
Temporary schemas are isolated to the session they are created in. Hence, you get multiple temporary schemas if you have concurrent sessions using temporary objects.
David J.
On 7/10/23 09:20, David G. Johnston wrote:
IOW, temporary schemata are how Pg lets different sessions have temporary objects use the same name?
On Mon, Jul 10, 2023 at 7:18 AM Ted Toth <txtoth@gmail.com> wrote:When a temp table is created I see a pg_temp_NNN (for example
pg_temp_3, pg_toast_temp_3) schemas created when/why are additional
temp schemas created( pg_temp_4/pg_toast_temp_4)?Temporary schemas are isolated to the session they are created in. Hence, you get multiple temporary schemas if you have concurrent sessions using temporary objects.
IOW, temporary schemata are how Pg lets different sessions have temporary objects use the same name?
--
Born in Arizona, moved to Babylonia.
Born in Arizona, moved to Babylonia.
I don't see that the schema is removed when the session is over and I see other sessions come along later and use it. I'm assuming here that a session is started on connect and ended when the connection is closed. On Mon, Jul 10, 2023 at 9:21 AM David G. Johnston <david.g.johnston@gmail.com> wrote: > > On Mon, Jul 10, 2023 at 7:18 AM Ted Toth <txtoth@gmail.com> wrote: >> >> When a temp table is created I see a pg_temp_NNN (for example >> pg_temp_3, pg_toast_temp_3) schemas created when/why are additional >> temp schemas created( pg_temp_4/pg_toast_temp_4)? >> > > Temporary schemas are isolated to the session they are created in. Hence, you get multiple temporary schemas if you haveconcurrent sessions using temporary objects. > > David J.
On Mon, Jul 10, 2023 at 9:20 AM Ted Toth <txtoth@gmail.com> wrote:
I don't see that the schema is removed when the session is over and I
see other sessions come along later and use it. I'm assuming here that
a session is started on connect and ended when the connection is
closed.
The first time a session needs a temporary schema it is assigned one which is then immediately cleared out.
David J.
So it's an optimization to reuse existing but currently unused temp schemas, correct? On Mon, Jul 10, 2023 at 11:22 AM David G. Johnston <david.g.johnston@gmail.com> wrote: > > On Mon, Jul 10, 2023 at 9:20 AM Ted Toth <txtoth@gmail.com> wrote: >> >> I don't see that the schema is removed when the session is over and I >> see other sessions come along later and use it. I'm assuming here that >> a session is started on connect and ended when the connection is >> closed. >> > > The first time a session needs a temporary schema it is assigned one which is then immediately cleared out. > > David J.
Ted Toth <txtoth@gmail.com> writes: > So it's an optimization to reuse existing but currently unused temp > schemas, correct? Exactly. We could just destroy and recreate the old temp schema, but that seems to lead to useless catalog churn. Instead we just destroy any old contents, if there's an existing temp schema in the slot assigned to the current backend. regards, tom lane