
tracks index pages, not free space on pages): 1/ Index free bytes set to NULL 2/ Comment added to the README briefly mentioning the index business 3/ Columns reordered more logically 4/ 'Blockid' column removed 5/ Free bytes column renamed to just 'bytes' instead of 'blockfreebytes' Mark Kirkwood
101 lines
3.5 KiB
Plaintext
101 lines
3.5 KiB
Plaintext
Pg_freespacemap - Real time queries on the free space map (FSM).
|
|
---------------
|
|
|
|
This module consists of a C function 'pg_freespacemap()' that returns
|
|
a set of records, and a view 'pg_freespacemap' to wrapper the function.
|
|
|
|
The module provides the ability to examine the contents of the free space
|
|
map, without having to restart or rebuild the server with additional
|
|
debugging code.
|
|
|
|
By default public access is REVOKED from both of these, just in case there
|
|
are security issues lurking.
|
|
|
|
|
|
Installation
|
|
------------
|
|
|
|
Build and install the main Postgresql source, then this contrib module:
|
|
|
|
$ cd contrib/pg_freespacemap
|
|
$ gmake
|
|
$ gmake install
|
|
|
|
|
|
To register the functions:
|
|
|
|
$ psql -d <database> -f pg_freespacemap.sql
|
|
|
|
|
|
Notes
|
|
-----
|
|
|
|
The definition of the columns exposed in the view is:
|
|
|
|
Column | references | Description
|
|
----------------+----------------------+------------------------------------
|
|
reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
|
|
reldatabase | pg_database.oid | Database for the relation.
|
|
relfilenode | pg_class.relfilenode | Refilenode of the relation.
|
|
relblocknumber | | Offset of the page in the relation.
|
|
bytes | | Free bytes in the block/page, or NULL
|
|
| | for an index page (see below).
|
|
|
|
|
|
There is one row for each page in the free space map.
|
|
|
|
Because the map is shared by all the databases, there are pages from
|
|
relations not belonging to the current database.
|
|
|
|
The free space map can contain pages for btree indexes if they were emptied
|
|
by a vacuum process. The bytes field is set to NULL in this case.
|
|
|
|
When the pg_freespacemap view is accessed, internal free space map locks are
|
|
taken, and a copy of the map data is made for the view to display.
|
|
This ensures that the view produces a consistent set of results, while not
|
|
blocking normal activity longer than necessary. Nonetheless there
|
|
could be some impact on database performance if this view is read often.
|
|
|
|
|
|
Sample output
|
|
-------------
|
|
|
|
regression=# \d pg_freespacemap
|
|
View "public.pg_freespacemap"
|
|
Column | Type | Modifiers
|
|
----------------+---------+-----------
|
|
reltablespace | oid |
|
|
reldatabase | oid |
|
|
relfilenode | oid |
|
|
relblocknumber | bigint |
|
|
bytes | integer |
|
|
View definition:
|
|
SELECT p.reltablespace, p.reldatabase, p.relfilenode, p.relblocknumber, p.bytes
|
|
FROM pg_freespacemap() p(reltablespace oid, reldatabase oid, relfilenode oid, relblocknumber bigint, bytes integer);
|
|
|
|
regression=# SELECT c.relname, m.relblocknumber, m.bytes
|
|
FROM pg_freespacemap m INNER JOIN pg_class c
|
|
ON c.relfilenode = m.relfilenode LIMIT 10;
|
|
relname | relblocknumber | bytes
|
|
------------------------+----------------+--------
|
|
sql_features | 5 | 2696
|
|
sql_implementation_info | 0 | 7104
|
|
sql_languages | 0 | 8016
|
|
sql_packages | 0 | 7376
|
|
sql_sizing | 0 | 6032
|
|
pg_authid | 0 | 7424
|
|
pg_toast_2618 | 13 | 4588
|
|
pg_toast_2618 | 12 | 1680
|
|
pg_toast_2618 | 10 | 1436
|
|
pg_toast_2618 | 7 | 1136
|
|
(10 rows)
|
|
|
|
regression=#
|
|
|
|
|
|
Author
|
|
------
|
|
|
|
* Mark Kirkwood <markir@paradise.net.nz>
|
|
|