Re: Proposal: Extending the PostgreSQL Protocol with Command Metadata

From: Andy Fan <zhihuifan1213(at)163(dot)com>
To: Kir Shatrov <sigkirs(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Proposal: Extending the PostgreSQL Protocol with Command Metadata
Date: 2025-08-18 23:55:10
Message-ID: 87cy8s423l.fsf@163.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Kir Shatrov <sigkirs(at)gmail(dot)com> writes:

Hi,

> ## Unlocking Greater Extensions
>
> Extensions leveraging this metadata protocol could allow to build things with very little overhead that are not possible
> today:
>
> - Multi-tenant applications tracking per-query resource consumption (buffer hits/misses, CPU/IO time)
> - Connection poolers making routing decisions based on server load
> - Performance monitoring without separate instrumentation queries
> - Applications implementing custom rate limiting based on DB metrics
> - Distributed tracing integration at the protocol level
>
> ## Why not session variables?
>
> You could argue this could be achieved by reading session variables after each query, but that quickly becomes not
> practical: leveraging session variables breaks multiplexing (e.g. PgBouncer) and hitting the server with yet another
> query when it's already busy just increases the number of incoming queries that it needs to handle.

Does pg_stat_statements [1] work for you? I think some differents
between pg_stat_statements and command level metrics are:

1. pg_stat_statements is a aggreated data and command level metrics is a
raw data for each statement.
2. the entries in pg_stat_statments in limitted by
pg_stat_statements.max.

But IMO we need some analysis or aggregated data on these metrics rather
than use the raw data, Could you explain more how to use these command
level metrics to make decision?

[1]
https://www.postgresql.org/docs/current/pgstatstatements.html#PGSTATSTATEMENTS-PG-STAT-STATEMENTS

--
Best Regards
Andy Fan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-08-19 00:07:23 Re: Potential deadlock in pgaio_io_wait()
Previous Message Jacob Champion 2025-08-18 23:43:46 Re: Support getrandom() for pg_strong_random() source