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 1tXyNl-00HWyz-JU for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jan 2025 08:04:10 +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 1tXyNk-008kXn-5t for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jan 2025 08:04:08 +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 1tXyNj-008kXf-SP for pgsql-hackers@lists.postgresql.org; Wed, 15 Jan 2025 08:04:08 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tXyNj-000V5J-0O for pgsql-hackers@lists.postgresql.org; Wed, 15 Jan 2025 08:04:07 +0000 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2f4409fc8fdso900154a91.1 for ; Wed, 15 Jan 2025 00:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736928246; x=1737533046; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jiFi3n6w/Le3SpWNydxLZq7vlS+C3Uz6EgHlQLtetCo=; b=LTO6Xc9Hh/ydvDFthfPDpXvkFQNEtf7CNfaUCVq81vrv3Uq+c51OGUwusP5847UfpK 3T//ugF5+qfHii3xH36F7vduc0YE1hB1nNsuJxpz01OUXQSw2npEGq+mjf2T3Gj/zKL1 rKraQoWPsSUyD5s+DkDIU+FGv/mL8sNUYG82FB6jR66Hay+iYn+U5H6v0T5PRZhsIUDp 8Y4Juh5o0P8c/g5qL6WopTTLdN1l8C1j1mQ7R1L+gHgx9YRXzJMZnRlBY0iY3BG7jfJt cKfeoKgBgoi/GsDCF1VzIw6UJNNdbUFEAni8Z6SJ0WKOY34fY7w5wfW2MyFCBFbgYNEM dVUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736928246; x=1737533046; h=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=jiFi3n6w/Le3SpWNydxLZq7vlS+C3Uz6EgHlQLtetCo=; b=gKykReeXAmThkx3BVlf08MoWrseuY/0HwqfagaNB+JInAjewJ8Qn8o0tAvl/0PjkX4 HO+wVGNQJwh3ih4pQn7OgxH6alpznkRdK6kqFX8PfmA3N5UfPeZ5NXqamKxl4owUMj4r CI7p5ZYzrGq2dy0nbDYv2Js6Zt6Lu44r78n7Oo4mHEwkiW0QbmXYkBrCH506JLVT3AFx v577ohW3rj/clXVOs3kaH2Yt3hkSRXBvRgGeDNW7xMLjlqBrnBHkb9nc/FiJY6aazh6m Gm4C4NM833q6uCCP/V7Rvn5bxsut2ruKd8fqqC8HJGB5HFfFc2rOn7JRZuhB4WN2xySY sqtA== X-Forwarded-Encrypted: i=1; AJvYcCUIg/04h1H0TM17dWz8Ql02l6BitMm9+aL4RE1vLEL6y7GnyPdhnJ8nE7cY1XUDNkwS0dgCt+BR5RR0G1Yi@lists.postgresql.org X-Gm-Message-State: AOJu0YwJjKYwdsEGLiBP9+oRrZSFn3FLebG1svFk1wHxNhHsAUSYQ4FC zHAxZGpBqCzHXH9wRc8LHOfqqsdbvo1x0kupZLaOyaa3+ySmdaZRGyAhL3YUPm0+WspmId4cBvT gtNsLwb87FOw1n9NH9oXzbxdepNw= X-Gm-Gg: ASbGnctsQ8JMWy8P9QFNYtgNFMcssuGjxntGhmDbPP76Vrh0r5voy1qOVMAjdL4bjBU Ji9ixGl+i9gr/lvuMSVGk7smBq8ylCXpSa+qtBQ== X-Google-Smtp-Source: AGHT+IH/ndkhxyeF7Ag+p/twj4dtu5qRBRYuYenycVJQO1a6Avs18qcNRe4uO41Y/TkQXJc4oLqdtBKYgFh+rRTjy1E= X-Received: by 2002:a17:90b:38c6:b0:2ef:949c:6f6b with SMTP id 98e67ed59e1d1-2f728e472dcmr3227407a91.13.1736928245633; Wed, 15 Jan 2025 00:04:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Nazir Bilal Yavuz Date: Wed, 15 Jan 2025 11:03:54 +0300 X-Gm-Features: AbW1kva4gWqS-hLNyyMKIOjAuCChS1h1BuosqPKw_0j1Q-NshDNfY9Lpg4Xz5aM Message-ID: Subject: Re: per backend I/O statistics To: Michael Paquier Cc: Bertrand Drouvot , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, 19 Dec 2024 at 07:22, Michael Paquier wrote: > > Fixed that, bumped the two version counters, and done. I encountered a problem while trying to add WAL stats to pg_stat_io and I wanted to hear your thoughts. Right now, pgstat_prep_backend_pending() is called in both pgstat_count_io_op() and pgstat_count_io_op_time() to create a local PgStat_BackendPending entry. In that process, pgstat_prep_pending_entry() -> MemoryContextAllocZero() is called. The problem is that MemoryContextAllocZero() can not be called in the critical sections. For example, here is what happens in the walsender backend: ''' ... -> exec_replication_command() -> SendBaseBackup() -> ... -> XLogInsertRecord() -> START_CRIT_SECTION() /* Now we are in the critical section */ -> ... -> XLogWrite() -> pgstat_count_io_op_time() for the pg_pwrite() IO -> pgstat_prep_backend_pending() -> pgstat_prep_pending_entry() -> MemoryContextAllocZero() -> Failed at Assert("CritSectionCount == 0 || (context)->allowInCritSection") ''' With this commit it may not be possible to count IOs in the critical sections. I think the problem happens only if the local PgStat_BackendPending entry is being created for the first time for this backend in the critical section. -- Regards, Nazir Bilal Yavuz Microsoft