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 1nMbDC-0006R5-EU for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Feb 2022 19:52:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nMbDA-0002ic-Pd for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Feb 2022 19:52:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMbDA-0002iS-Ew for pgsql-hackers@lists.postgresql.org; Tue, 22 Feb 2022 19:52:36 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nMbD7-0006yP-Mf for pgsql-hackers@postgresql.org; Tue, 22 Feb 2022 19:52:36 +0000 Received: by mail-pf1-x436.google.com with SMTP id w2so941132pfu.11 for ; Tue, 22 Feb 2022 11:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=nGSYH7P3QMP5Pa+KD3J4CZz/ss3HCcNWBE/xbQ/U84I=; b=qQmuKIYRHAHkqMZaK1T4RpzXLRosLt7AVopsm1/WujAi0+f5tvwvEDh+mA1SSOU0Nd 46ejn8iXicjUe1vc2oC1AKylCBc4PcKFu8xaFmUGMkgVKrUxa/Ug4sQQGk/7hjAZJPgF 5xkUSyQnRKAwBphtvkAH2Dy7Q/teUU8UyogEtaoAlKrGOjnN+cSutZgsqNAA+tGU/ziE cKUo6UcH4Q3UvlOQS2IYacYWff5NHwHdGdGWGKvfuYmazJeK4yivUCupjz8cgZUZ2abd zRdqCbxz8j76MPePAHnXAID8k8dOfXkLa4BSA8CTjzEPd5AKzA1b0rABSGMusJ02o0Av SkVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=nGSYH7P3QMP5Pa+KD3J4CZz/ss3HCcNWBE/xbQ/U84I=; b=Diah6c80MKB0+8hJZY1fPJHY39CsXLgwzMom2QISZ9vtjdccUH5kCYXNbnTNqf/d6k c3kGL04wbvvMmvRksmG9jnkuZov/uBOyRnqJ/rmwurXngAlG6I8YBwzJW/j1mT4DJEwX 9a6iX4YiH8nN9q8qJDV4GQm+jOPtvBwiJhV+tihXVqT+VRPxr2j/5RQNFuLB7bzbJuH4 c0Id8cJ1ahE8f7KO3o4Cdu7u9Gqa1l92Bc3a4cg4ffOB0HeiTKL0D6JEQrpdjfu9YX6Q +MCJwQvJnDPJ6OCvG5phJLmat4EvX6nP6DJMSudGVEqaW+mn3ONC7UQwMEMEzUpXIBpq Xz/g== X-Gm-Message-State: AOAM533U98wwUCiJyxi8iV0x/upeG3Aarcpu7dRi0EruRiNwU3HEOQ7G +FUv5FpwDWYwxz63BYbFUQUIbXIPuHU= X-Google-Smtp-Source: ABdhPJxNJCvmxW8z/wMCFEJV4bs28ZPjEUGSOgnjsaYBh0UsG31qHWMIi0mSt3SBmHkjM+Nm45ORaw== X-Received: by 2002:a63:114c:0:b0:373:a701:3736 with SMTP id 12-20020a63114c000000b00373a7013736mr20888173pgr.117.1645559551413; Tue, 22 Feb 2022 11:52:31 -0800 (PST) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id h10sm18446210pfc.103.2022.02.22.11.52.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 11:52:30 -0800 (PST) Date: Tue, 22 Feb 2022 11:52:29 -0800 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: Re: remove more archiving overhead Message-ID: <20220222195229.GA42988@nathanxps13> References: <20220222011948.GA3850532@nathanxps13> <20220222173711.GA3852671@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2oS5YaxWCcQjTEyO" Content-Disposition: inline In-Reply-To: <20220222173711.GA3852671@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Feb 22, 2022 at 09:37:11AM -0800, Nathan Bossart wrote: > In my testing, I found that when I killed the server just before unlink() > during WAL recyling, I ended up with links to the same file in pg_wal after > restarting. My latest test produced links to the same file for the current > WAL file and the next one. Maybe WAL recyling should use durable_rename() > instead of durable_rename_excl(). Here is an updated patch. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --2oS5YaxWCcQjTEyO Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-reduce-archiving-overhead.patch" From e080d493985cf0a203122c1e07952b0f765019e4 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 22 Feb 2022 11:39:28 -0800 Subject: [PATCH v2 1/1] reduce archiving overhead --- src/backend/access/transam/xlog.c | 10 ++++++---- src/backend/postmaster/pgarch.c | 14 +++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 0d2bd7a357..2ad047052f 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -3334,13 +3334,15 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath, } /* - * Perform the rename using link if available, paranoidly trying to avoid - * overwriting an existing file (there shouldn't be one). + * Perform the rename. Ideally, we'd use link() and unlink() to avoid + * overwriting an existing file (there shouldn't be one). However, that + * approach opens up the possibility that pg_wal will contain multiple hard + * links to the same WAL file after a crash. */ - if (durable_rename_excl(tmppath, path, LOG) != 0) + if (durable_rename(tmppath, path, LOG) != 0) { LWLockRelease(ControlFileLock); - /* durable_rename_excl already emitted log message */ + /* durable_rename already emitted log message */ return false; } diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index d916ed39a8..641297e9f5 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -746,7 +746,19 @@ pgarch_archiveDone(char *xlog) StatusFilePath(rlogready, xlog, ".ready"); StatusFilePath(rlogdone, xlog, ".done"); - (void) durable_rename(rlogready, rlogdone, WARNING); + + /* + * To avoid extra overhead, we don't durably rename the .ready file to + * .done. Archive commands and libraries must already gracefully handle + * attempts to re-archive files (e.g., if the server crashes just before + * this function is called), so it should be okay if the .ready file + * reappears after a crash. + */ + if (rename(rlogready, rlogdone) < 0) + ereport(WARNING, + (errcode_for_file_access(), + errmsg("could not rename file \"%s\" to \"%s\": %m", + rlogready, rlogdone))); } -- 2.25.1 --2oS5YaxWCcQjTEyO--