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 1kdUPG-0001iS-FQ for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Nov 2020 08:26:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kdUMa-0003a2-PQ for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Nov 2020 08:23: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 1kdUMa-0003Zu-Gh for pgsql-hackers@lists.postgresql.org; Fri, 13 Nov 2020 08:23:20 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kdUMX-0001wE-Jn for pgsql-hackers@lists.postgresql.org; Fri, 13 Nov 2020 08:23:19 +0000 Received: by mail-pf1-x42d.google.com with SMTP id v12so6977274pfm.13 for ; Fri, 13 Nov 2020 00:23:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=35Q89l2+xq5bLSAQSdkqVC8ozo0hf8dgR5nwSWTe7Xc=; b=cA4qetGzSK7KxA0GX7ST9JbsKqaRYc/FJyDoNHdIkM+stFX708eV1ji1DNwg/9EuFb lvcH6qSuZr+VHFvjpUYb/habAkM0vFlgASdFG43z9d5t+kBX8QUzfFM3D4ZEq+tEYR/J tRYeWmPh6TfWPG7yibO1qQ303dKnSfNa2/GG7Xfl9fRuAZBe/wA2RQfS5K0AjDLBAv94 n4UaXWlwk0xlG1a8sm2rjROlijrPXt31piNlX9s7FrMKgHXorlegKJawjVoRL3vfSxaC UsXfZSltPwaUDfhO5M0i/CCHwJGacHqU24WJtSWUMOMAAQe0xS6MryVkWIoHF9+I0GIe 4f6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=35Q89l2+xq5bLSAQSdkqVC8ozo0hf8dgR5nwSWTe7Xc=; b=TNaEGZABlcblOtg+glHvj0K0y13n5Zp+v86vLpek9YNLFqVO7a6zgF1jtF3qYBS/Ge tNGwLkFOq6i6pwICyXroVVm0sULRM2xW+q8yYmn6CNWs5DFXoDNu2ua1YodnW3MAMJSD Wc8MDmO3d1v9+oDPXOt1knLdwXUy30ty8M51NqtSr8WIXIKWFhnm/14deGiy7op4FwNR E3wPTVUDhoeACwXWBTcO3p6G45PU9PbtOuHr1xfkCCO51xi3xZlj73u/64uoJwPWGcz3 06ixSAHcpWsPDwKUx/GTtekJNqDhApISzhGJkp7m3+xynP8CSrftQPiwHY50x1Ann8lb 3CzQ== X-Gm-Message-State: AOAM532pMzBg0J78G4o4ejcSYAmNfLy+HSmZ74vs04Mhb+batpzZA9ln t1Le4sHxgTKn7ultoU8l9Nc= X-Google-Smtp-Source: ABdhPJwXjXBa6VX7VfesqqQlEmwauhZw68aWEg6UA9FWIVAEUHFzQCywJ3Bn0YPLs29doCEWvEfXjw== X-Received: by 2002:aa7:9308:0:b029:18b:3a1b:f46a with SMTP id 8-20020aa793080000b029018b3a1bf46amr1110497pfj.64.1605255795276; Fri, 13 Nov 2020 00:23:15 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id y23sm9840525pju.35.2020.11.13.00.23.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 00:23:14 -0800 (PST) Date: Fri, 13 Nov 2020 17:23:12 +0900 (JST) Message-Id: <20201113.172312.1767546251154140847.horikyota.ntt@gmail.com> To: osumi.takamichi@fujitsu.com Cc: tsunakawa.takay@fujitsu.com, sfrost@snowman.net, masao.fujii@oss.nttdata.com, ashutosh.bapat.oss@gmail.com, pgsql-hackers@lists.postgresql.org Subject: Re: In-placre persistance change of a relation From: Kyotaro Horiguchi In-Reply-To: References: <20201113.132201.148696021363404735.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 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: Precedence: bulk At Fri, 13 Nov 2020 07:15:41 +0000, "osumi.takamichi@fujitsu.com" wrote in > Hello, Tsunakawa-San > Thanks for sharing it! > > Do you know the reason why data copy was done before? And, it may be > > odd for me to ask this, but I think I saw someone referred to the past > > discussion that eliminating data copy is difficult due to some processing at > > commit. I can't find it. > I can share 2 sources why to eliminate the data copy is difficult in hackers thread. > > Tom's remark and the context to copy relation's data. > https://www.postgresql.org/message-id/flat/31724.1394163360%40sss.pgh.pa.us#31724.1394163360@sss.pgh.pa.us https://www.postgresql.org/message-id/CA+Tgmob44LNwwU73N1aJsGQyzQ61SdhKJRC_89wCm0+aLg=x2Q@mail.gmail.com > No, not really. The issue is more around what happens if we crash > part way through. At crash recovery time, the system catalogs are not > available, because the database isn't consistent yet and, anyway, the > startup process can't be bound to a database, let alone every database > that might contain unlogged tables. So the sentinel that's used to > decide whether to flush the contents of a table or index is the > presence or absence of an _init fork, which the startup process > obviously can see just fine. The _init fork also tells us what to > stick in the relation when we reset it; for a table, we can just reset > to an empty file, but that's not legal for indexes, so the _init fork > contains a pre-initialized empty index that we can just copy over. > > Now, to make an unlogged table logged, you've got to at some stage > remove those _init forks. But this is not a transactional operation. > If you remove the _init forks and then the transaction rolls back, > you've left the system an inconsistent state. If you postpone the > removal until commit time, then you have a problem if it fails, It's true. That are the cause of headache. > particularly if it works for the first file but fails for the second. > And if you crash at any point before you've fsync'd the containing > directory, you have no idea which files will still be on disk after a > hard reboot. This is not an issue in this patch *except* the case where init fork is failed to removed but the following removal of inittmp fork succeeds. Another idea is adding a "not-yet-committed" property to a fork. I added a new fork type for easiness of the patch but I could go that way if that is an issue. > Amit-San quoted this thread and mentioned that point in another thread. > https://www.postgresql.org/message-id/CAA4eK1%2BHDqS%2B1fhs5Jf9o4ZujQT%3DXBZ6sU0kOuEh2hqQAC%2Bt%3Dw%40mail.gmail.com This sounds like a bit differrent discussion. Making part-of-a-table UNLOGGED looks far difficult to me. regards. -- Kyotaro Horiguchi NTT Open Source Software Center