mirror of
https://github.com/postgres/postgres.git
synced 2026-06-21 22:49:12 -04:00
Commit257c8231bfchanged pg_buffercache_pages() to materialize its output directly into a tuplestore. As a result, the function ended up trusting a caller-supplied RECORD descriptors. That could lead to crashes if the supplied row definition did not match the actual returned values, for example by passing bool Datums to tuplestore_putvalues() with an incompatible descriptor. Fix this by constructing the correct tuple descriptor for pg_buffercache_pages() and assigning it to rsinfo->setDesc after InitMaterializedSRF(). This restores the executor's tupledesc_match() verification, so incompatible caller-supplied row definitions are rejected with an error, as before commit257c8231bf. Bug: #19508 Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru> Author: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com> Discussion: https://postgr.es/m/19508-e5f188183279219b@postgresql.org
95 lines
3.6 KiB
SQL
95 lines
3.6 KiB
SQL
CREATE EXTENSION pg_buffercache;
|
|
|
|
select count(*) = (select setting::bigint
|
|
from pg_settings
|
|
where name = 'shared_buffers')
|
|
from pg_buffercache;
|
|
|
|
-- For pg_buffercache_os_pages, we expect at least one entry for each buffer
|
|
select count(*) >= (select setting::bigint
|
|
from pg_settings
|
|
where name = 'shared_buffers')
|
|
from pg_buffercache_os_pages;
|
|
|
|
select buffers_used + buffers_unused > 0,
|
|
buffers_dirty <= buffers_used,
|
|
buffers_pinned <= buffers_used
|
|
from pg_buffercache_summary();
|
|
|
|
SELECT count(*) > 0 FROM pg_buffercache_usage_counts() WHERE buffers >= 0;
|
|
|
|
-- Check that the functions / views can't be accessed by default. To avoid
|
|
-- having to create a dedicated user, use the pg_database_owner pseudo-role.
|
|
SET ROLE pg_database_owner;
|
|
SELECT * FROM pg_buffercache;
|
|
SELECT * FROM pg_buffercache_os_pages;
|
|
SELECT * FROM pg_buffercache_pages() AS p (wrong int);
|
|
SELECT * FROM pg_buffercache_summary();
|
|
SELECT * FROM pg_buffercache_usage_counts();
|
|
RESET role;
|
|
|
|
-- Check that pg_monitor is allowed to query view / function
|
|
SET ROLE pg_monitor;
|
|
SELECT count(*) > 0 FROM pg_buffercache;
|
|
SELECT count(*) > 0 FROM pg_buffercache_os_pages;
|
|
SELECT buffers_used + buffers_unused > 0 FROM pg_buffercache_summary();
|
|
SELECT count(*) > 0 FROM pg_buffercache_usage_counts();
|
|
SELECT *
|
|
FROM pg_buffercache_pages() AS p
|
|
(bufferid integer, relfilenode oid, reltablespace oid, reldatabase oid,
|
|
relforknumber smallint, relblocknumber bigint, isdirty text,
|
|
usagecount smallint)
|
|
LIMIT 1;
|
|
RESET role;
|
|
|
|
|
|
------
|
|
---- Test pg_buffercache_evict* and pg_buffercache_mark_dirty* functions
|
|
------
|
|
|
|
CREATE ROLE regress_buffercache_normal;
|
|
SET ROLE regress_buffercache_normal;
|
|
|
|
-- These should fail because they need to be called as SUPERUSER
|
|
SELECT * FROM pg_buffercache_evict(1);
|
|
SELECT * FROM pg_buffercache_evict_relation(1);
|
|
SELECT * FROM pg_buffercache_evict_all();
|
|
SELECT * FROM pg_buffercache_mark_dirty(1);
|
|
SELECT * FROM pg_buffercache_mark_dirty_relation(1);
|
|
SELECT * FROM pg_buffercache_mark_dirty_all();
|
|
|
|
RESET ROLE;
|
|
|
|
-- These should return nothing, because these are STRICT functions
|
|
SELECT * FROM pg_buffercache_evict(NULL);
|
|
SELECT * FROM pg_buffercache_evict_relation(NULL);
|
|
SELECT * FROM pg_buffercache_mark_dirty(NULL);
|
|
SELECT * FROM pg_buffercache_mark_dirty_relation(NULL);
|
|
|
|
-- These should fail because they are not called by valid range of buffers
|
|
-- Number of the shared buffers are limited by max integer
|
|
SELECT 2147483647 max_buffers \gset
|
|
SELECT * FROM pg_buffercache_evict(-1);
|
|
SELECT * FROM pg_buffercache_evict(0);
|
|
SELECT * FROM pg_buffercache_evict(:max_buffers);
|
|
SELECT * FROM pg_buffercache_mark_dirty(-1);
|
|
SELECT * FROM pg_buffercache_mark_dirty(0);
|
|
SELECT * FROM pg_buffercache_mark_dirty(:max_buffers);
|
|
|
|
-- These should fail because they don't accept local relations
|
|
CREATE TEMP TABLE temp_pg_buffercache();
|
|
SELECT * FROM pg_buffercache_evict_relation('temp_pg_buffercache');
|
|
SELECT * FROM pg_buffercache_mark_dirty_relation('temp_pg_buffercache');
|
|
DROP TABLE temp_pg_buffercache;
|
|
|
|
-- These shouldn't fail
|
|
SELECT buffer_evicted IS NOT NULL FROM pg_buffercache_evict(1);
|
|
SELECT buffers_evicted IS NOT NULL FROM pg_buffercache_evict_all();
|
|
CREATE TABLE shared_pg_buffercache();
|
|
SELECT buffers_evicted IS NOT NULL FROM pg_buffercache_evict_relation('shared_pg_buffercache');
|
|
SELECT buffers_dirtied IS NOT NULL FROM pg_buffercache_mark_dirty_relation('shared_pg_buffercache');
|
|
DROP TABLE shared_pg_buffercache;
|
|
SELECT pg_buffercache_mark_dirty(1) IS NOT NULL;
|
|
SELECT pg_buffercache_mark_dirty_all() IS NOT NULL;
|
|
|
|
DROP ROLE regress_buffercache_normal;
|