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 1nKntD-0007Ss-D5 for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Feb 2022 21:00:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKntC-0000rt-9m for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Feb 2022 21:00:34 +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 1nKntC-0000rk-0X for pgsql-hackers@lists.postgresql.org; Thu, 17 Feb 2022 21:00:34 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nKnt5-0006pw-5v for pgsql-hackers@postgresql.org; Thu, 17 Feb 2022 21:00:33 +0000 Received: by mail-pj1-x1030.google.com with SMTP id a11-20020a17090a740b00b001b8b506c42fso10554930pjg.0 for ; Thu, 17 Feb 2022 13:00:27 -0800 (PST) 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=ompDT5YmmMIEc6DmmjGz7Fzr4q7mPD5UmZfhY4FRYG4=; b=SNlUwTr0NFJEo6qgfCminh5m4OyhtUgSrrjmZQB771q5Y30UUge3pgpkggwIC0XS3a yYjjEFfKnKLqBAV1Iw8uqK6+hGZiSzUNyKFwGImNOlb5Od+6vMgRalZWSggooy3DX0Bm lKlAjCJ1Z8Jn8i8cQZKYxYCc3OURAh7l91op7qf77/9SPV6iU0/308y18cEKONuHDC/z CG2cFwrOvxi4OZlYbDd/uoEHrxLv4RqWuvyhNZk3m4SzFdAKPyXB27dq1QoORXHPXX65 l+gocEzT8wWOWnsh/GGKA5bP/aElBlO251uzjdA12bWwZ7uCD7cHfQx5S/pqAunuvTkh cFNA== 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=ompDT5YmmMIEc6DmmjGz7Fzr4q7mPD5UmZfhY4FRYG4=; b=7Tjc/VPtdJ9C5+6QQeYOLIMqOofaGVfohDbFD3Pv4fpKybLK/ptf0fjB0TjTJ4qrC1 Itkl4WGwsFG9RXH16qLhXCZZr5G6S8VD9wKEsQVK2ljawWBxCL+W+7Sd6VQ7KOM2icnR nNaBG8GZxG4Qfo0W15wFClyS9Cw7ml9gekIKeNywpGVvTdOgPIxSXcEWpFaRBOAMdJ4X NK9s3KBeGyYv2He6OVQInh7vOY3rqiGsqCLRijJ4ObUGaUyBiuz3Dk1k19jjN6Z2GJll mr52hAcijOfLem4jn/8lKbBWrv6iRVF6VAuG0pG6/ekSv6Fxe7vrC6aMKOPQzcWHV5Zb ZVmw== X-Gm-Message-State: AOAM531PMTS1dwaxBKcC/Kj4vHjWxAJDJJgaggZcBJFdgyLT1a+xZsfC M6OeRQJJnmXedaenjff24pI= X-Google-Smtp-Source: ABdhPJwSX2kNbGIT/+kGZbq/XBb+UV4Bo72RYEwc6ooAJ0SMCAOUH0MmDswj6r56tUDC653IZAY/9Q== X-Received: by 2002:a17:90a:bb0e:b0:1b9:fffa:f030 with SMTP id u14-20020a17090abb0e00b001b9fffaf030mr4846289pjr.206.1645131625146; Thu, 17 Feb 2022 13:00:25 -0800 (PST) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id v9sm509215pfu.60.2022.02.17.13.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 13:00:24 -0800 (PST) Date: Thu, 17 Feb 2022 13:00:22 -0800 From: Nathan Bossart To: Andres Freund Cc: "Bossart, Nathan" , Bharath Rupireddy , Maxim Orlov , Amul Sul , Bruce Momjian , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: O(n) tasks cause lengthy startups and checkpoints Message-ID: <20220217210022.GA3248793@nathanxps13> References: <83A7426F-A7B6-4A10-A8F0-179AE30B871D@amazon.com> <20220211180249.GA1886051@nathanxps13> <20220217005057.GA3201038@nathanxps13> <20220217015052.2y3wxibeommk37ey@alap3.anarazel.de> <20220217041404.GA3243546@nathanxps13> <20220217065938.x2esfdppzypegn5j@alap3.anarazel.de> <20220217182337.GA3247866@nathanxps13> <20220217192709.eyf2cnymhxqsals7@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220217192709.eyf2cnymhxqsals7@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Feb 17, 2022 at 11:27:09AM -0800, Andres Freund wrote: > On 2022-02-17 10:23:37 -0800, Nathan Bossart wrote: >> On Wed, Feb 16, 2022 at 10:59:38PM -0800, Andres Freund wrote: >> > They're accessed by xid. The LSN is just for cleanup. Accessing files >> > left over from a previous transaction with the same xid wouldn't be >> > good - we'd read wrong catalog state for decoding... >> >> Okay, that part makes sense to me. However, I'm still confused about how >> this is handled today and why moving cleanup to a separate auxiliary >> process makes matters worse. > > Right now cleanup happens every checkpoint. So cleanup can't be deferred all > that far. We currently include a bunch of 32bit xids inside checkspoints, so > if they're rarer than 2^31-1, we're in trouble independent of logical > decoding. > > But with this patch cleanup of logical decoding mapping files (and other > pieces) can be *indefinitely* deferred, without being noticeable. I see. The custodian should ordinarily remove the files as quickly as possible. In fact, I bet it will typically line up with checkpoints for most users, as the checkpointer will set the latch. However, if there are many temporary files to clean up, removing the logical decoding files could be delayed for some time, as you said. > One possible way to improve this would be to switch the on-disk filenames to > be based on 64bit xids. But that might also present some problems (file name > length, cost of converting 32bit xids to 64bit xids). Okay. >> I've done quite a bit of reading, and I haven't found anything that seems >> intended to prevent this problem. Do you have any pointers? > > I don't know if we have an iron-clad enforcement of checkpoints happening > every 2*31-1 xids. It's very unlikely to happen - you'd run out of space > etc. But it'd be good to have something better than that. Okay. So IIUC the problem might already exist today, but offloading these tasks to a separate process could make it more likely. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com