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 1tDSpg-000tqe-9n for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Nov 2024 18:20:12 +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 1tDSpe-00FpaK-Bk for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Nov 2024 18:20:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tDSpd-00FpZK-Ve for pgsql-hackers@lists.postgresql.org; Tue, 19 Nov 2024 18:20:10 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tDSpY-002n6x-0K for pgsql-hackers@postgresql.org; Tue, 19 Nov 2024 18:20:09 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-6ee6a2ae6ecso38224757b3.3 for ; Tue, 19 Nov 2024 10:20:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732040402; x=1732645202; darn=postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=YZVaefGotdhHXQPBCAo2kPjouewSZ9fP1o4AfSlVzaI=; b=kt+WF5ht4iLVhgat/Ru8/RzoyEWVUlzvzi87P3oGCHEJeF6TMBbtuTQWDzpVLCT7oH z2wIFS1vQ86T1izJlzdJtvFarUj07KPccMcJFm3ncw3DUnNqrghFMUv74Gkc9M+0lWyt vn40iPOa0qIOJpNCdaybwewv52QNzAmDTnrENYycWRtRGMMWbQdneenzDIbcIq/IU6hV A/RU2RIaAwSDiT218NLNIzrm1bKv/Jk9KvctsXrXVnPAMeqOPRT9PRud33b8+WhnenAi GzJQ3IdesI+apgxeIIPICqu8pDmn9kQB7yXSj34kPgTdlEjJW6xL0WTjCh/Lwymtqz+H lmRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732040402; x=1732645202; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YZVaefGotdhHXQPBCAo2kPjouewSZ9fP1o4AfSlVzaI=; b=X2Hmk5RmIEadWD2kFoJM6EVsf+HmimnSr2VN7w+UdOJrHwrcRRPQIR10JCBdv7o15i 1ABlz46h093RP08ysuGJsNW9V/nDJcAuWsnwSN67p7WAw5dICHbUZz4tBnH0MFKFJvYB mKvbNe9a06O82+11y7ynsqVTT4lAqJnqs2/SQ72iaL6DMLJa8Z9xnh1L1Ofs8u/C8BT/ DYd6MWFx9Zp5pRxM0p/KLfpDT9ZBHZk88XGK3OBrIO2Ymidlh0jjKpKPdfgkvxH4lcKI t3i4D4kxR0pJHbFKiZOvPJFGJosPB7z4B43Y2lCbrxdki76lM0m60Orfq3zL0TbPBEOR sVAQ== X-Gm-Message-State: AOJu0Ywuqnt1wsV50Fo5K3G610g1I1OLh1w4JKcpyAnF71h0KVsQLV7F gpFj7Vc4BOq5u0KNgvPg0TkDUTQogoob5nKObK2fZgBCGq+gFTCG X-Google-Smtp-Source: AGHT+IGgO7XrhUOUUSNXK6XWWgiIoOjqUv7DX7/QXi9m0WNM+xas0Mm0vWcveXwBvdZWfcFk+4536w== X-Received: by 2002:a05:690c:6283:b0:6ee:9cb7:dc24 with SMTP id 00721157ae682-6ee9cb7decdmr65887917b3.38.1732040402064; Tue, 19 Nov 2024 10:20:02 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b37a896398sm117161985a.83.2024.11.19.10.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 10:20:01 -0800 (PST) Date: Tue, 19 Nov 2024 12:20:00 -0600 From: Nathan Bossart To: Greg Sabino Mullane Cc: pgsql-hackers@postgresql.org Subject: Re: optimize file transfer in pg_upgrade Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Nov 17, 2024 at 01:50:53PM -0500, Greg Sabino Mullane wrote: > On Wed, Nov 6, 2024 at 5:07 PM Nathan Bossart > wrote: >> Therefore, it can be much faster to instead move the entire data directory >> from the old cluster >> to the new cluster and to then swap the catalog relation files. > > Thank you for breaking this up so clearly into separate commits. I think it > is a very interesting idea, and anything to speed up pg_upgrade is always > welcome. Some minor thoughts: Thank you for reviewing! >> .. we don't really expect there to be directories within database > directories, >> so perhaps it would be better to either unconditionally rename or to fail. > Failure seems the best option here, so we can cleanly handle any future > cases in which we decide to put dirs in this directory. Good point. >> if (RelFileNumberIsValid(rfn)) >> { >> FileNameMap key; >> >> key.relfilenumber = (RelFileNumber) rfn; >> if (bsearch(&key, context->maps, context->size, >> sizeof(FileNameMap), FileNameMapCmp)) >> return 0; >> } >> >> snprintf(dst, sizeof(dst), "%s/%s", context->target, filename); >> if (rename(fname, dst) != 0) > > I'm not quite clear what we are doing here with falling through > for InvalidOid entries, could you explain? The idea is that if it looks like a data file that we might want to transfer (i.e., it starts with a RelFileNumber), we should consult our map to determine whether to move it. Otherwise, we want to unconditionally transfer it so that we always use the files generated during pg_restore in the new cluster (e.g., PG_VERSION and pg_filenode.map). In theory, this should result in the same end state as what --link mode does today (for the new cluster, at least). >> .. vm_must_add_frozenbit isn't handled yet. We could either disallow >> using catalog-swap mode if the upgrade involves versions older than v9.6 > > Yes, this. No need for more code to handle super old versions when other > options exist. I'm inclined to agree. >> with this problem is to introduce a special mode for "initdb --sync-only" >> that calls fsync() for everything _except_ the actual data files. If we >> fsync() the new catalog files as we move them into place, and if we assume >> that the old catalog files will have been properly synchronized before >> upgrading, there's no reason to synchronize them again at the end. > > Very cool approach! :) -- nathan