Skip to content

collector.stat_statements.query_length does not truncate properly #1211

@jsadowyj

Description

@jsadowyj

What did you do?
Enabled the following collector options:

 - collector.stat_statements.include_query
 - collector.stat_statements.query_length=4000

What did you expect to see?
The query label is truncated to 4000 characters (including comments).

What did you see instead? Under which circumstances?

pg_stat_statements_block_read_seconds_total{datname="<redacted>",queryid="-5016773285470984866",user="metabase_ro"} 0
pg_stat_statements_block_write_seconds_total{datname="<redacted>",queryid="-5016773285470984866",user="metabase_ro"} 0
pg_stat_statements_calls_total{datname="<redacted>",queryid="-5016773285470984866",user="metabase_ro"} 5
pg_stat_statements_query_id{query="-- Metabase:: userID: 1 queryType: MBQL queryHash: 54162c2fced7fe3932b12602637694179314c62f535f392cbd3cea208aec60d2\nSELECT \"public\".\"notifications\".\"id\" AS \"id\", (\"public\".\"notifications\".\"metadata\"#>> array[$1]::text[])::text AS \"metadata → body\", (\"public\".\"notifications\".\"metadata\"#>> array[$2]::text[])::text AS \"metadata → data\", (\"public\".\"notifications\".\"metadata\"#>> array[$3, $4]::text[])::text AS \"metadata → data → amount\", (\"public\".\"notifications\".\"metadata\"#>> array[$5, $6]::text[])::text AS \"metadata → data → platform_type\", (\"public\".\"notifications\".\"metadata\"#>> array[$7, $8]::text[])::text AS \"metadata → data → receiver\", (\"public\".\"notifications\".\"metadata\"#>> array[$9, $10, $11]::text[])::text AS \"metadata → data → receiver → avatar\", (\"public\".\"notifications\".\"metadata\"#>> array[$12, $13, $14]::text[])::text AS \"metadata → data → receiver → first_name\", (\"public\".\"notifications\".\"metadata\"#>> array[$15, $16, $17]::text[])::text AS \"metadata → data → receiver → id\", (\"public\".\"notifications\".\"metadata\"#>> array[$18, $19, $20]::text[])::text AS \"metadata → data → receiver → last_name\", (\"public\".\"notifications\".\"metadata\"#>> array[$21, $22, $23]::text[])::text AS \"metadata → data → receiver → username\", (\"public\".\"notifications\".\"metadata\"#>> array[$24, $25, $26]::text[])::text AS \"metadata → data → sender → first_name\", (\"public\".\"notifications\".\"metadata\"#>> array[$27, $28, $29]::text[])::text AS \"metadata → data → sender → id\", (\"public\".\"notifications\".\"metadata\"#>> array[$30, $31, $32]::text[])::text AS \"metadata → data → sender → last_name\", (\"public\".\"notifications\".\"metadata\"#>> array[$33, $34, $35]::text[])::text AS \"metadata → data → sender → username\", (\"public\".\"notifications\".\"metadata\"#>> array[$36, $37, $38]::text[])::text AS \"metadata → data → transaction → amount\", (\"public\".\"notifications\".\"metadata\"#>> array[$39, $40, $41]::text[])::text AS \"metadata → data → transaction → amountUsd\", (\"public\".\"notifications\".\"metadata\"#>> array[$42, $43, $44]::text[])::text AS \"metadata → data → transaction → blockExplorerLink\", (\"public\".\"notifications\".\"metadata\"#>> array[$45, $46, $47]::text[])::text AS \"metadata → data → transaction → from\", (\"public\".\"notifications\".\"metadata\"#>> array[$48, $49, $50]::text[])::text AS \"metadata → data → transaction → gasFee\", (\"public\".\"notifications\".\"metadata\"#>> array[$51, $52, $53, $54]::text[])::text AS \"metadata → data → transaction → original → error\", (\"public\".\"notifications\".\"metadata\"#>> array[$55, $56, $57]::text[])::text AS \"metadata → data → transaction → to\", (\"public\".\"notifications\".\"metadata\"#>> array[$58, $59, $60]::text[])::text AS \"metadata → data → transaction → transactionHash\", (\"public\".\"notifications\".\"metadata\"#>> array[$61, $62]::text[])::text AS \"metadata → data → transaction_hash\", (\"public\".\"notifications\".\"metadata\"#>> array[$63, $64]::text[])::text AS \"metadata → data → ulid\", (\"public\".\"notifications\".\"metadata\"#>> array[$65]::text[])::text AS \"metadata → event\", (\"public\".\"notifications\".\"metadata\"#>> array[$66]::text[])::text AS \"metadata → notification_type\", (\"public\".\"notifications\".\"metadata\"#>> array[$67, $68]::text[])::text AS \"metadata → payload → amount\", (\"public\".\"notifications\".\"metadata\"#>> array[$69, $70]::text[])::text AS \"metadata → payload → chainId\", (\"public\".\"notifications\".\"metadata\"#>> array[$71, $72]::text[])::bigint AS \"metadata → payload → creationHeight\", (\"public\".\"notifications\".\"metadata\"#>> array[$73, $74]::text[])::text AS \"metadata → payload → description\", (\"public\".\"notifications\".\"metadata\"#>> array[$75, $76]::text[])::text AS \"metadata → payload → from\", (\"public\".\"notifications\".\"metadata\"#>> array[$77, $78]::text[])::text AS \"metadata → payload → memo\", (\"public\".\"notifications\".\"metadata\"#>> array[$79, $80]::text[])::text AS \"metadata → payload → symbol\", (\"public\".\"notifications\".\"metadata\"#>> array[$81, $82]::text[])::text AS \"metadata → payload → to\", (\"public\".\"notifications\".\"metadata\"#>> ar",queryid="-5016773285470984866"} 1
pg_stat_statements_rows_total{datname="<redacted>",queryid="-5016773285470984866",user="metabase_ro"} 10000
pg_stat_statements_seconds_total{datname="<redacted>",queryid="-5016773285470984866",user="metabase_ro"} 42.436016087

The label length always exceeds 4000 bytes for the above query:

$ pbpaste | wc -c
    4451

Environment

  • System information:
# uname -srm
Linux 6.8.0-35-generic x86_64
  • postgres_exporter version:
# postgres_exporter --version
postgres_exporter, version 0.18.1 (branch: HEAD, revision: 320b684f3dcd3f09b6e694e43f9b389b1a8199e5)
  build user:       root@83cf77f7d3ab
  build date:       20250929-17:16:35
  go version:       go1.24.7
  platform:         linux/amd64
  tags:             unknown
  • postgres_exporter flags:
usr/local/bin/postgres_exporter \
    --collector.stat_statements \
    --collector.stat_statements.include_query \
    --collector.stat_statements.query_length=4000 \
    --collector.replication \
    --collector.replication_slot \
    --collector.stat_wal_receiver \
    --web.listen-address=0.0.0.0:9187 \
    --config.file=/etc/postgres_exporter/postgres_exporter.yml \
    --web.telemetry-path=/metrics
  • PostgreSQL version:
postgres=# select version();
                                                         version
--------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 15.10 - Percona Distribution on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0, 64-bit
(1 row)
  • Logs:

None to speak of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions