Skip to content

Feature: support safe operation with automatic dirty pages check #4

@DKroot

Description

@DKroot

pg_buffercache provides dirty flag implementation which could be checked like this:

-- Cache, ordered by the number of buffers
SELECT pn.nspname AS schema, pc.relname, count(1) AS buffers, sum(pb.isdirty :: INT) AS dirty_pages
FROM pg_buffercache pb
JOIN pg_class pc ON pb.relfilenode = pg_relation_filenode(pc.oid) --
    AND pb.reldatabase IN(0,
                          (SELECT oid
                           FROM pg_database
                           WHERE datname = current_database()))
JOIN pg_namespace pn ON pn.oid = pc.relnamespace
GROUP BY pc.relname, pn.nspname
ORDER BY buffers DESC;

It'd be nice to operate pg_drop_rel_cache() safely, that is not to clear the cache if any pages are dirty. You can return result and/or some messages to indicate this outcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions