Cancel problems of query to pg_stat_statements

From: Roman Khapov <rkhapov(at)yandex-team(dot)ru>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Cancel problems of query to pg_stat_statements
Date: 2025-04-24 17:49:16
Message-ID: 31431745515032@mail.yandex-team.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi!

 

Recently we faced a problem in out production psql installation, which was that we had to cancel all requests to the db, including performance monitoring requests, that uses ps_stat_statements. But we could not cancel the request in usual way, and had to kill -9 the pg process of it.

 

We've noticed that the the query execution stuck on PGSS_TEXT_FILE file reading in function qtext_load_file, which doesn't have CHECK_FOR_INTERRUPTS in the read cycle. In addition to our case with large PGSS_TEXT_FILE (and maybe the problems with virtual disk i/o) that can explain uncancellable pg_stat_statements queries.

 

Also, the reading block size can be reduced from 1GB to 32MB in order to increase the frequency of CHECK_FOR_INTERRUPTS calls without qtext_load_file performance degradation. To check that I did some little testing with fio like:

 

fio --name=readtest --filename=./random-bytes-file --rw=read --bs=32m --size=10G --ioengine=libaio --direct=1 --numjobs=1

 

So, I made a simple patch that adds CHECK_FOR_INTERRUPTS call in read cycle of qtext_load_file and change max value of toread from 1GB to 32MB.

 

I would appreciate your feedback on these changes.

 

 

Attachment Content-Type Size
unknown_filename text/html 1.5 KB
cancelable-qtext_load_file.patch text/x-diff 1.6 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Sami Imseih 2025-04-24 18:15:06 Re: Conflicting updates of command progress
Previous Message Masahiko Sawada 2025-04-24 17:48:58 Re: Fix slot synchronization with two_phase decoding enabled