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 1nebZl-00049a-9n for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Apr 2022 11:54:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nebZk-0004mt-5r for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Apr 2022 11:54:20 +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 1nebZj-0004mj-P9 for pgsql-hackers@lists.postgresql.org; Wed, 13 Apr 2022 11:54:19 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nebZg-00087e-FB for pgsql-hackers@postgresql.org; Wed, 13 Apr 2022 11:54:19 +0000 Received: by mail-io1-xd32.google.com with SMTP id x4so1540119iop.7 for ; Wed, 13 Apr 2022 04:54:15 -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=I6C2pDPuYCpw3Ai22lBL+pt45mupFy3Y9/9XCy1hUGc=; b=QGbSQ3z7eBUvj1PvodDx3XFPlO6528L33OZkFOx33BTl9Yo3Vz7ubDc/LcTRnVhQe1 uYSDJF+AleWKCLCuUfoQUeoSmX8Wv96hMBTaZHv/I3RBuV8kC3bvg2BIVfd2LAAoE4Js W+1S1HHpVIo/UIOvLOR4AdjnBUMOCgHK3h5L+jdnUi8/WkdmxTj7q8qtSaTlTj1OkIyS eaivm8zzmulqWqjhhTWOW3gYtOnqOqSKHP1fsZv1bzh72TQnMfHWZbgqA4ciTKoVKpxU kowSDYC4HGOuScjeP9CWo2mdTzezvRoWJAu1hqv6aUi9VL2QyTv4h+lhymRw1C+hKJNX 3M+w== 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=I6C2pDPuYCpw3Ai22lBL+pt45mupFy3Y9/9XCy1hUGc=; b=U4usQhgS2z9gllpKo1ZbXZm5I/udUx03V4gYCKoivt7PxXtmmDLcx1rhtZfw/EWdPX JfHM97RYMDAFINpyp8Hu8vkHS2RviJnGG2/9GD0fQtEQW0f5/hnS7UW29Iol+PyKZQd1 AJOYckR/jyehOyfYRHTHHdCM+T+QChhu9TUaVEq4uEKOj3RcsFo00phVhiGoRL80Mv1J +N/vfd2tujDttwZ5RroXiguR0/oHBpd9mKPER76Wf9tXMPcTNjw9ZnXnjBYqTI74sU14 xrHEQn6srl5N96Fb/xf80FNexhf/fytxMeZyVkCTSyMGg8rCyDZ9Oh6k3u1OZrF3fqv4 /RXg== X-Gm-Message-State: AOAM5314U0pQ7fVdh/XGFHr5+NsVnTGFqX8nzRXYJbpc4wImgzISprHs 52yzx54BnRLcnEGtbHHKWKpUiQ== X-Google-Smtp-Source: ABdhPJw+jZ0SWNX18TVhSS2Q0TEoev0jjizdvIIvPL6MUJenSx+MQWcyWQQzywD3ld1Kl1dLImOzZg== X-Received: by 2002:a02:90c9:0:b0:323:98e6:1ae8 with SMTP id c9-20020a0290c9000000b0032398e61ae8mr21261948jag.15.1649850854488; Wed, 13 Apr 2022 04:54:14 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id s13-20020a6bdc0d000000b006408888551dsm23062730ioc.8.2022.04.13.04.54.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Apr 2022 04:54:13 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 9C2AF8004DB; Wed, 13 Apr 2022 06:54:12 -0500 (CDT) Date: Wed, 13 Apr 2022 06:54:12 -0500 From: Justin Pryzby To: Michael Paquier Cc: Thomas Munro , David Steele , Fujii Masao , Bruce Momjian , Paul Guo , Tom Lane , Michael Brown , pgsql-hackers@postgresql.org Subject: Re: should frontend tools use syncfs() ? Message-ID: <20220413115412.GM26620@telsasoft.com> References: <20210930004340.GM831@telsasoft.com> 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 Thu, Sep 30, 2021 at 12:49:36PM +0900, Michael Paquier wrote: > On Wed, Sep 29, 2021 at 07:43:41PM -0500, Justin Pryzby wrote: > > Forking this thread in which Thomas implemented syncfs for the startup process > > (61752afb2). > > https://www.postgresql.org/message-id/flat/CA%2BhUKG%2BSG9jSW3ekwib0cSdC0yD-jReJ21X4bZAmqxoWTLTc2A%40mail.gmail.com > > > > Is there any reason that initdb/pg_basebackup/pg_checksums/pg_rewind shouldn't > > use syncfs() ? > > That makes sense. > > > do_syncfs() is in src/backend/ so would need to be duplicated^Wimplemented in > > common. > > The fd handling in the backend makes things tricky if trying to plug > in a common interface, so I'd rather do that as this is frontend-only > code. > > > They can't use the GUC, so need to add an cmdline option or look at an > > environment variable. > > fsync_pgdata() is going to manipulate many inodes anyway, because > that's a code path designed to do so. If we know that syncfs() is > just going to be better, I'd rather just call it by default if > available and not add new switches to all the frontend tools in need > of flushing the data folder, switches that are not documented in your > patch. It is a draft/POC, after all. The argument against using syncfs by default is that it could be worse than recursive fsync if a tiny 200MB postgres instance lives on a shared filesystem along with other, larger applications (maybe a larger postgres instance). There's also an argument that syncfs might be unreliable in the case of a write error. (But I agreed with Thomas' earlier assessment: that claim caries little weight since fsync() itself wasn't reliable for 20some years). I didn't pursue this patch, as it's easier for me to use /bin/sync -f. Someone should adopt it if interested. -- Justin