RE: Temporary tables prevent autovacuum, leading to XID wraparound

Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>

From: "Tsunakawa, Takayuki" <tsunakawa.takay@jp.fujitsu.com>
To: 'Robert Haas' <robertmhaas@gmail.com>
Cc: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2018-02-05T03:10:17Z
Lists: pgsql-hackers

Attachments

From: Robert Haas [mailto:robertmhaas@gmail.com]
> Temporary tables contain XIDs, so they need to be vacuumed for XID
> wraparound.  Otherwise, queries against those tables by the session
> that created them could yield wrong answers.  However, autovacuum
> can't perform that vacuuming; it would have to be done by the session.
> I think we should consider having backends try to remove their
> temporary schema on startup; then, if a temp table in a backend is old
> enough that it's due for vacuum for wraparound, have autovacuum kill
> the connection.  The former is necessary to prevent sessions from
> being killed on account of temp tables they "inherited" from a backend
> that didn't exit cleanly.

The attached patch does the former.  The small change in autovacuum.c is mainly for autovac launcher and background workers which don't connect to a database.  I'll add this to the next CF.  I'd like this to be back-patched.

I didn't do the latter, because killing the connection seemed a bit overkill.  If we're going to do it, then we should also kill the connection which is preventing vacuum regardless of whether it has temporary tables in its session.

Regards
Takayuki Tsunakawa



Commits

  1. Clarify comment about assignment and reset of temp namespace ID in MyProc

  2. Make autovacuum more aggressive to remove orphaned temp tables

  3. Don't count background workers against a user's connection limit.