Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nckNo-0007Co-0o for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Apr 2022 08:54:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nckNm-0002kA-Ns for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Apr 2022 08:54:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nckNm-0002k1-Av for pgsql-hackers@lists.postgresql.org; Fri, 08 Apr 2022 08:54:18 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nckNi-0008Md-Tn for pgsql-hackers@lists.postgresql.org; Fri, 08 Apr 2022 08:54:17 +0000 Received: by mail-ej1-x631.google.com with SMTP id ot30so15846540ejb.12 for ; Fri, 08 Apr 2022 01:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:comments:mime-version :content-id:content-transfer-encoding:date:message-id; bh=Jt20jAdPACCzcGVVDFCSXpl70HsIlkcvvqEIdT5P2A0=; b=oNVi1ySs0xrwFz6D3mMl7LKtUd5i4/PHGZxuPlcTmYvc/4Yhszscirk4/6SUn8xHAD r9p6jfX6of/eb3ggj/hV/e0bZ1vfQTk12G7OZK30TaYYDxMboS1yYOIDC8azWvYtPE4j ywrsejzvqbAyIuxgMgB/Yv3Zn7qsBU50lMhjo1msc2C1IK8lt1UsGO5BGLVXPKX6FyEn ag5L0oFR6KzzWV8hSCgAnxjW5DKzs+eI3Yb1f/dL/PR2L23y8iGT0DppuT3mITQ/M5dv Lo8IO4/IsnwiVCWzkprqh0DMdyKyhIDTSfPBpxOuPz4hx0BEa2eSRcUKCEnlB1OYVEVm Mutw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :comments:mime-version:content-id:content-transfer-encoding:date :message-id; bh=Jt20jAdPACCzcGVVDFCSXpl70HsIlkcvvqEIdT5P2A0=; b=fzbXimZkSpXysGc2F5RAhxKF8w42nQyW4fd+0gGqajT7wS8LSar4Ifu54QZsR0lKrG hyKX+nmHuyO5zbhJznKLJAdtJysuZl1TXc3wJ8WybYjNFAW2N63qwY19ZzSCyOys/73E q5xDU7O+/ENaH+tWpEBtPxCaClgnOlOmCKa10agc+Oxn2PXu5XPFSMx9p04OOPBeN9p7 qRRUmA9NVuRa7nJMWE0FPr/gX5Jo/McQb5J67tTn48NgUgIHHXfWUfpYE2dn1FRxAKhc SV+Z8flzneVUeg5iDILeY6rkgOr2+JnGdODFyQPr1ABIrKdecRf/1QxhkGsYs8v+asuk jcjA== X-Gm-Message-State: AOAM532qwV3ZlFpwvg8vIt7wYuELFmST4r9NNCmggV9rUaPm5rPwFKAK MvJgJzwoQIfvPMUJEwsoxYA/lIQ49MLajg== X-Google-Smtp-Source: ABdhPJw2JLiG4zO2IumD/lUFJkpFqkuIuQkmx2lobx2wkqVAmuG3X9nz4+3gaBxwU99TubQYmsvhZw== X-Received: by 2002:a17:907:6d0c:b0:6e8:61d6:9c6f with SMTP id sa12-20020a1709076d0c00b006e861d69c6fmr171657ejc.288.1649408052949; Fri, 08 Apr 2022 01:54:12 -0700 (PDT) Received: from antos (85-207-121-76.static.bluetone.cz. [85.207.121.76]) by smtp.gmail.com with ESMTPSA id s20-20020a056402015400b00418f9574a36sm10187523edu.73.2022.04.08.01.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 01:54:12 -0700 (PDT) From: Antonin Houska To: Robert Haas cc: Stephen Frost , PostgreSQL Hackers Subject: Re: Temporary file access API In-reply-to: References: <4987.1644323098@antos> <20220301143431.GT10577@tamriel.snowman.net> <27013.1646738099@antos> Comments: In-reply-to Robert Haas message dated "Tue, 05 Apr 2022 15:29:38 -0400." X-Mailer: MH-E 8.6+git; nmh 1.7+dev; GNU Emacs 27.2.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3145.1649408068.1@antos> Content-Transfer-Encoding: quoted-printable Date: Fri, 08 Apr 2022 10:54:28 +0200 Message-ID: <3146.1649408068@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas wrote: > On Tue, Mar 8, 2022 at 6:12 AM Antonin Houska wrote: > > Thanks for your comments, the initial version is attached here. > = > I've been meaning to look at this thread for some time but have not > found enough time to do that until just now. And now I have > questions... > = > 1. Supposing we accepted this, how widely do you think that we could > adopt it? I see that this patch set adapts a few places to use it and > that's nice, but I have a feeling there's a lot more places that are > making use of system calls directly, or through some other > abstraction, than just this. I'm not sure that we actually want to use > something like this everywhere, but what would be the rule for > deciding where to use it and where not to use > it? If the plan for this facility is just to adapt these two > particular places to use it, that doesn't feel like enough to be > worthwhile. Admittedly I viewed the problem from the perspective of the TDE, so I have= n't spent much time looking for other opportunities. Now, with the stats colle= ctor using shared memory, even one of the use cases implemented here no longer exists. I need to do more research. Do you think that the use of a system call is a problem itself (e.g. becau= se the code looks less simple if read/write is used somewhere and fread/fwrit= e elsewhere; of course of read/write is mandatory in special cases like WAL, heap pages, etc.) or is the problem that the system calls are used too frequently? I suppose only the latter. Anyway, I'm not sure there are *many* places where system calls are used t= oo frequently. Instead, the coding uses to be such that the information is fi= rst assembled in memory and then written to file at once. So the value of the (buffered) stream is that it makes the code simpler (eliminates the need t= o prepare the data in memory). That's what I tried to do for reorderbuffer.c= and pgstat.c in my patch. Related question is whether we should try to replace some uses of the libc stream (FILE *) at some places. You seem to suggest that in [1]. One examp= le is snapmgr.c:ExportSnapshot(), if we also implement output formatting. Of course there are places where (FILE *) cannot be replaced because, besides regular file, the code needs to work with stdin/stdout in general. (Parsin= g of configuration files falls into this category, but that doesn't matter beca= use bison-generated parser seems to implement buffering anyway.) > 2. What about frontend code? Most frontend code won't examine data > files directly, but at least pg_controldata, pg_checksums, and > pg_resetwal are exceptions. If the frequency of using system calls is the problem, then I wouldn't cha= nge these because ControlFileData structure needs to be initialized in memory anyway and then written at once. And pg_checksums reads whole blocks anyway. I'll take a closer look. > 3. How would we extend this to support encryption? Add an extra > argument to BufFileStreamInit(V)FD passing down the encryption > details? Yes. > There are some smaller things about the patch with which I'm not 100% > comfortable, but I'd like to start by understanding the big picture. Thanks! [1] https://www.postgresql.org/message-id/CA+TgmoYGjN_f=3DFCErX49bzjhNG+Go= ctY+a+XhNRWCVvDY8U74w@mail.gmail.com -- = Antonin Houska Web: https://www.cybertec-postgresql.com