pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedPITR and Temp Tables
6+ messages / 4 participants
[nested] [flat]
* PITR and Temp Tables
@ 2022-04-20 12:17 Huan Ruan <leohuanruan@gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Huan Ruan @ 2022-04-20 12:17 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hi All
Let's say at T0 a database has N session based temp tables. They would have
corresponding records in the catalog tables like pg_class and pg_attribute
that are visible to other sessions.
At T1, I do a PITR to T0. That recovered database should not have those
temp tables because the sessions they were created in are not present. My
question is what events trigger the deletion of those temp tables' catalog
records (e.g. pg_class and pg_attribute etc.) in the recovered database?
Thanks
Huan
^ permalink raw reply [nested|flat] 6+ messages in thread
* RE: PITR and Temp Tables
@ 2022-04-20 12:45 Patrick FICHE <Patrick.Fiche@aqsacom.com>
parent: Huan Ruan <leohuanruan@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Patrick FICHE @ 2022-04-20 12:45 UTC (permalink / raw)
To: Huan Ruan <leohuanruan@gmail.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
From: Huan Ruan <leohuanruan@gmail.com>
Sent: Wednesday, April 20, 2022 2:18 PM
To: pgsql-general@lists.postgresql.org
Subject: PITR and Temp Tables
Hi All
Let's say at T0 a database has N session based temp tables. They would have corresponding records in the catalog tables like pg_class and pg_attribute that are visible to other sessions.
At T1, I do a PITR to T0. That recovered database should not have those temp tables because the sessions they were created in are not present. My question is what events trigger the deletion of those temp tables' catalog records (e.g. pg_class and pg_attribute etc.) in the recovered database?
Thanks
Huan
Hi,
My guess is that temp table entries will still be in your catalog until you do a VACUUM FULL of the pg_class / pg_attribute tables.
But you should not care about these entries if these tables are vacuumed at regular intervals.
Regards,
Patrick
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: PITR and Temp Tables
@ 2022-04-20 13:02 Huan Ruan <leohuanruan@gmail.com>
parent: Patrick FICHE <Patrick.Fiche@aqsacom.com>
0 siblings, 0 replies; 6+ messages in thread
From: Huan Ruan @ 2022-04-20 13:02 UTC (permalink / raw)
To: Patrick FICHE <Patrick.Fiche@aqsacom.com>; +Cc: pgsql-general@lists.postgresql.org
Hi Patrick
Thanks for your reply.
>
>
> My guess is that temp table entries will still be in your catalog until
> you do a VACUUM FULL of the pg_class / pg_attribute tables.
>
> But you should not care about these entries if these tables are vacuumed
> at regular intervals.
>
What I observed in one instance seems* to be like this - by the time I
connected to the recovered database (as soon as I could), an autovacuuum
has run on those catalog tables and they don't have those temp table
entries. Normally, autovacuum removes dead tuples, but those temp table
records are live tuples at T0. So if it was autovacuum that removed them in
the recovered database, were they live or dead tuples? If they are dead,
what did the deletion that made them dead?
*I would like to confirm to be 100% sure but was wondering if I can get an
explanation here.
Regards
Huan
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: PITR and Temp Tables
@ 2022-04-20 13:36 Tom Lane <tgl@sss.pgh.pa.us>
parent: Huan Ruan <leohuanruan@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Tom Lane @ 2022-04-20 13:36 UTC (permalink / raw)
To: Huan Ruan <leohuanruan@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
Huan Ruan <leohuanruan@gmail.com> writes:
> Let's say at T0 a database has N session based temp tables. They would have
> corresponding records in the catalog tables like pg_class and pg_attribute
> that are visible to other sessions.
> At T1, I do a PITR to T0. That recovered database should not have those
> temp tables because the sessions they were created in are not present. My
> question is what events trigger the deletion of those temp tables' catalog
> records (e.g. pg_class and pg_attribute etc.) in the recovered database?
Those records will still be there in the catalogs, yes.
Cleaning out the contents of a temporary schema is not the responsibility
of the WAL/recovery system. It's done by live backends at two times:
1. A session that has used a temp schema will normally clean out the
contained objects when it exits.
2. As a backstop in case #1 fails, a session that is about to begin using
a temp schema will clean out any surviving contents.
So if you rewound to a point where some temp objects exist, it'd be the
responsibility of the first session that wants to use a given temp schema
to clean out those objects.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: PITR and Temp Tables
@ 2022-04-20 14:04 Greg Stark <stark@mit.edu>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Greg Stark @ 2022-04-20 14:04 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Huan Ruan <leohuanruan@gmail.com>; pgsql-general@lists.postgresql.org
There actually is a third backstop if no other session ever connects to
that temp schema and cleans them out.
Eventually autovacuum notices that they would need a vacuum "to prevent
wraparound". It can't actually did the vacuum on temp tables but if there's
no session attached to the temp schema it drops them.
This normally takes quite a long time to reach so if you routinely have
sessions using temp schemas it's unlikely to happen. But if you only use
temp schemas manually then eventually it would.
On Wed., Apr. 20, 2022, 09:37 Tom Lane, <tgl@sss.pgh.pa.us> wrote:
> Huan Ruan <leohuanruan@gmail.com> writes:
> > Let's say at T0 a database has N session based temp tables. They would
> have
> > corresponding records in the catalog tables like pg_class and
> pg_attribute
> > that are visible to other sessions.
>
> > At T1, I do a PITR to T0. That recovered database should not have those
> > temp tables because the sessions they were created in are not present. My
> > question is what events trigger the deletion of those temp tables'
> catalog
> > records (e.g. pg_class and pg_attribute etc.) in the recovered database?
>
> Those records will still be there in the catalogs, yes.
>
> Cleaning out the contents of a temporary schema is not the responsibility
> of the WAL/recovery system. It's done by live backends at two times:
>
> 1. A session that has used a temp schema will normally clean out the
> contained objects when it exits.
>
> 2. As a backstop in case #1 fails, a session that is about to begin using
> a temp schema will clean out any surviving contents.
>
> So if you rewound to a point where some temp objects exist, it'd be the
> responsibility of the first session that wants to use a given temp schema
> to clean out those objects.
>
> regards, tom lane
>
>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: PITR and Temp Tables
@ 2022-04-20 21:12 Huan Ruan <leohuanruan@gmail.com>
parent: Greg Stark <stark@mit.edu>
0 siblings, 0 replies; 6+ messages in thread
From: Huan Ruan @ 2022-04-20 21:12 UTC (permalink / raw)
To: Greg Stark <stark@mit.edu>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general@lists.postgresql.org
Many thanks for the explanation, Tom and Greg. That all makes sense.
Cheers
Huan
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2022-04-20 21:12 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 12:17 PITR and Temp Tables Huan Ruan <leohuanruan@gmail.com>
2022-04-20 12:45 ` Patrick FICHE <Patrick.Fiche@aqsacom.com>
2022-04-20 13:02 ` Huan Ruan <leohuanruan@gmail.com>
2022-04-20 13:36 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-04-20 14:04 ` Greg Stark <stark@mit.edu>
2022-04-20 21:12 ` Huan Ruan <leohuanruan@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox