pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: pgsql-hackers@postgresql.org
Subject: use CREATE DATABASE STRATEGY = FILE_COPY in pg_upgrade
Date: Tue, 4 Jun 2024 14:39:23 -0500
Message-ID: <Zl9ta3FtgdjizkJ5@nathan> (raw)

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

Attachments:

use_file_copy_for_pg_upgrade.patch (text/plain, 514B) download 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

view thread (21+ messages)  latest in thread

Message-ID: <Zl9ta3FtgdjizkJ5@nathan>
Permalink:  ../Zl9ta3FtgdjizkJ5@nathan/
Also on:    postgresql.org/message-id/Zl9ta3FtgdjizkJ5@nathan

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com
  Subject: Re: use CREATE DATABASE STRATEGY = FILE_COPY in pg_upgrade
  In-Reply-To: <Zl9ta3FtgdjizkJ5@nathan>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox