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 1ncaXU-0007ap-9a for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Apr 2022 22:23:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ncaXT-0000ye-33 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Apr 2022 22:23:39 +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 1ncaXS-0000yU-QL for pgsql-hackers@lists.postgresql.org; Thu, 07 Apr 2022 22:23:38 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ncaXN-0003Eo-6U for pgsql-hackers@postgresql.org; Thu, 07 Apr 2022 22:23:37 +0000 Received: by mail-pj1-x102f.google.com with SMTP id kw18so6920470pjb.5 for ; Thu, 07 Apr 2022 15:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=mUPJOVvGNoUI1mvrM6TtszE1wCH4pYTiVCwmFmragyw=; b=YwHd5tBNzxJCtD7qA1vCINGyIyPUYZAALRxfNa8giK7pVMg5mAbXhD/RQYCAEYMrpq r2xaZDmdYfQF/iIip8GXSCE3lx6HhZeet9ivAzJOgQAaapgnZF7i36pP/YjVKSEnmiW9 5TQa7NDv2rQmi3aK3Q3DngeQ12kQ0RIIWJMT+7CopIalSZ5i2/O2Y0bH61lvbIq2g3ad xRwwOqDP+utoTk3dALyMzuanPxQx5kV+vGs4ywCoV4DI+p7vmp/pwnijSipwn8q99T9c qx7wWezh6etd/xWFqv/eh5wQTyalOdrOuvO5sWTWh5ED2t7Rs+L0goFhQ0S9DYsx9lrO gnug== 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:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=mUPJOVvGNoUI1mvrM6TtszE1wCH4pYTiVCwmFmragyw=; b=L0GIV+EYdxtnrhsPMR4eO5ZaABvVEoR7/V3ZkhtcLbcfy4IQhQ5yZMo0g1jZuNodVy ed3hji8wnx3Zqbc02uikcmvr8eBswNo7AzL42lJhHzxORpiNbMm0oTpg/z6B6Y9sjl6D gB2yNPlmTn7Ij5WNSOynGNbrcc6dyGIpsWDM6h1kjZpaQRGlVtpsvCilDGB1Dn+SbzGV EcUs3W3t5l1wcEttbcF6/kR9hFXvQTjHC11W2jsGgtekP9Y3NClmB+WkApAUhMqxuq6K Q8Omac4ENU4E1180iD0C5sZlY1YbJWI+YxOYMSkZ/sfiBMaccQ7aY3QJkucTfN+2BJJa BiBA== X-Gm-Message-State: AOAM531GBPa2oaR1EPeXR3Q0GGSyFGyBKkovs1xZbBgTMNwcZ4YuJgWX I49ZXiHBbQXdO6H9PWOAB5c= X-Google-Smtp-Source: ABdhPJx9ugQW2QOzNjYTXBbqtoczuD6BUupX86DYW+tQN6/S5/61awGvmKEyhS4hpLslGGJbLdxxaQ== X-Received: by 2002:a17:903:213:b0:156:7efe:4783 with SMTP id r19-20020a170903021300b001567efe4783mr16041660plh.126.1649370210419; Thu, 07 Apr 2022 15:23:30 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id s24-20020a17090a441800b001ca9b5724a6sm9475405pjg.36.2022.04.07.15.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 15:23:29 -0700 (PDT) Date: Thu, 7 Apr 2022 15:23:27 -0700 From: Nathan Bossart To: Kyotaro Horiguchi Cc: pgsql-hackers@postgresql.org Subject: Re: remove more archiving overhead Message-ID: <20220407222327.GA1363808@nathanxps13> References: <20220222011948.GA3850532@nathanxps13> <20220222173711.GA3852671@nathanxps13> <20220222195229.GA42988@nathanxps13> <20220224.141349.1809640551882183816.horikyota.ntt@gmail.com> <20220224175553.GA660690@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="5mCyUwZo2JvN/JJP" Content-Disposition: inline In-Reply-To: <20220224175553.GA660690@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Feb 24, 2022 at 09:55:53AM -0800, Nathan Bossart wrote: > Yes. I found that a crash at an unfortunate moment can produce multiple > links to the same file in pg_wal, which seemed bad independent of archival. > By fixing that (i.e., switching from durable_rename_excl() to > durable_rename()), we not only avoid this problem, but we also avoid trying > to archive a file the server is concurrently writing. Then, after a crash, > the WAL file to archive should either not exist (which is handled by the > archiver) or contain the same contents as any preexisting archives. I moved the fix for this to a new thread [0] since I think it should be back-patched. I've attached a new patch that only contains the part related to reducing archiving overhead. [0] https://www.postgresql.org/message-id/20220407182954.GA1231544%40nathanxps13 -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --5mCyUwZo2JvN/JJP Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-Reduce-overhead-of-renaming-archive-status-files.patch" From 6d8972412179fd3c82bb7e471966d4b7862bcbff Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Thu, 7 Apr 2022 14:11:59 -0700 Subject: [PATCH v3 1/1] Reduce overhead of renaming archive status files. Presently, archive status files are durably renamed from .ready to .done to indicate that a file has been archived. Persisting this rename to disk accounts for a significant amount of the overhead associated with archiving. While durably renaming the file prevents re-archiving in most cases, archive commands and libraries must already gracefully handle attempts to re-archive the last archived file after a crash (e.g., a crash immediately after archive_command exits but before the server renames the status file). This change reduces the amount of overhead associated with archiving by using rename() instead of durable_rename() to rename the archive status files. As a consequence, the server is more likely to attempt to re-archive files after a crash, but as noted above, archive commands and modules are already expected to handle this. It is also possible that the server will attempt to re- archive files that have been removed or recycled, but the archiver already handles this, too. Author: Nathan Bossart --- src/backend/postmaster/pgarch.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index 0c8ca29f73..17a4151c01 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 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 --5mCyUwZo2JvN/JJP--