Many recently discussed features can make use of an extensible storage manager API. Namely, storage level compression and encryption [1], [2], [3], disk quota feature [4], SLRU storage changes [5], and any other features that may want to substitute PostgreSQL storage layer with their implementation (i.e. lazy_restore [6]).
Attached is a proposal to change smgr API to make it extensible. The idea is to add a hook for plugins to get control in smgr and define custom storage managers. The patch replaces smgrsw[] array and smgr_sw selector with smgr() function that loads f_smgr implementation.
As before it has only one implementation - smgr_md, which is wrapped into smgr_standard().
To create custom implementation, a developer needs to implement smgr API functions staticconststruct f_smgr smgr_custom = { .smgr_init = custominit, ... }
create a hook function
const f_smgr * smgr_custom(BackendId backend, RelFileNode rnode) { //Here we can also add some logic and chose which smgr to use based on rnode and backend return &smgr_custom; }
and finally set the hook: smgr_hook = smgr_custom;