Thread

  1. Re: [Proposal] Expose internal MultiXact member count function for efficient monitoring

    Naga Appani <nagnrik@gmail.com> — 2025-12-30T02:57:11Z

    On Sun, Dec 28, 2025 at 9:51 PM Michael Paquier <michael@paquier.xyz> wrote:
    > So, here is what I have in mind, split into independent pieces:
    > - Remove the existing type confusion with GetMultiXactInfo(), due to
    > how things have always been done in MultiXactMemberFreezeThreshold().
    > - Add macro MultiXactOffsetStorageSize(), to calculate the amount of
    > space used between two offsets.
    > - The main patch, with adjustments in comments, the test (no
    > non-ASCII characters in that, please).  One thing that was really
    > surprising is that you did not consider ROLE_PG_READ_ALL_STATS.  We
    > expect all the stats information to be hidden if a role is not granted
    > access to them, and this function should be no exception especially as
    > it relates to disk space usage like database or tablespace size
    > functions.
    >
    > Anyway, attached are all these updated pieces.  The doc edits are what
    > I have mentioned upthread, close to what you have suggested to me
    > offline.
    >
    > Comments?
    > --
    > Michael
    
    Thank you for patches, Michael! I've tested and everything works well:
    - All patches apply cleanly
    - Isolation test (multixact-stats) passes
    - Function correctly reports stats under heavy load
    
    Tested with significant multixact activity:
    ++++++++++++++++++++++++++++++++++++++++++++++
    postgres=# \x
    Expanded display is on.
    postgres=# SELECT
        to_char(num_mxids::bigint, 'FM999,999,999,999') AS num_mxids,
        to_char(num_members::bigint, 'FM999,999,999,999') AS num_members,
        to_char(members_size::bigint, 'FM999,999,999,999') AS members_size_bytes,
        pg_size_pretty(members_size) AS members_size_pretty,
        to_char(oldest_multixact::text::bigint, 'FM999,999,999,999') AS
    oldest_multixact
    FROM pg_get_multixact_stats();
    -[ RECORD 1 ]-------+------------------
    num_mxids           | 235,095,556
    num_members         | 14,435,701,862
    members_size_bytes  | 72,178,509,300
    members_size_pretty | 67 GB
    oldest_multixact    | 2
    ++++++++++++++++++++++++++++++++++++++++++++++
    
    After cleanup, the function properly resets:
    ++++++++++++++++++++++++++++++++++++++++++++++
    -[ RECORD 1 ]-------+-------------
    num_mxids           | 0
    num_members         | 0
    members_size_bytes  | 0
    members_size_pretty | 0 bytes
    oldest_multixact    | 235,095,558
    ++++++++++++++++++++++++++++++++++++++++++++++
    
    The oldest_multixact correctly advances to reflect the cleanup.
    
    Thanks for adding the pg_read_all_stats privilege check!
    
    I think this is ready for RFC.
    
    Best regards,
    Naga