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 1nczci-0000zN-SC for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Apr 2022 01:10:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nczch-0007du-ER for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Apr 2022 01:10:43 +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 1nczch-0007dl-5N for pgsql-hackers@lists.postgresql.org; Sat, 09 Apr 2022 01:10:43 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nczce-0004p3-NO for pgsql-hackers@postgresql.org; Sat, 09 Apr 2022 01:10:42 +0000 Received: by mail-il1-x12f.google.com with SMTP id x9so7595472ilc.3 for ; Fri, 08 Apr 2022 18:10:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Yi5Qc0I8qNrLVSLbNVAku3vRIuNF59//UYpvXSubDSY=; b=PlyGhrruVtSreXDRJOpXV84kMqA+vEALpPlEcuBQAGizx6CDCnDVRfVACcha5R7zoG af5PkzeWz4qIy1zMRfjOSenSlZHsIknIEKD6QgAbnsEEwEswV8cAaVQVrNizIeOZx56v XffAmVMAUCwxmuFrqV7kuP+9CMcFALa3yfCTUaSGzZcjt2TQwxokIPuMC49QzDhlf1zo 6pb4xOyJSaStAG2OEpGsxox18QWGHo8T74dNcANs/GCG/viyIeUR+rzkb+MVMp2HBKn9 otSJn0iEIYavQRD+Iuy7akkU8eN7zxqCvWY1rymwxb+jTR2LncTtG/Tc0ycfL5pNpF0V zBxA== 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:user-agent; bh=Yi5Qc0I8qNrLVSLbNVAku3vRIuNF59//UYpvXSubDSY=; b=Q8Yft56j6kQkqZEFpN1hvnKNjy63sdYAju5TgtFte+QfgUbEwf2T+SsZdgwotrNL/6 mE690LazaYXiINHcWQdutjv4SMXu0j8ZfGj3UvQFLqWnK7sQoh0ABe+xuqm/tDhh+5Z4 nm6DvUltg9yvHwgGPbqoe4oUK38Yvwa5JG4ngJvnJc6DXp1sOXFPIJhdYyfissrI4jrB FO3aqndFakQk6DajgSiaTgGnpyOSTOsQlq+l9JSEEUGooBLFab/0QCxA2J5WAg7i+lkq 7vObZOlzSbmYlL4dkaST69NXzccYAOtVK5DW+MZtNsN5/rKOktMUGqqtQZDvqb+watnc 4xHQ== X-Gm-Message-State: AOAM531+dr14jgUKpF0GOGVM517LDantw92w/Fd/m2kicqdupLl9mH8X A0JESKl+BOk+Oku8Z3zAbMoK3Q== X-Google-Smtp-Source: ABdhPJxg5lNaP9d1JbvPAJewLeDXcCqZ8rLWZrvSEKCY8k65RUIZTcA5PJlet6I+MDHmcbsWV9KMUw== X-Received: by 2002:a05:6e02:1568:b0:2c9:cb97:973 with SMTP id k8-20020a056e02156800b002c9cb970973mr9260926ilu.132.1649466639162; Fri, 08 Apr 2022 18:10:39 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id b5-20020a056e02048500b002ca5003b9e8sm8783511ils.1.2022.04.08.18.10.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2022 18:10:38 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 334CE800E4F; Fri, 8 Apr 2022 20:10:38 -0500 (CDT) Date: Fri, 8 Apr 2022 20:10:38 -0500 From: Justin Pryzby To: Robert Haas Cc: Nathan Bossart , pgsql-hackers@postgresql.org Subject: Re: avoid multiple hard links to same WAL file after a crash Message-ID: <20220409011037.GN24419@telsasoft.com> References: <20220407182954.GA1231544@nathanxps13> <20220408165312.GB1409034@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Apr 08, 2022 at 09:00:36PM -0400, Robert Haas wrote: > > I think there might be another problem. The man page for rename() seems to > > indicate that overwriting an existing file also introduces a window where > > the old and new path are hard links to the same file. This isn't a problem > > for the WAL files because we should never be overwriting an existing one, > > but I wonder if it's a problem for other code paths. My guess is that many > > code paths that overwrite an existing file are first writing changes to a > > temporary file before atomically replacing the original. Those paths are > > likely okay, too, as you can usually just discard any existing temporary > > files. > > I wonder if this is really true. I thought rename() was supposed to be atomic. Looks like it's atomic in that it's not like cp + rm, but not atomic the other way you want. | If newpath already exists, it will be atomically replaced, so that there is no point at which another process attempting to access newpath will find it missing. However, there will probably be a window in which | both oldpath and newpath refer to the file being renamed.