Thread

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix PQdescribePrepared with more than 7498 params

  1. Add ParameterDescription message to libpq frontend long message types

    Ning Sun <classicning@gmail.com> — 2026-04-01T06:32:17Z

    Hi,
    
    I'm maintaining a Rust library pgwire to implement postgres wire 
    protocol in rust. While doing a corner case test, I noticed the 
    inconsistency for ParameterDescription between backend and frontend.
    
    The backend allows up to 65535 parameters in a prepared statement. But 
    when running Describe on the statement, there is a size limit of 30000 
    bytes for ParameterDescription on the frontend. This means we can only 
    describe statements with at most ~7500 parameters. For statements exceed 
    the limit, it ends up with error about the message size.
    
    This patch simply adds ParameterDescription to VALID_LONG_MESSAGE_TYPE 
    whitelist to remove the cap.
    
    
  2. Re: Add ParameterDescription message to libpq frontend long message types

    jie wang <jugierwang@gmail.com> — 2026-04-02T01:13:57Z

    Ning Sun <classicning@gmail.com> 于2026年4月2日周四 08:52写道:
    
    > Hi,
    >
    > I'm maintaining a Rust library pgwire to implement postgres wire
    > protocol in rust. While doing a corner case test, I noticed the
    > inconsistency for ParameterDescription between backend and frontend.
    >
    > The backend allows up to 65535 parameters in a prepared statement. But
    > when running Describe on the statement, there is a size limit of 30000
    > bytes for ParameterDescription on the frontend. This means we can only
    > describe statements with at most ~7500 parameters. For statements exceed
    > the limit, it ends up with error about the message size.
    >
    > This patch simply adds ParameterDescription to VALID_LONG_MESSAGE_TYPE
    > whitelist to remove the cap.
    >
    >
     Hi,
    
    Based on my understanding, this approach is safe for the following reasons:
    
    1. The message format is clearly defined and has been properly handled.
    2. Similar message types (such as RowDescription) are already allowed to
    exceed this limit.
    3. No changes have been introduced at the protocol level.
    
    Thanks!
    wang jie
    
  3. Re: Add ParameterDescription message to libpq frontend long message types

    ZizhuanLiu X-MAN <44973863@qq.com> — 2026-06-14T12:46:24Z

    >Original
    >From: jie wang <jugierwang@gmail.com>
    >Date: 2026-04-02 09:13
    >To: Ning Sun <classicning@gmail.com>
    >Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
    >Subject: Re: Add ParameterDescription message to libpq frontend long message types
    >
    >Ning Sun <classicning@gmail.com> 于2026年4月2日周四 08:52写道:
    >Hi,
    >
    >I'm maintaining a Rust library pgwire to implement postgres wire
    >protocol in rust. While doing a corner case test, I noticed the
    >inconsistency for ParameterDescription between backend and frontend.
    >
    >The backend allows up to 65535 parameters in a prepared statement. But
    >when running Describe on the statement, there is a size limit of?30000
    >bytes?for ParameterDescription on the frontend. This means we can only
    >describe statements with at most ~7500 parameters. For statements exceed
    >the limit, it ends up with error about the message size.
    >
    >This patch simply adds ParameterDescription to VALID_LONG_MESSAGE_TYPE
    >whitelist to remove the cap.
    >
    >
    >
    >
    >Hi,
    >
    >Based on my understanding, this approach is safe for the following reasons:
    >
    >1. The message format is clearly defined and has been properly handled.
    >2. Similar message types (such as RowDescription) are already allowed to exceed this limit.
    >3. No changes have been introduced at the protocol level.
    >
    >Thanks!
    >wang jie
    
    
    
    Hi, Ning Sun, wang jie,
    
    Thank you very much for your investigation and patch. I have learned a lot about libpq internals from this discussion.
    
    The overall interaction architecture is: CLIENTAPP <--> LIBPQ <--> BACKEND. 
    
    The frontend/backend inconsistency we are discussing happens exactly in this workflow, which I summarize below:
    
    1. The client submits a prepared statement with up to PQ_QUERY_PARAM_MAX_LIMIT (65535) parameters. 
    Libpq accepts this request, which conforms to the official PostgreSQL limit documented in Appendix K, 
    where the maximum number of query parameters is defined as 65535.
    
    2. The backend successfully prepares the statement with the full parameter set without any truncation.
    
    3. When the client retrieves statement metadata via PQdescribePrepared() and similar libpq APIs, the backend
    returns complete parameter information for all 65535 parameters. The resulting ParameterDescription message
    totals 262146 bytes. However, libpq enforces a hardcoded 30000-byte limit for any message type outside the 
    VALID_LONG_MESSAGE_TYPE whitelist. Since ParameterDescription (type t) is not whitelisted, this valid oversized
    message is rejected, resulting in a synchronization loss error.
    
    4. After reviewing the libpq source code, I confirmed that ParameterDescription messages only have two consumption paths:
      - Debug tracing: pqTraceOutput_ParameterDescription(), which iterates and prints each parameter’s metadata to conn->Pfdebug;
      - Upper-layer application access: clients consume the metadata through public APIs like PQnparams() and PQparamtype().
    Even for the full 65535 parameters, the maximum payload size is only around 256KB. This size is completely safe and manageable, and allowing longer ParameterDescription messages introduces no negative impact on either the debug tracing or application API consumption paths.
    
    5. I have applied, compiled and tested this patch locally. It works as expected and perfectly resolves the frontend-backend inconsistency.
    
    Thanks again for your great work!
    
    
    regards,
    --
    ZizhuanLiu (X-MAN)
    44973863@qq.com
  4. Re: Add ParameterDescription message to libpq frontend long message types

    Heikki Linnakangas <hlinnaka@iki.fi> — 2026-06-15T09:01:36Z

    On 01/04/2026 09:32, Ning Sun wrote:
    > I'm maintaining a Rust library pgwire to implement postgres wire 
    > protocol in rust. While doing a corner case test, I noticed the 
    > inconsistency for ParameterDescription between backend and frontend.
    > 
    > The backend allows up to 65535 parameters in a prepared statement. But 
    > when running Describe on the statement, there is a size limit of 30000 
    > bytes for ParameterDescription on the frontend. This means we can only 
    > describe statements with at most ~7500 parameters. For statements exceed 
    > the limit, it ends up with error about the message size.
    > 
    > This patch simply adds ParameterDescription to VALID_LONG_MESSAGE_TYPE 
    > whitelist to remove the cap.
    
    Committed and backpatched to all supported versions, thanks!
    
    - Heikki