|From:||Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>|
|Subject:||Protect syscache from bloating with negative cache entries|
|Views:||Raw Message | Whole Thread | Download mbox|
Hello, recently one of my customer stumbled over an immoderate
This is a known issue living on the Todo page in the PostgreSQL
> Fix memory leak caused by negative catcache entries
This patch addresses the two cases of syscache bloat by using
invalidation callback mechanism.
Overview of the patch
The bloat is caused by negative cache entries in catcaches. They
are crucial for performance but it is a problem that there's no
way to remove them. They last for the backends' lifetime.
The first patch provides a means to flush catcache negative
entries, then defines a relcache invalidation callback to flush
negative entries in syscaches for pg_statistic(STATRELATTINH) and
pg_attributes(ATTNAME, ATTNUM). The second patch implements a
syscache invalidation callback so that deletion of a schema
causes a flush for pg_class (RELNAMENSP).
Both of the aboves are not hard-coded and defined in cacheinfo
using additional four members.
Still, catcache can bloat by repeatedly accessing non-existent
table with unique names in a permanently-living schema but it
seems a bit too artificial (or malicious). Since such negative
entries don't have a trigger to remove, caps are needed to
prevent them from bloating syscaches, but the limits are hardly
seem reasonably determinable.
Defects or disadvantages
This patch scans over whole the target catcache to find negative
entries to remove and it might take a (comparably) long time on a
catcache with so many entries. By the second patch, unrelated
negative caches may be involved in flushing since they are keyd
by hashvalue, not by the exact key values.
The attached files are the following.
Negative entry flushing by relcache invalidation using
relcache invalidation callback.
Negative entry flushing by catcache invalidation using
catcache invalidation callback.
a test script for STATRELATTINH bloating.
a test script for RELNAMENSP bloating.
3 and 4 are used as the following,
./gen.pl | psql postgres > /dev/null
NTT Open Source Software Center
|Next Message||Etsuro Fujita||2016-12-19 12:05:49||Re: postgres_fdw bug in 9.6|
|Previous Message||Thomas Munro||2016-12-19 11:13:19||Re: Measuring replay lag|