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 1vElfy-0002lJ-0O for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Oct 2025 09:44:05 +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 1vElfw-00DaE9-V2 for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Oct 2025 09:44:03 +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.94.2) (envelope-from ) id 1vElfw-00DaE1-Lo for pgsql-hackers@lists.postgresql.org; Fri, 31 Oct 2025 09:44:03 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vElfu-004iOW-04 for pgsql-hackers@lists.postgresql.org; Fri, 31 Oct 2025 09:44:02 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-b64cdbb949cso271376766b.1 for ; Fri, 31 Oct 2025 02:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761903839; x=1762508639; darn=lists.postgresql.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Eoi7O2Ph2EzPXCuwkO17v9nClQoSOz8r4mvRvArQiag=; b=gepWGHLDrgoke1ozUY7dv0QP+jkqoedn9TQ/A2g67XLtrWxFAtm9uZMEFcMacxyX61 PnLIVc5+iqkdI3YS5JiKkkGIlVDxfY3RhG9+74w1zKoG9Xw5B6p49ky43rEy8BOz8+zM 9kMYAj8KJ7CUTCxHnbVq5aFdHLJkrTCdML/jHIPlEjtkhe/gl0uH0k4p+XmndMzztK8G Fy0YpgRUcdbcC5PX7lsR2tsZm+LKsi7PkJR8jTW1DUr6qL80vTB7KNhvbjt+m4C8VPj7 2M4A5lFwGad6Y/EyltW0S5oG32+lXVk7vgLRYOEsZBQ2SqDKWJKsov1qRGP2c4tILQ2z XToA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761903839; x=1762508639; h=content-transfer-encoding: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=Eoi7O2Ph2EzPXCuwkO17v9nClQoSOz8r4mvRvArQiag=; b=raz+JBtG2e5l4sAmg+2keVxxJutW5++tk+LUGoQFti5Ws9r8a+xnlShl/MfOiOe7pR GF6i9r3Hy+OoZJ0iDTsSqLs7iEyN37cuoM9zlm3cwakoMmZKiHUkRwEDYnuYpSDxir9v VUPvsPLZAQPWumpC5eOslqAqsi5mA4zfsWojErPhSL+ylYNa0vPIJr4h3Eip8HJ5g9ti R4XOkkXxZIMZH88btUO9txjUjKFbGRUtbzrABZ8nihawKAUsPS0mAsBhww8p/K9bor3A ySzai8FOcZg0/QlDZt26xrePEhS9c2+8qs/t0xKr8UWHGR6lnp8TvTk6AcIJZb+hN0c4 gt/w== X-Gm-Message-State: AOJu0Ywde7P7CCVNAxs833N2eEF5oTJzv+2frF3Nu8y5ma7co+N5bVi3 GwdT/bvR8fI2lWAV2hi3yJOppKbWm3OVy32FUqJJY7EFkN/1jlFNDzgQJQCRfDMTuptHyiJwVi+ Ro3RBNriixoVGheamrln0JUwh3XlXsL0Hh0mZqVo= X-Gm-Gg: ASbGncsrvEhr9Uh94DxujGUZ86s9M7UJBlz3Tox5n2VtxU90CvCcb1gGmB+AtqDJpA+ +KXz7MUE4oF//H2dCZ+iAkvOM55+m1Q8w+I3nQaUDbDM+ft+6pFfPwOr02nSvWUg1qaTwxkh5pm C9lopK6lB/vEQIIzSQqzvxUYKQTcOQ31Q/grItks9mfeFNK3glEM6vnKC8jXgGkS62Dhshe5bDk vVP9B8BoAzxmW8s6p11rKIeYVpeO5WAn8SIr4zPl4EWfcwJA8U9YehVo4Cv+BS6dmhYY92sQ7pL hbF0tx3bP9S8zHXfLVL3AJtdkVoF+/djEkLntFwcPm2IB7BWVcOUswYUydM= X-Google-Smtp-Source: AGHT+IHwqTzRKG0xq+yYdt1xgVTwmMud0CS5OANfDW1wNL/jWy98IlfPy7qy1Ytmsvt+NAg5mTMd5fqfro6/be2DBDs= X-Received: by 2002:a17:906:ee89:b0:b44:f9fe:913a with SMTP id a640c23a62f3a-b70708a2d37mr237852366b.65.1761903839259; Fri, 31 Oct 2025 02:43:59 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Xuneng Zhou Date: Fri, 31 Oct 2025 17:43:46 +0800 X-Gm-Features: AWmQ_bn5sHv9I04Rwazq1mMIVR50LtmKSybfnJGOz4jFwoP2wDb8EmG_uPbOdHU Message-ID: Subject: Re: Question on pg_stat_io showing zero reads/writes for I/O workers To: 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:30=E2=80=AFPM 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 follo= wing 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 b= itmap 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 wh= y the stats aren=E2=80=99t being reflected in pg_stat_io? Do I need to enab= le 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 co= unters > 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