Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whLKg-000AHt-1M for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jul 2026 06:00:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whLKe-004vLe-1y for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jul 2026 06:00:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whLKe-004vLV-0s for pgsql-hackers@lists.postgresql.org; Wed, 08 Jul 2026 06:00:29 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1whLKc-000000006Z9-2ct2 for pgsql-hackers@lists.postgresql.org; Wed, 08 Jul 2026 06:00:28 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5aeb5829fd5so261507e87.1 for ; Tue, 07 Jul 2026 23:00:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783490425; x=1784095225; darn=lists.postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:to:from:date:from:to:cc:subject:date :message-id:reply-to:content-type; bh=o/3KCrLJQC3EzYunER/LwLNAQtkMfiiWFK3wUo4QJMQ=; b=Z39krCoYl+lXT3R3wJdhWUjG/X+31T+QWncfkUg3GnrrW3z2lbWngZc7TCP8L3j1hq 2BRZ7OmrtgZbh3LnQKwAs9Wujpy3OjNL3al/rwvmTsyO70CunYAEvARGulRHa0LbLEVX Fw+cDRBFa3M1DhuFbYe0qgoTjazLfXu9xlooa6PAYIzmYLleSV690DOKyibRCy9/MBLY /7QDWWMTVQqDkE0ILBUR8FPuOeaE31Ut5PSL5OQJVQ30BbjOvHWtWeCjPOKQTMzLx91h aMo2JqkW5svB24qFJ20LC//nTBpQNzF3VuL3FU/OsrTU57o958pznumQVx5P63e8py9x DA9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783490425; x=1784095225; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=o/3KCrLJQC3EzYunER/LwLNAQtkMfiiWFK3wUo4QJMQ=; b=eKPIZ2nYTpQouetO4Pt4LLN+zIoC2SoolScKDCqFexezVU7nLKXOKKtajcq2Qp8ama o6xQ33CZXAyl8gnyTu4kuEwoIqiLgY8jiMirPTErEqXFAvanyTyzuVxTK2ryWWXcxcf1 h6X7WWyv+8JmK/RAlH9aLBnrdk7MUm6LuAjogsGbiYl7WydKYBlEOSipYk+2R1AuCkA5 tozRLeErTsPSqlnbfT6i3iQZFuEWJg/FkXYZtP/btsUKdVAz/bKyt4q916AxEWh/6fRt bUeNfhyaP9qC5U4qzaJ2TjuiacV0twLUgMzRs7Zli/vGncySONgdDUx8BuNQxOusoj3M SvzA== X-Gm-Message-State: AOJu0YwLPFVwC/HcchJ25QA6tBU6ZF5Iq5y7kU3icRjBKRImF62XFJen hv8MQ3GdaT/EUe+SV8fmc8DACvceFPYgBntxQJw2no+oQwpY6WRSmUZcwsufiQ== X-Gm-Gg: AfdE7cmAvKJyo+1T77xxVDUB7/ENvrLpUg4O4mcrU4qo5+o+JcpQgRDOw/KCTmC907Z BmVOCQY5Cw/zZzYqQkwNDt59LmOFcl8budLpqP9xoZwpolxXWeKr1X7lvydwt2HZ4Hybto6HYDp McIf0vmeom3R2inkoW5D6XxW4jcR6vR2oQeC1Q4NvK1aDjW7W8IFGVmy6ZUwAGtDje8kUgCtvNq IRwN05g0WF2fcVGNapZAamrAvBtdCYxsHwaIZOF1kuZqUfKlM3TRzHhsQANkS8IyL+C58ENcSI1 LKXVAnXWUjpXj7Zgo8Ku3KZSr0KQDWHo1bFd+tx0gRIgGxC36NiByKFOXxIsQiW368FKWu8bVcp taU9UR4Vq/wok9aAmWO+6fV/zybqh9Bn2TMEU81vEaksqMCnzEOMwo2FhLkEN+gAnCpeGEJnxFV R8m9eHdrdNcLOhGou5KVPXG2eVQ1SDovdKlLdQci6P8HS3t4XO+8za8zOFX7N4o3s8rlHnM1st X-Received: by 2002:a05:6512:8390:b0:5ae:b602:fa2f with SMTP id 2adb3069b0e04-5b011478caamr170842e87.40.1783490424999; Tue, 07 Jul 2026 23:00:24 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b00e57193fsm395196e87.22.2026.07.07.23.00.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 23:00:24 -0700 (PDT) Date: Wed, 8 Jul 2026 06:00:22 +0000 From: Bertrand Drouvot To: pgsql-hackers@lists.postgresql.org Subject: Re: Add per-backend AIO statistics Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Tue, Jul 07, 2026 at 11:02:03AM +0000, Bertrand Drouvot wrote: > postgres=# select count(*),avg(length(data)) from smalldocs; > count | avg > ---------+----------------------- > 1024000 | 1024.0000000000000000 > (1 row) > > postgres=# SELECT * FROM pg_stat_get_backend_aio(pg_backend_pid()); > started | executed_sync | executed_async | completed_self | completed_other | handle_waits | submitted | stats_reset > ---------+---------------+----------------+----------------+-----------------+--------------+-----------+------------------------------- > 3125 | 46 | 3079 | 46 | 0 | 0 | 3078 | 2026-07-07 09:28:27.412136+00 > > We can see that the sequential scan fully benefits from AIO. > > 2/ query the largedocs table: > > postgres=# select count(*),avg(length(data)) from largedocs; > count | avg > -------+---------------------- > 1000 | 1048576.000000000000 > (1 row) > > postgres=# SELECT * FROM pg_stat_get_backend_aio(pg_backend_pid()); > started | executed_sync | executed_async | completed_self | completed_other | handle_waits | submitted | stats_reset > ---------+---------------+----------------+----------------+-----------------+--------------+-----------+------------------------------- > 121154 | 121150 | 4 | 121150 | 0 | 0 | 4 | 2026-07-07 09:35:00.504872+00 > > We can see that the sequential scan bypasses AIO. I was just doing some AIO experiments and was using the new pg_stat_get_backend_aio() function. So, while at it, sharing more examples here: 3/ pg_stat_get_backend_aio() and pg_stat_get_backend_io() correlation postgres=# SELECT executed_sync, executed_async FROM pg_stat_get_backend_aio(pg_backend_pid()); executed_sync | executed_async ---------------+---------------- 46 | 3088 (1 row) postgres=# SELECT object, context, reads, read_bytes FROM pg_stat_get_backend_io(pg_backend_pid()); object | context | reads | read_bytes ---------------+-----------+-------+------------ relation | bulkread | 3088 | 401580032 relation | bulkwrite | 0 | 0 relation | init | 0 | 0 relation | normal | 46 | 376832 relation | vacuum | 0 | 0 temp relation | normal | 0 | 0 wal | init | | wal | normal | 0 | 0 (8 rows) We can see that the "executed_sync" matches the reads "normal" context and that the "executed_async" matches the reads "bulkread" context. 4/ io_uring and multiple backends postgres=# SELECT a.pid, (pg_stat_get_backend_aio(a.pid)).completed_other FROM pg_stat_activity a WHERE a.backend_type = 'client backend'; pid | completed_other ---------+----------------- 1911889 | 245 1911892 | 511 1911912 | 147 1911933 | 161 (4 rows) We can see that the backends completed AIO on behalf of other backends, which makes fully sense in io_uring mode. 5/ io_max_concurrency = 4 postgres=# SELECT started, handle_waits FROM pg_stat_get_backend_aio(pg_backend_pid()); started | handle_waits ---------+-------------- 3139 | 3026 (1 row) We can see that the backend had to wait for free AIO handles on 96% of its IOs. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com