From: | Michael Paquier <michael(at)paquier(dot)xyz> |
---|---|
To: | Andres Freund <andres(at)anarazel(dot)de> |
Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, "Tsunakawa, Takayuki" <tsunakawa(dot)takay(at)jp(dot)fujitsu(dot)com>, Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>, "tgl(at)sss(dot)pgh(dot)pa(dot)us" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "robertmhaas(at)gmail(dot)com" <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Temporary tables prevent autovacuum, leading to XID wraparound |
Date: | 2018-08-09 16:50:47 |
Message-ID: | 20180809165047.GK13638@paquier.xyz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Aug 09, 2018 at 02:29:54AM -0700, Andres Freund wrote:
> On 2018-08-09 09:00:29 +0200, Michael Paquier wrote:
>> Would you be fine if I add an extra note like what's in
>> BackendIdGetProc? Say "The result may be out of date quickly, so the
>> caller must be careful how to handle this information."
>
> That's a caveat, not a documentation of the memory ordering /
> concurrency.
I think that I am going to add this note anyway in the new routine.
> You somewhere need a comment to the effect of "We are
> guaranteed to see a recent enough value of ->tempNamespace because
> anybody creating a temporary table acquires a lock - serving as a memory
> barrier - during the creation of said table, after assigning the
> tempNamespace variable. At the same time, before considering dropping a
> temporary table as orphaned, we acquire a lock and recheck tempNamespace
> afterwards". Note that I'm not explaining the concrete model you have
> here, but the way you could explain a theoretical one.
Okay, here is an idea... When assigning the value I have now that:
+ /*
+ * Mark MyProc as owning this namespace which other processes can use to
+ * decide if a temporary namespace is in use or not. We assume that
+ * assignment of namespaceId is an atomic operation. Even if it is not,
+ * there is no visible temporary relations associated to it and the
+ * temporary namespace creation is not committed yet, so none of its
+ * contents should be seen yet if scanning pg_class or pg_namespace.
+ */
I actually have tried to mention what you are willing to see in the
comments with the last sentence. So that is awkward :)
I would propose to reword the last sentence of the patch as follows
then:
"Even if it is not atomic, the temporary relation which resulted in the
creation of this temporary namespace is still locked until the current
transaction commits, so it would not be accessible yet."
When resetting the value on abort I have that:
+ /*
+ * Reset the temporary namespace flag in MyProc. The creation of
+ * the temporary namespace has failed for some reason and should
+ * not be seen by other processes as it has not been committed
+ * yet, hence this would be fine even if not atomic, still we
+ * assume that it is an atomic assignment.
+ */
Hence I would propose the following wording for this part:
"Reset the temporary namespace flag in MyProc. We assume that this
operation is atomic, however it would be fine even if not atomic as the
temporary table which created this namespace is still locked until this
transaction aborts so it would not be visible yet."
Better ideas are of course welcome.
--
Michael
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2018-08-09 17:08:20 | Re: libpq should not look up all host addresses at once |
Previous Message | Andrew Dunstan | 2018-08-09 16:45:09 | Re: PATCH: pgbench - option to build using ppoll() for larger connection counts |