sequence cache is kept forever - Mailing list pgsql-hackers

From Tomas Vondra
Subject sequence cache is kept forever
Date
Msg-id 8ac85deb-dec1-f0d8-abe0-d0d348471e8f@enterprisedb.com
Whole thread Raw
Responses Re: sequence cache is kept forever
List 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



pgsql-hackers by date:

Previous
From: wenjing
Date:
Subject: Re: [Proposal] Global temporary tables
Next
From: "David G. Johnston"
Date:
Subject: Re: update with no changes