"cache reference leak" issue happened when using sepgsql module

Started by Michael Luoover 5 years ago2 messages
#1Michael Luo
mkluo666@outlook.com
1 attachment(s)

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.

Attachments:

sepgsql_bug_fix.patchapplication/octet-stream; name=sepgsql_bug_fix.patchDownload
diff --git a/contrib/sepgsql/dml.c b/contrib/sepgsql/dml.c
index 2892346..22dac36 100644
--- 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;
 
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Luo (#1)
Re: "cache reference leak" issue happened when using sepgsql module

Michael Luo <mkluo666@outlook.com> writes:

When using sepgsql module, I got warning "WARNING: cache reference leak”.
...
The patch attached to fix this issue, please check it.

Right you are, fix pushed.

regards, tom lane