"cache reference leak" issue happened when using sepgsql module
Michael Luo <mkluo666@outlook.com>
From: Michael Luo <mkluo666@outlook.com>
To: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Cc: michael luo <zhengcheng.luo@ww-it.cn>
Date: 2020-04-16T13:46:12Z
Lists: pgsql-hackers
Attachments
- sepgsql_bug_fix.patch (application/octet-stream) patch
Hi !
When using sepgsql module, I got warning "WARNING: cache reference leak”.
```
postgres=# UPDATE range_parted set c = 95 WHERE a = 'b' and b > 10 and c > 100 returning (range_parted), *;
WARNING: cache reference leak: cache pg_attribute (7), tuple 38/54 has count 1
WARNING: cache reference leak: cache pg_attribute (7), tuple 39/56 has count 1
WARNING: cache reference leak: cache pg_attribute (7), tuple 53/51 has count 1
WARNING: cache reference leak: cache pg_attribute (7), tuple 53/50 has count 1
range_parted | a | b | c | d | e
---------------+---+----+----+----+---
(b,15,95,16,) | b | 15 | 95 | 16 |
(b,17,95,19,) | b | 17 | 95 | 19 |
(2 rows)
UPDATE 2
postgres=#
```
I am using the codes of Postgres REL_12_STABLE branch.
This issue can be reproduced by the SQLs below, and I test that on CentOS7 with “permissive” mode of SeLinux.
```
CREATE TABLE range_parted (a text, b bigint, c numeric, d int, e varchar) PARTITION BY RANGE (b);
CREATE TABLE part_b_10_b_20 (e varchar, c numeric, a text, b bigint, d int) PARTITION BY RANGE (c);
ALTER TABLE range_parted ATTACH PARTITION part_b_10_b_20 FOR VALUES FROM (10) TO (20);
CREATE TABLE part_c_100_200 (e varchar, c numeric, a text, b bigint, d int);
ALTER TABLE part_c_100_200 DROP COLUMN e, DROP COLUMN c, DROP COLUMN a;
ALTER TABLE part_c_100_200 ADD COLUMN c numeric, ADD COLUMN e varchar, ADD COLUMN a text;
ALTER TABLE part_c_100_200 DROP COLUMN b;
ALTER TABLE part_c_100_200 ADD COLUMN b bigint;
CREATE TABLE part_c_1_100 (e varchar, d int, c numeric, b bigint, a text);
ALTER TABLE part_b_10_b_20 ATTACH PARTITION part_c_1_100 FOR VALUES FROM (1) TO (100);
ALTER TABLE part_b_10_b_20 ATTACH PARTITION part_c_100_200 FOR VALUES FROM (100) TO (200);
\set init_range_parted 'truncate range_parted; insert into range_parted VALUES(''b'', 12, 96, 1), (''b'', 13, 97, 2), (''b'', 15, 105, 16), (''b'', 17, 105, 19)'
:init_range_parted;
UPDATE range_parted set c = 95 WHERE a = 'b' and b > 10 and c > 100 returning (range_parted), *;
```
The patch attached to fix this issue, please check it.
```
--- a/contrib/sepgsql/dml.c
+++ b/contrib/sepgsql/dml.c
@@ -69,7 +69,10 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
continue;
if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
+ {
+ ReleaseSysCache(tuple);
continue;
+ }
index = attno - FirstLowInvalidHeapAttributeNumber;
````
骆政丞 / Michael Luo
成都文武信息技术有限公司 / ChengDu WenWu Information Technology Co.,Ltd.
地址:成都高新区天府软件园 D 区 5 栋 1705 官网:http://w3.ww-it.cn.
Commits
-
Fix cache reference leak in contrib/sepgsql.
- fc576b7c4f3a 13.0 landed
- f4a42005613b 10.13 landed
- cc2737ab0312 11.8 landed
- 687e566b90f3 12.3 landed
- 46b1b6379a32 9.5.22 landed
- 3cdf2421a299 9.6.18 landed