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 1vC31u-008LsI-CA for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Oct 2025 21:39:29 +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 1vC31t-00C09P-AE for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Oct 2025 21:39:28 +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 1vC2yl-00BwYH-8S for pgsql-hackers@lists.postgresql.org; Thu, 23 Oct 2025 21:36:14 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vC2yi-003Q5k-0I for pgsql-hackers@lists.postgresql.org; Thu, 23 Oct 2025 21:36:13 +0000 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-63c3d7e2217so2618962a12.3 for ; Thu, 23 Oct 2025 14:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761255369; x=1761860169; 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=sHvXd558PP/zNjVIsckYJOXfb2wi+hKeCCuXC0UBRDs=; b=ZXx+TZDY2rFJ0CH8KE+0L/2JkhMCliOdrX5HtGTeJ8o532nVVVcCDfCAIC+k3wb3QT xcCd8CyWivm+cdmC/4XcqmP1MWOcVJ1ccM9hszML8Y+UanWLmFAFD0s6/JAHGVmrx0zW bZuDJDd6ubHJS9Jxc29NYKliGfDeY66IKKGFBlHYi8zyihjG4GBERQbWC4p7QjpJY/x/ +NHtrEU3dSzvh8jawtGrY7QbppUUvIpQFe82knideYtLwZ3gaf2lVTHXCcTFFlpndsPP jReuNskGP3UXH/urgylglocqCXncODRuyY3P2PTsZaGOzwkRgUcUj96YNFrnGHLrqzgW l5Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761255369; x=1761860169; 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=sHvXd558PP/zNjVIsckYJOXfb2wi+hKeCCuXC0UBRDs=; b=ZPEFh51LETThWA6GUpGeXkNahDAT2ke57C5iHMY5rUhCAm8quNLlsejVo+dAQwYPA+ GSVGxcYqjJO+/qSdxJUpLhiKTg0yL5cQ+vP8afoDmKBZ/pLTJUfpfaRGqxQ8rkrshhap /Kg6Mdo9kt0tPAFHkJSjqRNMtCGJ3EgLteQqlEbmY1SmXbujNtSLpEBUFQvmyB7KWS2W aZXV93B9ktsCr24dgiTzzJOLxo8bW9u4JsWf+QduWSooU4D/arDySuPva/hnd6WwEFbL gndSWeDv11RLQ9Z1jwMqIoUprXk0ry5VnFULNyM5/xfIv5+2gnENLd1DWdNhEBa106HS 7hbA== X-Gm-Message-State: AOJu0Yw2VdX3JXHWg9QXdAG6EXBgCm/xwjS/rHcIipqOjAJ6KNmtTUiO Y66cOOhV7Qenhyequ46Zxpr0I2lKrRj9OT1GHhkSReTA9Q9rbGrtr9CTPcozb7XidsFLgXHL8E1 VLBeAPiDbtPg2YgBbNqzKwOU5C2smdW3PndrVGaA= X-Gm-Gg: ASbGncursmbiBLnUAsWCF53N10cqvXFxy54sBn92IEBgBMxyPs9O7pIEkaENe0wdg/z 4I8BUM4YbdZVE99vnShnBR9VH269MclmTOhkvVj/JiySNXzNP/WnhMYW5owfW7bydpB0TIikFh1 GVoyrSlzwtGdsXxVVi8lRunzGIkdpGfJaHrpHz+gBsSF0BgOciKP2qLmVZ8cxNkJZemz3uRKAZz vCdfeUUu9BJ78DT7AbCm5uOMIS3a3hIqr0D5EWtDvC5E8hBQUJqeCFyZwk= X-Google-Smtp-Source: AGHT+IEXiLWt5TnP0wBFTHkzg8Iq3e2pHcysaaP7lI+Vk29YSUHZeVD7BtDrG7/IoCoq/bRtKLunK6/vZ78t+aPsbEc= X-Received: by 2002:a05:6402:1d53:b0:631:cc4f:2ff5 with SMTP id 4fb4d7f45d1cf-63e600e9980mr120529a12.25.1761255369130; Thu, 23 Oct 2025 14:36:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Thu, 23 Oct 2025 16:35:58 -0500 X-Gm-Features: AWmQ_bnIU5xBMT0e4hrxLfVHbVR3T_ybD7SjAsz7SIvUAGifHLSKAhLDbx6zVb0 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 Thanks for the feedback! > > Other design points: > > > > 1. Filenames use "pgstat..stat" based on the numeric kind ID. > > This avoids requiring extensions to provide names and prevents issues > > with spaces or special characters. > > Hmm. Is that really what we want here? This pretty says that one > single custom kind would never be able use multiple files, ever. Perhaps if someone wants to have separate files for each different types of data, we should be able to support multiple files. I think we can add an option for the number of files and they can then be named "pgstat..1.stat", pgstat..2.stat", etc. I rather avoid having the extension provide a set of files names. So as arguments to the callback, besides the main file pointer ( as you mention below), we also provide the list of custom file pointers. what do you think? > Hmm. I would like to propose something a bit more flexible, > refactoring and reusing some of the existing callbacks, among the > following lines: > - Rather than introducing a second callback able to do more > serialization work, let's expand a bit the responsibility of > to_serialized_name and from_serialized_name to be able to work in a > more extended way, renaming them to "to/from_serialized_entry", which Sure, we can go that route. > - The fd or FILE* of the "main" pgstats file should be added as > argument of both routines (not mandatory, but we are likely going to > need that if we want to add more "custom" data in the main pgstats > file before writing or reading a chunk). For example, for a PGSS text > file, we would likely write two fields to the main data file: an > offset and a length to be able to retrieve a query string, from a > secondary file. Yeah, that could be a good idea for pg_s_s, if we don't want to store the key alongside the query text. Make more sense. > - FDs where the data is written while we are in the to/from serialize > can be handled within the code paths specific to the stats kind code. > The first time a serialized callback of a stats kind is called, the > extra file(s) is(are) opened. This may come at the cost of one new > callback: at the end of the read and writes of the stats data, we > would need an extra look that's able to perform cleanup actions, which > would be here to make sure that the fds opened for the extra files are > closed when we are done. The close of each file is equivalent to the > pgstat_close_file() done in the patch, except that we'd loop over a > callback that would do the cleanup job once we are done reading or > writing a file. One step that can be customized in this new "end" > callback is if a stats kind may decide to unlink() a previous file, as > we do for the main pgstats file, or keep one or more files around. > That would be up to the extension developer. We should be able to > reuse or rework reset_all_cb() with a status given to it, depending on > if we are dealing with a failure or a success path. Currently, > reset_all_cb() is only used in a failure path, the idea would be to > extend it for the success case. I will provide a patch with the recommendations. -- Sami