what causes new temp schemas to be created

Started by Ted Tothalmost 3 years ago7 messagesgeneral
Jump to latest
#1Ted Toth
txtoth@gmail.com

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

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Ted Toth (#1)
Re: what causes new temp schemas to be created

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.

#3Ron
ronljohnsonjr@gmail.com
In reply to: David G. Johnston (#2)
Re: what causes new temp schemas to be created

On 7/10/23 09:20, David G. Johnston 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 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.

#4Ted Toth
txtoth@gmail.com
In reply to: David G. Johnston (#2)
Re: what causes new temp schemas to be created

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:

Show quoted text

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.

#5David G. Johnston
david.g.johnston@gmail.com
In reply to: Ted Toth (#4)
Re: what causes new temp schemas to be created

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.

#6Ted Toth
txtoth@gmail.com
In reply to: David G. Johnston (#5)
Re: what causes new temp schemas to be created

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:

Show quoted text

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.

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ted Toth (#6)
Re: what causes new temp schemas to be created

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