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.94.2) (envelope-from ) id 1vFehu-00FUoO-Ea for pgsql-admin@arkaria.postgresql.org; Sun, 02 Nov 2025 20:29:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vFeht-00DjpX-FJ for pgsql-admin@arkaria.postgresql.org; Sun, 02 Nov 2025 20:29:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vEzgk-002KHg-0E for pgsql-admin@lists.postgresql.org; Sat, 01 Nov 2025 00:41:49 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vEzgg-005Kq6-2e for pgsql-admin@lists.postgresql.org; Sat, 01 Nov 2025 00:41:48 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-6408f034513so1133787a12.0 for ; Fri, 31 Oct 2025 17:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761957705; x=1762562505; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kzbaSAmOJImHYCm/3K0e1hvOUKG1+HUUbH9pD4YN+zE=; b=MO8udm/63UPgHQ4aVh387hQShjAyjPA1hjJAIewoesQXpMZXCeQpeZaMQHVeT6d5Ju sEShGxSX9E0DMDXb7JsPwdDlv38PVicGCqA2ZRTPLrtdMT4EcEt1B+eSmiWrgjNB796l 5cMldtGT1D9mgiiRb+R6apj0j0ZQ3wlHwzOy+hf8asrWQqMQ6QROP7wpIM4YsG94JTaV FgNOfqc/O2Bqr+Kf6Btq5vKbooUn/YS43vYaWu1CAba7raH7qGEi5mkY2losYIptk3al TtmwPKD4NKsHGYgIQELpXgKSkYgZ5O+076d/tbUNfcM9jgtH3rRMtid7EsR+CgGuB6zs qBHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761957705; x=1762562505; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kzbaSAmOJImHYCm/3K0e1hvOUKG1+HUUbH9pD4YN+zE=; b=QQnEC1oOqbVr1xGLL3Xeo/bK30PcpY4m2V0yiaFVWXnW9+wHjsBGOzFSUjtzuUrDlD 7EGadn9Q0n9usUPXuHxI8oh2jUzArNPolzoP3qbnsGNqtpN8DjINhiPn6ukTHE1StzYK 7jZtWifhYGOfqd7hnyg9gPeqf5XB17XaDKt9z0TKqHrnqoWxje1dj7YD6WWvoeE2E3Pp Ui7sgm+6fLKCXDlm2IR16+iM0NF/fgvJzKfoeYQaJr37j/jxMrOAhQlAqm8ZmyzUTwfh A1xDGd89QVPNOOQy4iKlAt63Z03vyc0jubnCbVMrAMA2umZGkK5NRzMP2pov7oLFkACI O7Qw== X-Gm-Message-State: AOJu0YxfhLitGyAAH/0B2SlUAakhbVd4GRgwyy5CJzpK4ESndoZhISSP OCJ1GQpHqGjS/CMvGvvU0v+CKsSUNo/px5o/RLjD3xQp881zJoLGowdjVpYff3HSGujQZXVGgWH CXWghoAWehCzygaUEjr/ST3NHo5DNk1M= X-Gm-Gg: ASbGncuC4mFF7dwTI0oiv79cGGFJYyRXvCw6iAJ4GXCOimBmba6981GDkuelouPtbYX 1NsfCpjHUnMmiHiMb9AcwwM99rGyWB6otIJSv8P3bn98K+hpK2AcSwVyn4QewsTacLtK6Km09lm lHVanfsdIhA95e5ZOThbAAjiSJg/D/U/aRpI3Lc67KDI6kyph7KWg6gnwZM54eAGHlmRha61quH 3brG2bgen/lYI9KojTZhpEZbdAioc2KtxueXW1qoxRcAKg2putkhbiO87QcJfx+DgxR1XF6P7WM O5AEmaewiQTcaXetbwzEiLhQUabr4sj3y3m8RCDHjlnnXJ5aNMyvdnCJAciXWCLwzoW91GU= X-Google-Smtp-Source: AGHT+IEHeJbI4OT7eSacngb/YZYm6uUSQR90QPfd9WLgNLKxZn/IVpnM+J1qsYP7Vd99aCJJjzu9h4r+qtF+63omuRQ= X-Received: by 2002:a05:6402:5243:b0:637:e361:f44b with SMTP id 4fb4d7f45d1cf-6407700c6f7mr3957630a12.12.1761957705249; Fri, 31 Oct 2025 17:41:45 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Xuneng Zhou Date: Sat, 1 Nov 2025 08:41:33 +0800 X-Gm-Features: AWmQ_bmGnPmdKhu75PqQIh8TRoDsVU-m9XZ_WAwvuSIY0ql7JbGBrRLJAAfUnlQ Message-ID: Subject: Re: Question on pg_stat_io showing zero reads/writes for I/O workers To: Shardul Borhade Cc: pgsql-admin@lists.postgresql.org, pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Fri, Oct 31, 2025 at 5:50=E2=80=AFPM Shardul Borhade wrote: > > Hi Xuneng, > > Thank you so much for the incredibly clear and detailed explanation. Your= analysis of how I/O stats are attributed at submission time was exactly th= e information I was missing, and it completely solved the mystery. > > You were absolutely correct. I followed your suggested test procedure, an= d it confirmed that AIO is indeed working as intended. > > The key confirmation for me was checking pg_stat_activity while running a= heavy, cache-cleared sequential scan. Just as you predicted, the wait_even= t for my client backend process was AioIoCompletion > > pid | backend_type | wait_event_type | wait_event > > ---------+----------------+-----------------+----------------- > 3052099 | client backend | IO | AioIoCompletion. > > This was the "smoking gun" that proved the main process was delegating th= e I/O and waiting for the workers, rather than doing the reads itself. > > Thanks again for your help and for the excellent work on PostgreSQL. Thanks for your question and kind words =E2=80=94 it means a lot to me. I a= lso think this is worth investigating further. Best, Xuneng > > On Fri, Oct 31, 2025 at 10:30=E2=80=AFAM Xuneng Zhou wrote: >> >> Hi, >> >> On Fri, Oct 31, 2025 at 4:17=E2=80=AFPM Shardul Borhade wrote: >> > >> > Hi team, >> > >> > I=E2=80=99m running into an issue with pg_stat_io. When I run the foll= owing query: >> > >> > SELECT backend_type, reads, writes, read_time >> > FROM pg_stat_io >> > WHERE backend_type LIKE '%io%'; >> > >> > I consistently get: >> > >> > backend_type | reads | writes | read_time >> > --------------+-------+--------+----------- >> > io worker | 0 | 0 | 0 >> > io worker | 0 | 0 | 0 >> > io worker | 0 | 0 | 0 >> > io worker | 0 | 0 | 0 >> > io worker | 0 | 0 | 0 >> > io worker | 0 | 0 | 0 >> > io worker | | 0 | >> > io worker | 0 | 0 | 0 >> > (8 rows) >> > >> > I tried running a heavy sequential scan on a 55 GB table as well as a = bitmap heap scan, but the reads and writes columns still show zero. >> > >> > However, I can clearly observe performance differences when I tune the= io_workers configuration, so I believe they are active. >> > >> > Am I missing something here? Could someone please help me understand w= hy the stats aren=E2=80=99t being reflected in pg_stat_io? Do I need to ena= ble any other server parameter to log this information? >> >> When your client backend issues a query: >> >> 1. Your backend calls `AsyncReadBuffers()` and counts the IO stats >> 2. The IO worker performs the actual I/O but doesn't increment its own c= ounters >> 3. Stats accumulate under "client backend", not "io worker" >> >> Check your *client backend* stats instead: >> >> ```sql >> You should see reads/writes here: >> >> SELECT backend_type, context, object, reads, writes >> FROM pg_stat_io >> WHERE backend_type =3D 'client backend' >> AND reads > 0 >> ORDER BY reads DESC; >> >> -- Verify IO workers exist: >> >> SELECT pid, backend_type, wait_event >> FROM pg_stat_activity >> WHERE backend_type =3D 'io worker'; >> >> >> Quick Test >> >> -- Reset stats >> >> SELECT pg_stat_reset_shared('io'); >> >> -- Run your heavy scan >> >> SELECT COUNT(*) FROM your_large_table; >> >> -- Check client backend stats (should increase) >> >> SELECT SUM(reads) as total_reads >> FROM pg_stat_io >> WHERE backend_type =3D 'client backend'; >> >> -- Check IO worker stats (will remain zero) >> >> SELECT SUM(reads) as total_reads >> FROM pg_stat_io >> WHERE backend_type =3D 'io worker'; >> >> See source code: >> >> - `src/backend/storage/buffer/bufmgr.c` (AsyncReadBuffers, line 1938) >> - stats counted at submission >> - `src/backend/utils/activity/pgstat_io.c` (pgstat_count_io_op, line >> 74) - uses submitter's MyBackendType >> - `src/backend/storage/aio/aio_io.c` (pgaio_io_perform_synchronously) >> - IO worker doesn't call stat functions >> >> However, this behavior seems not great here. If the above analysis is >> sound, should we add something like this to not track i/o worker >> // In pgstat_tracks_io_bktype() >> case B_IO_WORKER: >> return false; // Don't show zero-value rows >> or track actual IO worker stats? >> >> Best, >> Xuneng