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 1vEldA-0001iF-VZ for pgsql-admin@arkaria.postgresql.org; Fri, 31 Oct 2025 09:41:12 +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 1vEld9-00DWcI-VF for pgsql-admin@arkaria.postgresql.org; Fri, 31 Oct 2025 09:41:10 +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 1vEld9-00DWc7-KD for pgsql-admin@lists.postgresql.org; Fri, 31 Oct 2025 09:41:10 +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 1vEld6-005E0K-1a for pgsql-admin@lists.postgresql.org; Fri, 31 Oct 2025 09:41:10 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-634cef434beso5669135a12.1 for ; Fri, 31 Oct 2025 02:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761903667; x=1762508467; 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=zODLZa8PRK/TOOhvyW2N5zDzq+WHPJW4hZcLvWqRs2c=; b=UeowQbALjwkMDEB1h7X2tOQb/o9/zqdps2kw1Z2Gms6vrBPALX5xVcokeu/r9umvgT 9ABJ4qV1aGzG9HCw1/Qc8B4JlEX3OcSaS6LHAyFZCX42/jWadWRCjPYBSXnw9UFovQcp YccsaeENa0pSa7fojeLyuKO6x7sIGy6pL9/aDOZgp4YdKs1zJG72VGnlygF+xXg4ZpIA QmocgebXecs/g6fmPuiOT9jVBlhr+/JriE7a7x0Jn+BmgZwjzJBvxRXuzWVOOhC23Ybx k7edDjGo99mmzVuPg/LsnHUAVRAsq4VuVotKDXyYzWIji38tiwseh+XLPbQit6wVet2L OhrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761903667; x=1762508467; 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=zODLZa8PRK/TOOhvyW2N5zDzq+WHPJW4hZcLvWqRs2c=; b=BR7PDee0Aw+1DkT5MFES1EF0gQO/wCMaclrfoO2z1Gp8e4+3wf0HTcDc8owOhh2meP qcnzOW0vkjLbhqO/AdWye+YY7oh2dm+05abKBQPrAFuNely5CsHmICo6KfFPzCHfnwnl Pa4ykrPuyy9YPKIrReErILACQBQfSEVw3mu1boIJpPKhohQp4S0qMiFFAPtO/ACw6PGk ksPgqKHBy39YE99MMX7ycpju8rRAcYngWevZFg15ed9lrkshHg0Lecn8edpZhj1d9+zd l+fDNOl1ghVq1g7uMl5DmNJ5f/e3OKhJYzhstjD1SBVL84ylnYhR8x3ncJ612f+74IGX XSDg== X-Gm-Message-State: AOJu0YwWeGX27BPV9DLL2Yuxk0DnnE9CloPOWVRXtNUtBvMJnoMiaDl7 htr3Rf/ld0NYJ9EvNsuDL1Tf8cj682DHAd84+ZHexsDFr7O54yZxlfRKb1QAmB5X2owVQEQlA4L NOFHE4qov5bLFlbTKQwJtmU+yRvrT1S7XYBNZ X-Gm-Gg: ASbGncvqokqz9qfpl5LxX87SFWYkGgglIbrt5BgUBrKE5yaj9pFgtLIuks5JBhM7Jok Fd/0VfWXy7RfV5CH7SNwOetQzyGdx8qE/InCMIfLuEECYQ5VZ2PrKgDrdy0v//FxvbPMYvKYJbv A3aa/Vy1RMHRg5SflrG8+EF9n2IEVmuOe1kjUZXXAOdD+fek6kJjpkgHGjAjFAyebpdaO4Ncufh j/eyYKstpUC/0bScmnBcVtbVBfnfR/MMiP3/Rfy2e5QZuQcTbtbsL2hb8KMseQ2glAiYJQtSbXO 8z4E3fpN3upmmzQpgnAUsSv68Q4TbyslHPv8sTWGqWs5Ws/CmK9gsAgyXkY= X-Google-Smtp-Source: AGHT+IE2J+SREEOoK8AeYK9CThNKL7VKbX599+0osyaVmgiVAz0EYNsuWXlQCcuN5FY06X0fURopUcQkOSis50x3+Dc= X-Received: by 2002:a05:6402:1ec4:b0:62e:ebb4:e6e0 with SMTP id 4fb4d7f45d1cf-640752fd5a0mr2435594a12.1.1761903666542; Fri, 31 Oct 2025 02:41:06 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Xuneng Zhou Date: Fri, 31 Oct 2025 17:40:55 +0800 X-Gm-Features: AWmQ_blLxhCX6zyYGuRsif99ZyHT0AvJiB5ZdpsbBmHgXbelY-9HgFCZSddZASM Message-ID: Subject: Re: Question on pg_stat_io showing zero reads/writes for I/O workers To: pgsql-admin@lists.postgresql.org 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 > Test message sending.