sequence cache is kept forever

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: sequence cache is kept forever
Date: 2021-11-19 17:33:14
Message-ID: 8ac85deb-dec1-f0d8-abe0-d0d348471e8f@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While working on a patch, I noticed that we never clean the cache of
sequence values, i.e. seqhashtab in sequence.c. That is, once we create
an entry for a sequence (by calling nextval), it will stay forever
(until the backend terminates). Even if the sequence gets dropped, the
entry stays behind.

The SeqTableData entries are fairly small (~30B), but even considering
that it's still a memory leak. Not an issue for common workloads, which
use just a handful of sequences, but sometimes people create a lot of
temporary objects, including sequences.

Or what happens when a connection calls nextval() on a sequence, the
sequence gets dropped, the Oid gets reused for new sequence, and then we
call nextval() again? Seems like it might cause various issues with
returning bogus values from stale cache.

Admittedly, it doesn't seem like a critical issue - it's been like this
since 2002 (a2597ef179) [1] which separated the sequence cache from
relcache, to address issues with locking.

[1]
https://www.postgresql.org/message-id/flat/23899.1022076750%40sss.pgh.pa.us

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2021-11-19 17:37:52 Re: update with no changes
Previous Message wenjing 2021-11-19 17:31:09 Re: [Proposal] Global temporary tables