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 1sEa0I-002Hyp-Mc for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Jun 2024 19:39:32 +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 1sEa0I-002BuO-MZ for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Jun 2024 19:39:30 +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 1sEa0I-002BuG-Cx for pgsql-hackers@lists.postgresql.org; Tue, 04 Jun 2024 19:39:30 +0000 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sEa0G-0000Ow-1F for pgsql-hackers@postgresql.org; Tue, 04 Jun 2024 19:39:29 +0000 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7eb326607edso39084039f.3 for ; Tue, 04 Jun 2024 12:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717529966; x=1718134766; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=ZB+sXo1dkeXJRIDzXflAl4rZrmilmQKeTUwRkzB27Nw=; b=J90QGmLy6tob8CYVgcK9o9hivMngWwjb2uaRlvray3i7wAbLpSgZelrZTt1Tzl10C7 KcUI+cP/oVLNEwMywBEcd81aI4IUghVHtOEEP+9LarUliTO4sRn15uUtNzz7s+xu5dd0 MvXByEUlNHHTeGKuSStAq+eH3uSpVufnfIGw7Lq7CAkaQVq7GOFMzGuf+Kx5b8as2V0R oobtPIuymmbcbvSdKxw1hTSygPOsruRUmGpJJLT+z758JWVUNbDm3pFe+Av0lzxzYBP9 pLQPopXQM/BWAcjTTGF3xOo2vbkuGyyV93F4pJ6HF0KUQticF6lLne7+bERPpeW4/XcW Yg4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717529966; x=1718134766; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZB+sXo1dkeXJRIDzXflAl4rZrmilmQKeTUwRkzB27Nw=; b=rOPks3A40nS9jXzWT54zIhyauAXC2XbUA25sbFBnRbiLSzk88uqMsTQNw34eacOp2o 2Jdwh1Zk4f6h2xzCfInC8wR1WB1ea0g281QgMhP1JFWpnNABgHof8YNfcLgcu6HJ6//i aRXWimSi3VhA6+RlPnYcEQrXnCucWeWzJvz8s7t5tuuKbJZX8PdHJhPThn4M/6yikng5 MZouOHpf3/NYKcxUIUKI+lBUByF6QAwEgt35OznHcLAnZuskeHugz8NVRSjivhF0m7xw F4806MwNSTtg+8AyEcsBYKHbZ+1r9hQZHeVeFhJojinJH//ZbjZaA11ZGMIW2vuc8/A2 iFFw== X-Gm-Message-State: AOJu0YzoSkX8VCkawp/VtuBy7OdfsyA0WEOpE57X8ysCld/qUOzWp3aM fKEEOSh79iL7fgKPCtp65LEJ7rHhX3hPMH/CuiVedVhg5QCul05gIWeB2A== X-Google-Smtp-Source: AGHT+IEQX7AC2558lciiVuKfbkREHKQ6itPHPoOnT6xYGOGiCHEkYpc+s0qkwMSNYINpS9YORhuzwg== X-Received: by 2002:a05:6602:21ce:b0:7de:dea5:4bb0 with SMTP id ca18e2360f4ac-7eb3ca6a27fmr33634339f.16.1717529965362; Tue, 04 Jun 2024 12:39:25 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4b48764e71asm2592815173.31.2024.06.04.12.39.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 12:39:24 -0700 (PDT) Date: Tue, 4 Jun 2024 14:39:23 -0500 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: use CREATE DATABASE STRATEGY = FILE_COPY in pg_upgrade Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="KO2Ht27sYUykHtZV" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --KO2Ht27sYUykHtZV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I noticed that the "Restoring database schemas in the new cluster" part of pg_upgrade can take a while if you have many databases, so I experimented with a couple different settings to see if there are any easy ways to speed it up. The FILE_COPY strategy for CREATE DATABASE helped quite significantly on my laptop. For ~3k empty databases, this step went from ~100 seconds to ~30 seconds with the attached patch. I see commit ad43a41 made a similar change for initdb, so there might even be an argument for back-patching this to v15 (where STRATEGY was introduced). One thing I still need to verify is that this doesn't harm anything when there are lots of objects in the databases, i.e., more WAL generated during many concurrent CREATE-DATABASE-induced checkpoints. Thoughts? -- nathan --KO2Ht27sYUykHtZV Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="use_file_copy_for_pg_upgrade.patch" diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index e324070828..bc9fef4198 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -3126,7 +3126,9 @@ dumpDatabase(Archive *fout) */ if (dopt->binary_upgrade) { - appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0 OID = %u", + appendPQExpBuffer(creaQry, + "CREATE DATABASE %s WITH TEMPLATE = template0 " + "OID = %u STRATEGY = FILE_COPY", qdatname, dbCatId.oid); } else --KO2Ht27sYUykHtZV--