Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qYzze-003VlB-SB for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Aug 2023 02:22:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qYzzd-0032Df-GN for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Aug 2023 02:22:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qYzzd-0032DP-5p for pgsql-hackers@lists.postgresql.org; Thu, 24 Aug 2023 02:22:40 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qYzzZ-000dF8-JL for pgsql-hackers@lists.postgresql.org; Thu, 24 Aug 2023 02:22:39 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bc83a96067so39382555ad.0 for ; Wed, 23 Aug 2023 19:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692843756; x=1693448556; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=1D3DblR3brH8RO/S3WQfwWortxoRLedZII3totxYuCA=; b=aTSe9/KahyumylOOk8SOuYj5KBCMNCVddqPLn3frPIJvsdyViitbCUclj/zDs4lFXY FBoI4edQvETXuN2Nh4Tfsn0XXOVEF0XhbcZ31BToG47znmfc06kohvSR9I6N3WKVrabO anoUGLD/AK4JbWZ52GdpIkCRqdHGOlrHX7+8nPhnesQnFYIt36KLLGZ2Z+b+RNf0/j3q 88r6C8Kws+MUZK7fIVQxfq9F/NXWI22WRSSAOsbVXqH1gk7gQWEhHFpgN3GklcwsmEdO fLZmIeH5GYx1rPF9doIwB17ubGILbzM2utzt0nBfUeZziIFZnpcI3HrNPk08LF0XKsCO Dubg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692843756; x=1693448556; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1D3DblR3brH8RO/S3WQfwWortxoRLedZII3totxYuCA=; b=Uri7fxvaSz6Khww69TK8x5cJ1EG3aeWy66Px1zObyRo8BjGEtINTvRqeArBWMhFij1 g5PxiIi1b4+EfWM0PUdIzSAOT9Je9xbDUj33MFG9tblX+OhlKfMLFF4W43ioXGsR2U5M Zpxx8bLnNonxH34FRYYeAjorvg2jcR0unJ1LQ4Q7C3FAKzLoThGxaaeuP7UWTKXWrpZ7 YYcjxgagIsq9F9nNtibQiIcSTidvTIYLFIf164wAuAqiBBBqU105XYQWhhYr9WfegXSk ni9Wtm5XGaeA8Mn1GASatAaf8TaUCefs48D6NNybCd4Yq7owRgUHc/WUfH5MFoEt73dT d1tg== X-Gm-Message-State: AOJu0YxIuimXonfUcJG7VnEZydeztrhqlvwKcK5m86mOO8I/BnUCmphl CxjnPsFcNnn2Udi1E9/N+YY= X-Google-Smtp-Source: AGHT+IF4IFjDzM+KHpnCKHQY3ZumUo0sDqYYljwKThCZ+5IgwmjbhqeatGeC8TZeVIPS/2XU4GHWjw== X-Received: by 2002:a17:902:900a:b0:1bd:ccee:8f0e with SMTP id a10-20020a170902900a00b001bdccee8f0emr11871534plp.9.1692843756498; Wed, 23 Aug 2023 19:22:36 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id g3-20020a170902740300b001bdc50316c3sm5582585pll.232.2023.08.23.19.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 19:22:35 -0700 (PDT) Date: Thu, 24 Aug 2023 11:22:32 +0900 (JST) Message-Id: <20230824.112232.1895676924995181515.horikyota.ntt@gmail.com> To: nathandbossart@gmail.com Cc: jakub.wartak@enterprisedb.com, stark.cfm@gmail.com, hlinnaka@iki.fi, barwick@gmail.com, jchampion@timescale.com, pryzby@telsasoft.com, tgl@sss.pgh.pa.us, rjuju123@gmail.com, jakub.wartak@tomtom.com, pgsql-hackers@lists.postgresql.org Subject: Re: In-placre persistance change of a relation From: Kyotaro Horiguchi In-Reply-To: <20230814193848.GA1573015@nathanxps13> References: <20230428.105853.743427640418401945.horikyota.ntt@gmail.com> <20230814193848.GA1573015@nathanxps13> User-Agent: Mew version 6.8 on Emacs 27.2 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thank you for looking this! At Mon, 14 Aug 2023 12:38:48 -0700, Nathan Bossart wrote in > I think there are some good ideas here. I started to take a look at the > patches, and I've attached a rebased version of the patch set. Apologies > if I am repeating any discussions from upthread. > > First, I tested the time difference in ALTER TABLE SET UNLOGGED/LOGGED with > the patch applied, and the results looked pretty impressive. > > before: > postgres=# alter table test set unlogged; > ALTER TABLE > Time: 5108.071 ms (00:05.108) > postgres=# alter table test set logged; > ALTER TABLE > Time: 6747.648 ms (00:06.748) > > after: > postgres=# alter table test set unlogged; > ALTER TABLE > Time: 25.609 ms > postgres=# alter table test set logged; > ALTER TABLE > Time: 1241.800 ms (00:01.242) Thanks for confirmation. The difference between the both directions is that making a table logged requires to emit WAL records for the entire content. > My first question is whether 0001 is a prerequisite to 0002. I'm assuming > it is, but the reason wasn't immediately obvious to me. If it's just In 0002, if a backend crashes after creating an init fork file but before the associated commit, a lingering fork file could result in data loss on the next startup. Thus, an utterly reliable file cleanup mechanism is essential. 0001 also addresses the orphan storage files issue arising from ALTER TABLE and similar commands. > nice-to-have, perhaps we could simplify the patch set a bit. I see that > Heikki had some general concerns with the marker file approach [0], so > perhaps it is at least worth brainstorming some alternatives if we _do_ > need it. The rationale behind the file-based implementation is that any leftover init fork file from a crash needs to be deleted before the reinit(INIT) process kicks in, which happens irrelevantly to WAL, before the start of crash recovery. I could implement it separately from the reinit module, but I didn't since that results in almost a duplication. As commented in xlog.c, the purpose of the pre-recovery reinit CLEANUP phase is to ensure hot standbys don't encounter erroneous unlogged relations. Based on that requirement, we need a mechanism to guarantee that additional crucial operations are executed reliably at the next startup post-crash, right before recovery kicks in (or reinit CLEANUP). 0001 persists this data on a per-operation basis tightly bonded to their target objects. I could turn this into something like undo longs in a simple form, but I'd rather not craft a general-purpose undo log system for this unelss it's absolutely necessary. > [0] https://postgr.es/m/9827ebd3-de2e-fd52-4091-a568387b1fc2%40iki.fi regards. -- Kyotaro Horiguchi NTT Open Source Software Center