Skip to content

pg_dbsm

track database size

pg_dbsm · track database size

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100425pg_dbsmpg_dbsm0.0.1STATUnknownC

Usage

Sources:

pg_dbsm 0.0.1 is a background-worker extension that periodically records the size of every database in the cluster. The worker connects to one configured database, creates an unqualified dbsm table there, and appends each database name, collection timestamp, total size, and size increment.

Configure the worker

shared_preload_libraries = 'pg_dbsm'
dbsm.database = 'postgres'
dbsm.naptime = 86400

Restart PostgreSQL after adding pg_dbsm to shared_preload_libraries. dbsm.database selects the storage database and defaults to postgres; dbsm.naptime is the collection interval in seconds and defaults to 86400. Then inspect the worker-created table in that database:

CREATE EXTENSION pg_dbsm;

SELECT datname, created, datsize, incsize
FROM dbsm
ORDER BY created DESC;

Ownership and failure behavior

The version 0.0.1 installation SQL is effectively empty: CREATE EXTENSION neither registers the background worker nor creates or owns the dbsm table. Preloading the library is what registers the worker, and the worker creates the table and index. Consequently, dropping the extension does not stop a still-preloaded library or clean up those objects.

The first row for each database has a null incsize, not zero: the source tests m.datsize = NULL, which can never be true, and then subtracts the missing previous value. Account for that when reporting growth.

The source configures the worker not to restart automatically after failure. Monitor its process and PostgreSQL log, protect the central table, and define retention because it grows indefinitely. The project has no published modern compatibility matrix; verify this old C background-worker code on the exact PostgreSQL major version before production use.

Table reader