PostgreSQL Extention for buffer cache manipulation.
buffercache_tools allows you to change buffers of various postgres objects, such as:
- Relation
- Relation fork
- Database
- Tablespace
It is possible to clear and mark dirty specific buffers.
Also, buffercache_tools allows you to read a specific page of a relation into the buffer cache and see information about all buffers of a specific relation.
This extension supports building with make and meson. It is necessary that the postgres bin directory is specified in the PATH environment variable. Alternatively, you can also specify the absolute directory of the client application yourself.
make installor
make PG_CONFIG=postgres_directory/bin/pg_config installmeson build
cd build
ninja installor
meson build -Dpg_config=postgres_directory/bin/pg_config
cd build
ninja installThere are 5 buffer change functions with different coverages:
- pg_change_buffer()
- pg_change_relation_fork_buffers()
- pg_change_relation_buffers()
- pg_change_database_buffers()
- pg_change_tablespace_buffers()
- Buffer change mode (In the source code it's called "buffer processing function").
- The identifier of the object whose buffers need to be modified (for example oid for pg_change_database_buffers()).
- Arguments for the corresponding buffer modification mode.
- mark_dirty - mark buffer dirty. Arguments: not required.
- flush - Write buffer page to disk without drop. Arguments: not required.
- change_spcoid - change tablespace oid. Arguments: Tablespace Oid.
- change_dboid - change database oid. Arguments: Database Oid.
- change_relnumber - change relnumber. Arguments: relnumber relations.
- change_forknum - change fork number. Arguments: Fork name in text format ('main', 'fsm', 'vm', 'init').
- change_blocknum - change block number. Arguments: block number.
pg_change_buffer('mark_dirty', 400);
pg_change_buffer('flush', 400);
pg_change_buffer('change_spcoid', 400, 1253);
pg_change_buffer('change_dboid', 400, 154);
pg_change_buffer('change_relnumber', 400, 254);
pg_change_buffer('change_forknum', 400, 'main');
pg_change_buffer('change_blocknum', 400, 34252);
pg_change_relation_fork_buffers('change_blocknum', 'test_table', 'main', 34252);
pg_change_relation_buffers('change_blocknum', 'test_table', 34252);
pg_change_database_buffers('change_blocknum', 4321, 34252);
pg_change_tablespace_buffers('change_blocknum', 5421, 34252);If the function was executed successfully, the output value will be true.
SELECT * FROM pg_change_relation_fork_buffers('mark_dirty', 'test_table', 'main');
pg_change_relation_fork_buffers
---------------------------------
tInformation about temporary table buffers can only be viewed, but not changed.
Show information about buffers from the buffer cache that belong to a specific relation.
SELECT * FROM pg_show_relation_buffers('test_table');
buffernum | blocknum | dirty | usagecount | pinning | fork
-----------+----------+-------+------------+---------+------
4487 | 2 | t | 2 | 0 | fsm
4488 | 1 | t | 2 | 0 | fsm
4489 | 0 | t | 2 | 0 | fsm
4490 | 0 | t | 2 | 0 | vm
4491 | 0 | t | 1 | 0 | mainThe standard pg_buffercache extension also has a function for displaying information about buffers in the buffer cache, but pg_show_relation_buffers() will also let you see information about local buffers of temporary tables that exist only in the current session.
SELECT * FROM pg_show_relation_buffers('test_table');
buffernum | blocknum | dirty | usagecount | pinning | fork
-----------+----------+-------+------------+---------+------
-1 | 0 | t | 2 | 0 | main
-2 | 0 | t | 2 | 0 | vm
-3 | 0 | t | 2 | 0 | fsm
-4 | 1 | t | 2 | 0 | fsm
-5 | 2 | t | 2 | 0 | fsmShow information about specific buffer from the buffer cache. pg_show_buffer() does not supported local buffers.
SELECT * FROM pg_show_buffer(1);
blocknum | fork | relnumber | dboid | spcoid | dirty | usagecount | pinning
----------+------+-----------+-------+--------+-------+------------+---------
0 | main | 1262 | 0 | 1664 | f | 5 | 0Read a specific page of a specific relation into the buffer cache. Returns the number of the filled buffer.
SELECT pg_read_page_into_buffer('test', 'main', 0);
pg_read_page_into_buffer
--------------------------
5074To run the test suite, execute:
make installcheck or
cd build
ninja test after installation.