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.96) (envelope-from ) id 1vTP4W-000rno-0r for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Dec 2025 18:37:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vTP3V-000Vyf-25 for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Dec 2025 18:36:54 +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.96) (envelope-from ) id 1vTP3V-000VyX-0x for pgsql-hackers@lists.postgresql.org; Wed, 10 Dec 2025 18:36:54 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vTP3T-0000zY-34 for pgsql-hackers@lists.postgresql.org; Wed, 10 Dec 2025 18:36:53 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-649728a2228so230917a12.3 for ; Wed, 10 Dec 2025 10:36:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765391810; x=1765996610; 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=oMnkP1BzWP3BoKUpHX2KujiuVTNBfJFcMlupNL/mS9Q=; b=mBuJbbl7erv4bHYGleDfHUU64b9lmsPBewPKsU07z0Ob/V07ZvQkv3oLc7WS83k9MH pfzm3l+LTCV5g2Sd0x0vLgHAzo0uA1e7yPQLohkwrwjrZfpSnka363M9JnJIXy+I+8Tx FSWhEHnOmAFK72AMGhffOgdxv2zRPL82Rh9zkYrDuHnIry0s9ya8+8gSqqqnB0asqoSk YKXZMbIdZ+lCZgYOdTIlMEm8Dw2tTasM8ILlk7PehReC4u3kGyEDb3rjQeJrD4yx/oFT tfTNte4RWrlbd5Rs0+PpP5Jpy4acUs7YiO9q9Xs0g4U90Y90VpxlkZg+laXFEvMSjvkF 4n8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765391810; x=1765996610; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oMnkP1BzWP3BoKUpHX2KujiuVTNBfJFcMlupNL/mS9Q=; b=J65Lm8Rrt46wMwAjlUYAYs3/zLCw1eM2Abqu6/QoWxyBa4YjD8IT5g+wC5UV8CDSwA ci1odxP5gH/0kWzqHVN0Ndizz6xj2547eqm7Usq/vDfKSzkcfcqZhbKF/dgrWmDlxVR3 01NCZ8NvR1ro8c8nhLJ1Udp5/nnvq+4qf4zygQ1YE0Yk+GWZTWXiUTOCLoaJzyB+ZXN4 Cn4bP0rJycl33Ih79/iXBaFj4z6n5KFEfb/OSJjj8p+VbbU8efWdHt3TK/hs039QE92V IML6M/s7KWrneezLutjpigtxQEYyn4ThJVCCLOvcYoc4Vngck8DVKFOmhHIG1LDnDoJw XHJA== X-Forwarded-Encrypted: i=1; AJvYcCUNCFYOO/lxbyz3QXZsc2vqiLsvLF+f8RKlwkyIyWLLmZWrYNt8nJLcNqY9419+K4ltT2Ck7tg50800MgYV@lists.postgresql.org X-Gm-Message-State: AOJu0YzHGnPRGZ+v1FS7sPfJ+Clcja1xVLuHgQMnwKjjRkG/UvPu472B OFb/WO9UDCgKUyoceeE45DdMAxGg+Mt7f77tgdASZH0igV1x/5nFZ4nxOQjNwzxeibNdqpv3qhb 8+edBhAno6sXSxLsS0CS58boiME11QHE= X-Gm-Gg: AY/fxX7e9ITqMHB6nV7CtUQwc8zdm2dboPP6cKY7NgAF4bNGQKcBp3fXv4IYqK2xxPR F+uoxju9CT2G8TB/wZQWGSQwB/YAyTkryZLjcQ4SPFWh+sfRND4OFGbs5lA8qgGzvxq7MYJ/pt7 Tj+DU4A6UIHhw02xiHBq2i+PfM60GoXtDq3cWemQOBjSY5Z9sOso3F6Nl8OChlU4EiACXy/L2Vx eRBidNx2k5iGxx63hZDMoJaQEU2f/X5u9vIcipofhUxyP8M25/oVccHaiDUSKDi7HuzTKRev9lJ xwpfGA== X-Google-Smtp-Source: AGHT+IEWiaUe6NfRx+qZZM19PHXxlSva1FLazlBl2NmGmhwLHJHPEl6PTs8yD7jJqAK2IvGxUp+wbcUmiYV+GfsJlYs= X-Received: by 2002:a05:6402:5047:b0:649:815e:3fae with SMTP id 4fb4d7f45d1cf-649815e49aemr633210a12.1.1765391809841; Wed, 10 Dec 2025 10:36:49 -0800 (PST) MIME-Version: 1.0 References: <9252DA7C-C611-4A93-A484-E6CD42557C15@gmail.com> <4E61FDC4-CFBB-4116-980F-75ADD245A1F6@gmail.com> In-Reply-To: From: Sami Imseih Date: Wed, 10 Dec 2025 12:36:36 -0600 X-Gm-Features: AQt7F2ojnkVk34smW6Mqc-2AmWk0BiyG94j6G8jXrwIRC0pZt6iUzISyTP2ksBg Message-ID: Subject: Re: [Proposal] Adding callback support for custom statistics kinds To: Michael Paquier Cc: Chao Li , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > Now, it is kind of true that the STATS_WRITE case feels a bit > disturbing written this way: we let a module take an action, but we > don't actually know the state of the main pgstats file when inside the > callback. I mean, you can know how things are going on, but it means > that a module can just rely on a check if > PGSTAT_STAT_PERMANENT_FILENAME is on disk, but an unlink() could have > failed as well. So, yes, I am wondering whether we should do what > Chao is suggesting, passing an extra state to the callback to let the > module know if we have actually succeeded or failed the operations > that have been taken on the main stats file before the callback > end_extra_stats is called in the three cases. It does not matter for > the STATS_READ case, but it may matter for the STATS_DISCARD or > STATS_WRITE case. I am having a hard time being convinced that this extra status is needed. I am not expecting an extension to operate on the main stats file inside the end_extra_stats callback, and even if some operation failed on the main stats file, the cleanup callback will need to take the steps to perform the cleanup on its own resources. Is there a concrete example? > FWIW, I still have the same question as the one posted here about the > business in pgstat_initialize(), still present in v6: > https://www.postgresql.org/message-id/aTepXZ97PsXpuywI@paquier.xyz > > This remains unanswered. Responding to the questions from the thread above. > Why does this part need to run each time a backend initializes its > access to pgstats? Good point. This is unnecessary. This validation should really be done inside StatsShmemInit by postmaster. > By the way, checking that to_serialized_extra_stats and > kind_info->from_serialized_extra_stats need to be both defined is > fine as these are coupled together, but I am not following the reason > why end_extra_stats would need to be included in the set? For > example, a stats kind could decide to add some data to the main > pgstats file without creating extra files, hence they may not need to > define end_extra_stats. .. and after giving this more thought, I actually don't think we should do any validation for any of the callbacks. If an extension is writing to any file ( core or custom ), naturally they will want to read it back. Now I am not sure what these validations are protecting us against. Also, maybe the extension wants to just read data from the main stats file, I could see that use-case, perhaps. So, I am proposing removing the validation altogether. What do you think? -- Sami Imseih Amazon Web Services (AWS)