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