From: | Noah Misch <noah(at)leadboat(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | pgstat_heap() consults freed memory |
Date: | 2014-06-27 14:57:04 |
Message-ID: | 20140627145704.GA1353741@tornado.leadboat.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
pgstat_heap() creates a BufferAccessStrategy and attaches it to a
HeapScanDesc. It continues to use that strategy after calling heap_endscan(),
which frees the strategy. This is only a risk when the table contains empty
pages at the end. I get a crash in an assert-enabled build with this test
procedure, after disabling autovacuum:
-- session 1
create table t (c) as select * from generate_series(1,20000);
delete from t where c > 10000;
-- session 2
begin; lock table t in access share mode;
-- session 1
vacuum t;
-- restart PostgreSQL to clear shared buffers
-- session 3
select * from pgstattuple('t');
The simplest fix is to move the heap_endscan() call past the last use of the
strategy. However, I don't think this function ought to be creating a
strategy explicitly. It should use the one that initscan() creates, if any.
--
Noah Misch
EnterpriseDB http://www.enterprisedb.com
Attachment | Content-Type | Size |
---|---|---|
pgstat_heap-freed-memory-v1.patch | text/plain | 1.8 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Ryan Johnson | 2014-06-27 15:17:12 | Re: Index-only scans and non-MVCC snapshots |
Previous Message | Andres Freund | 2014-06-27 14:41:01 | Re: Index-only scans and non-MVCC snapshots |