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 1tGKSk-002HUc-R1 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Nov 2024 16:00:22 +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 1tGKSi-00GLe8-KW for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Nov 2024 16:00:20 +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 1tGKSi-00GLdi-9a for pgsql-hackers@lists.postgresql.org; Wed, 27 Nov 2024 16:00:20 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tGKSf-004Lpt-NC for pgsql-hackers@lists.postgresql.org; Wed, 27 Nov 2024 16:00:19 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-432d866f70fso63100065e9.2 for ; Wed, 27 Nov 2024 08:00:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732723217; x=1733328017; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OfSeLUJ/4rd8PzDcuZL+YB0QMSJfIQymXalGogyiLfc=; b=ksXbQ988cH+c7d3Ki12lhYzlj5kGq6IiMonVfzB8ILcpSmLhsMldVARB2+qV7l7amN 5VcliqIHKezPEDGjSBt+zLy5j6ghBkA39MQp9wU59JBXeCusMKNqMJ4QAuxl2l3FglgH VkQxQvvyQXDzNN7Y/rKjt/6LHAjkpVk1z6cuRy+Hz2ONtSUdFtBFufaYgI/IXKcOxrNO e2uGlPQYVIXqDItcM91Y6XHqFavrcJQz8skRYmD3s4lslG/qsSaDHYcwF5fyf8lKbCYZ vTRUaNCtHmsbAmcPh5um6BPvVjdKhl8n/og3vXMkgm+BeIcXXnbjumsj2zouLxbWiDYG VeKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732723217; x=1733328017; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OfSeLUJ/4rd8PzDcuZL+YB0QMSJfIQymXalGogyiLfc=; b=Q3fVUnfhZeaRUm/eUuNnWDaYnDxtz+bGtHu0Uj4XMjeMXWdZ7e2dS60KGDyX/cAWF9 S3LD6b8AODa4+/zgOvmIr0KMlN3+TuYam5q4u8HSCbNZ+axhnSSxpm6JGWwYf//I+veF KdkSA+F1IcwVIqQf3mz3Ao3S4mVkE0TgV+N5c/Ou5yq2EwuAI2VPuG57rLoIhQNYzBaJ InisN9C1l+y8rMLPq64mmbjbbwfmuAZVI4ncSw3XNqWGLwmBo44RGs9P7mUMYAGwVEvl zJNephY3fUewhd/DJAKBZ14CFAIgrNYb1+gBzfjPjHMbXVjFDRhbXe30Wze8aU0ogTg4 lz5A== X-Forwarded-Encrypted: i=1; AJvYcCWXCNWAqdAhbA3ZeMIUK6K6Am0F19JwoSG6I2GNsFJY5/OHj7rEIfgomj8LN68F/2aXbCZptN0Y8nRNWAUQ@lists.postgresql.org X-Gm-Message-State: AOJu0YzQbowEQyJvJolc4GZ5vbatMyxxFMPzSt1mbCj+mE2PweoLgfT3 4q3CT9inYgigEh0Sm/S55rupWpIJ0rTMh9GP16vulA042yrllILw X-Gm-Gg: ASbGncvjTVCXEKjgFaHcyYOGwc3zlqXZzMebbZx4oWXC82NXPiqCCEv7Vw7F0WkLgzL sw8uKM8ibfjFi0MOQ4JFVLPiWaAb8GGjN+UuxyjeTm05O8m82vMQk+1pk9jT7MYDMQPKU5InaRH puWZ6Kl72V4DBypXVm+96ad46+59K10Vegvbi8ieRqT0VU7J3g/6K2376b/iQDOdGmZts1MxIDm jYI+2cC6QDXPYSWRojY1yw3D5LuUI7Dkh+WSfpIvJSK8Nqti+hL1GhzMltCMt8nFiuNO8DNESdS a8L/mUq/nrqH4FKv87YXcm3vDn1takqFLlvkCjadQqNtbWck/X+LkcqMmfNVIbBgkqeqUjKkmLp T X-Google-Smtp-Source: AGHT+IHaWb/P3kaJot8jODxr3W2/9Oj/KOQwvTghAToR5q+Nkx7rAs3bamUoz5aQhtRwjbQqOFr18g== X-Received: by 2002:a05:600c:4686:b0:434:a7e3:db5c with SMTP id 5b1f17b1804b1-434a9dbf4a1mr31759695e9.11.1732723216570; Wed, 27 Nov 2024 08:00:16 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3825fafe158sm16658668f8f.27.2024.11.27.08.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:00:16 -0800 (PST) Date: Wed, 27 Nov 2024 16:00:14 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: Nazir Bilal Yavuz , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: per backend I/O 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 Wed, Nov 27, 2024 at 03:33:38PM +0900, Michael Paquier wrote: > On Mon, Nov 25, 2024 at 03:47:59PM +0000, Bertrand Drouvot wrote: > > It also takes care of most of the comments that you have made in [1], meaning > > that it: > > > > - removes the backend type from PgStat_Backend and look for the backend type > > at "display" time. > > - creates PgStat_BackendPendingIO and PgStat_PendingIO now refers to it (I > > used PgStat_BackendPendingIO and not PgStat_BackendPending because this is what > > it is after all). > > - adds the missing comment related to the PID in the doc. > > - merges 0004 with 0001 (so that pg_stat_get_backend_io() is now part of 0001). > > - creates its own pgstat_backend.c file. > > I have begun studying the patch, and I have one question. > > +void > +pgstat_create_backend_stat(ProcNumber procnum) > [...] > + /* Create the per-backend statistics entry */ > + if (pgstat_tracks_per_backend_bktype(MyBackendType)) > + pgstat_create_backend_stat(MyProcNumber); > > Perhaps that's a very stupid question, but I was looking at this part > of the patch, and wondered why we don't use init_backend_cb? I > vaguely recalled that MyProcNumber and MyBackendType would be set > before we go through the pgstat initialization step. MyDatabaseId is > filled after the pgstat initialization, but we don't care about this > information for such backend stats. Using init_backend_cb (and moving the pgstat_tracks_per_backend_bktype() check in it) is currently producing a failed assertion: TRAP: failed Assert("pgstat_is_initialized && !pgstat_is_shutdown"), File: "pgstat.c", Line: 1567, PID: 2080000 postgres: postgres postgres [local] initializing(ExceptionalCondition+0xbb)[0x5fd0c69afaed] postgres: postgres postgres [local] initializing(pgstat_assert_is_up+0x3f)[0x5fd0c67d1b77] postgres: postgres postgres [local] initializing(pgstat_get_entry_ref+0x95)[0x5fd0c67db068] postgres: postgres postgres [local] initializing(pgstat_prep_pending_entry+0xaa)[0x5fd0c67d1181] postgres: postgres postgres [local] initializing(pgstat_create_backend_stat+0x96)[0x5fd0c67d3986] But even if we, say move the "pgstat_is_initialized = true" before the init_backend_cb() call in pgstat_initialize() (not saying that makes sense, just trying out), then we are back to the restore/reset issue but this time during initdb: TRAP: failed Assert("!pgstat_entry_ref_hash_lookup(pgStatEntryRefHash, shent->key)"), File: "pgstat_shmem.c", Line: 852, PID: 2109086 /home/postgres/postgresql/pg_installed/pg18/bin/postgres(ExceptionalCondition+0xbb)[0x621723499c5a] /home/postgres/postgresql/pg_installed/pg18/bin/postgres(+0x70dd2b)[0x6217232c5d2b] /home/postgres/postgresql/pg_installed/pg18/bin/postgres(pgstat_drop_all_entries+0x61)[0x6217232c60b5] /home/postgres/postgresql/pg_installed/pg18/bin/postgres(+0x705356)[0x6217232bd356] /home/postgres/postgresql/pg_installed/pg18/bin/postgres(+0x70462a)[0x6217232bc62a] /home/postgres/postgresql/pg_installed/pg18/bin/postgres(pgstat_restore_stats+0x1c)[0x6217232b9f01] /home/postgres/postgresql/pg_installed/pg18/bin/postgres(StartupXLOG+0x693)[0x621722da9697] /home/postgres/postgresql/pg_installed/pg18/bin/postgres(InitPostgres+0x1d8)[0x6217234b40df] /home/postgres/postgresql/pg_installed/pg18/bin/postgres(BootstrapModeMain+0x532)[0x621722dd79bf] where "PID: 2109086" is a B_STANDALONE_BACKEND. This is due to the fact that, during the initdb bootstrap, init_backend_cb() is called before StartupXLOG(). One option could be to move B_STANDALONE_BACKEND in the "false" section of pgstat_tracks_per_backend_bktype() and ensure that we set pgstat_is_initialized to true before init_backend_cb() is called (but I don't think that makes that much sense). I'd vote to just keep the pgstat_create_backend_stat() call in pgstat_beinit(). That said, we probably should document that init_backend_cb() should not call pgstat_get_entry_ref(), but that's probably worth another thread. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com