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 1vNOQJ-001NsY-2Q for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Nov 2025 04:43:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vNOQH-00GW7F-0x for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Nov 2025 04:43:33 +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.96) (envelope-from ) id 1vNOQG-00GW75-30 for pgsql-hackers@lists.postgresql.org; Mon, 24 Nov 2025 04:43:33 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vNOQE-001AHH-20 for pgsql-hackers@lists.postgresql.org; Mon, 24 Nov 2025 04:43:32 +0000 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-6408f9cb1dcso5673823a12.3 for ; Sun, 23 Nov 2025 20:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763959409; x=1764564209; 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=kyjGBzKcfSRleVyVzsp0Hoagx1CbCL5lptLeA/JipHI=; b=BlPEt5rjG5GVpaLT1QSxCcZBPMWbg3QfRmvqmK2FbdhpuCAYX4VR59fkZbifwr9fbf hs8fbMXd0UoVrahe3xa+oqMlRIaTSl8IRPcfU3ty0Xypp4Rpg43Wd0/BWQUMvix3pXkd ymr0kicfgWWabwALGleE3rRg3uB5RhP4dtHVUJelNqpc10a/XJfT5Y4Axc3Yh7vGCNd6 KOLSDDE0+WjR0DIAJBUAvAyzyYgbobw1L5xGl+z0EirhnoigQNvbQhO7BCSJ5C77JYx7 mwnHSNDMJWCUX41JbNKHC4mlTHPGJeDPKOufKmRA0CD9KbkiXB9xbWOWG0W4FAwwVbTY Cnqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763959409; x=1764564209; 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=kyjGBzKcfSRleVyVzsp0Hoagx1CbCL5lptLeA/JipHI=; b=dOOgkuasKbBNWNEY6+p/kdXjKug/HtwUfU2iF+55xpo6+tSc1qqv61KoLZPt+QW7yw LAtvFRadsLbPwAvGDPgtDcGAIc6SPUjgHxy4bNg2xPegKvhOQp/7EZW/m9PItF68qrMc sbsbBJWzzbdOqXlrDwwA1nbUTEnYwel3CyxkGTTgRNt1qlJBrAeQwDwwzX2vqrBZvB3F 2we6u+x1y2brfjBtJUWsKZLIn8IC2vn0E/nHSj22DTnbAvEuukn9wX3/ZfADGecxeiyE /7pGJUzOqJ3Jajc0REQp8dfE45tuhIZkiodEbqE82TYM7GSMeBbzrzP0d19fo1f5dUY+ nxFQ== X-Gm-Message-State: AOJu0YxCHyzvNoLcNerXPztydeZEZk6/Vey+9kQozs6K17zsjG5mKVgQ nFGF35fJSGPX78FNKvm7skOiNtTbCak9bn2S8s8+ufczrgwBzGQ2Gxppyv7vGtTwY1CDVyCfN/6 RNBstvuT2TniwWcnEi59CvD48BJl83l0ywLRu X-Gm-Gg: ASbGnctApJG5pvvxSZ+WZOIpah9WN4r5w0zpESgyTVPtW1zvOaKZzY34wEAbe//huRo Gp4QnkirKFGhY3EH6pCE9nG5BmyCkP1CZbGCsXyl9J7ZyjuEK0EqbnkDlr73cLB2mjvCPFkL/Xd Ken4tatKPqDAWdQhqG1E6z2SjR8xXc81C1O/sfNbhyxr/spmwR5jPvIlrdCys58wxvzSfrOznvo ufSA+N8TtNlO30rvHK8eH7ikByEGKnwLO1MiF5iNmYrZ5H1QW9MVQ5WGp8VPooVD5rTGg== X-Google-Smtp-Source: AGHT+IEp3QUKAlW6g0jAlGkS1P+JGaJsOVxDbjxQ5eIIi+T/T0Qf0yvibTABsEn7aBEwffi8+bpBsxWMz/RuOZMD27Y= X-Received: by 2002:a05:6402:1ed0:b0:643:e03:db04 with SMTP id 4fb4d7f45d1cf-64554335b27mr10200165a12.14.1763959408754; Sun, 23 Nov 2025 20:43:28 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Sun, 23 Nov 2025 22:43:17 -0600 X-Gm-Features: AWmQ_bmMJMEUsaeOtNikKoLU5E93lKOm8qONk9qv1M7d3T7r75TjOY_Q46bgGbI Message-ID: Subject: Re: [Proposal] Adding callback support for custom statistics kinds To: Michael Paquier Cc: 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 > > It just occurred to me that the documentation [0] should be > > updated to describe the callbacks. I will do that in the next > > revision. > > > > [0] https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-ADDIN-CUSTOM-CUMULATIVE-STATISTICS > > Hmm. Based on what I can read from the patch, you are still enforcing > file name patterns in the backend, as of: > + extra->statfiles[i] = psprintf("%s/pgstat.%d.%d.stat", > + PGSTAT_STAT_PERMANENT_DIRECTORY, kind, i); > > My take (also mentioned upthread) is that this design should go the > other way around, where modules have the possibility to define their > own file names, and some of them could be generated on-the-fly when > writing the files, for example for a per-file database split, or the > object ID itself. The way I thought about it is that extension developer can just provide the number of files they need and the they are then given a list of file pointers that they need. They can then manage what each file is used for. They also don't need to worry about naming the files, all they need to do is track what each file in the list does. > The important part for variable-numbered stats is that the keys of the > entries have to be in the main pgstats file. Then, the extra data is > loaded back based on the data in the entry key, based on a file name > that only a custom stats kind knows about (fd and file name). It > means that the custom stats kind needs to track the files it has to > clean up by itself in this scheme. We could pass back to the startup > process some fds that it cleans up, but it feels simpler here to let > the custom code do what they want, instead, rather than having an > array that tracks the file names and/or their fds. yeah, I was leaning towards putting more responsibility on pgstat to manage these extra files, but you are suggesting that we just let the extension manage the create/cleanup of these files as well. After re-reading your earlier suggestions, this sounds like a third callback that is used for file cleanup, and this callback could be the existing reset_all_cb. Also, instead of reset_all_cb being called during pgstat_reset_after_failure, it can be called during the success case, i.e, a new pgstat_reset_after_success. reset_all_cb also carries a status argument so the extension knows what to do in the case of success or failure. This also means we need to also update all existing callbacks to do work in the failed status. Is that correct? -- Sami