Subject: Parallelizing startup with many databases

From: Babak Ghadiri <[email-masked]>
Date: Fri, 2 Jan 2026 11:25:07 +0330

Hello,
I hope you are doing well.

In PostgreSQL 16, startup appears to initialize databases sequentially and
primarily uses a single CPU core. In clusters with a very large number of
databases (around 5,000 in our case), this results in noticeably long
startup times after restarts or crash recovery.

I would like to ask:

- Is the largely single-threaded startup behavior a fundamental
architectural
  constraint (e.g. catalog dependencies, locking, recovery ordering), or
mainly
  an unimplemented optimization?
- Are there any existing discussions, patches, versions (18+) to
parallelize parts of startup or otherwise improve startup scalability with
many databases?
- Are there any PostgreSQL configuration settings known to dramatically
reduce startup time, or is startup performance mostly fixed by architecture
in this scenario?

I understand that having many databases in a single cluster is not the most
common or recommended multi-tenant model, but this is an existing system and
I’m trying to better understand the current limits and future direction.

Thank you for your time and insights.

Best regards.

---

From: Andreas Karlsson <[email-masked]>
Date: Sat, 3 Jan 2026 00:38:10 +0100

> startup times after restarts or crash recovery.

Have you measured what is actually causing the slow startup? Without 
knowing what is actually slow it is hard to say if threading would even 
help.

How slow are we talking about and have you managed to create a minimal 
case for reproducing the issue?

>    constraint (e.g. catalog dependencies, locking, recovery ordering), 
> or mainly

PostgreSQL does not support threading, it uses a multi-process model to 
implement for example parallel queries. And there is no way threading 
would be introduced just to improved startup performance.

> parallelize parts of startup or otherwise improve startup scalability 
> with many databases?

Not as far as I am aware but you can search our archives.

> reduce startup time, or is startup performance mostly fixed by 
> architecture in this scenario?

I would first start trying to figure out why startup is slow before 
doing anything else.

Andreas

---

From: Tom Lane <[email-masked]>
Date: Fri, 02 Jan 2026 19:02:27 -0500

> knowing what is actually slow it is hard to say if threading would even 

"perf" results would likely be useful.

I tried creating 5000 databases here and didn't notice any particular
increase in server startup time (didn't try crash-recovery case).
So whatever this is is likely somewhat configuration- or
platform-dependent.

Having said that, 5000 databases sounds like an anti-pattern to
begin with.  You're paying for an additional copy of the system
catalogs for each one.

			regards, tom lane

---

From: Jelte Fennema-Nio <[email-masked]>
Date: Sat, 3 Jan 2026 01:58:25 +0100

> startup times after restarts or crash recovery.

You probably want to consider setting:
recovery_init_sync_method=syncfs

I'm 99% certain that that will solve your problem.

https://www.postgresql.org/docs/current/runtime-config-error-handling.html

https://www.postgresql.org/message-id/flat/[email-masked]

PS It took me way to long to find that setting. I think we should move it
from the error handling docs page to the page with all of the other
recovery settings.
https://www.postgresql.org/docs/current/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY

---

From: Andreas Karlsson <[email-masked]>
Date: Sat, 3 Jan 2026 20:09:00 +0100

On 1/3/26 1:58 AM, Jelte Fennema-Nio wrote:
> PS It took me way to long to find that setting. I think we should move 
> it from the error handling docs page to the page with all of the other 
> recovery settings. https://www.postgresql.org/docs/current/runtime- 
> config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY <https://www.postgresql.org/ 
> docs/current/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY>

I agree that it is currently not in exactly a great location but the 
issue is that the "Recovery" section is a subsection of the "WAL" 
section, and syncing the data directory is only loosely related to WAL. 
One could argue it is related to WAL as in that it is something done 
before replaying WAL but it is not an obvious location either. Or is it?

Andreas

---

From: "Jelte Fennema-Nio" <[email-masked]>
Date: Sun, 04 Jan 2026 00:26:33 +0100

> before replaying WAL but it is not an obvious location either. Or is it?

<Moving this discussion to pgsql-docs, with accompanying patch>

While the setting is not strictly related to WAL it still seems a much
more natural place than the "Error handling" page. Especially because of
the description of this subheading:

> This section describes the settings that apply to recovery in general,
> affecting crash recovery, streaming replication and archive-based
> replication.

The only recovery related GUC that exists that's not on the WAL page is
recovery_min_apply_delay, which is under the Replication->Standby
section. Since that GUC is only valid on standbys that seems like a
sensible choice.
From 1ec7e36748ecf3d0c7e4333137c390658dc43e20 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <[email-masked]>
Date: Sun, 4 Jan 2026 00:09:13 +0100
Subject: [PATCH v1] docs: Move recovery_init_sync_method to WAL->Recovery
 section

The recovery_init_sync_method GUC was separated from all other recovery
related GUCS in our docs. This made it pretty hard to find in the docs
if you don't know exactly what you're looking for. This moves it to the
generic "Recovery" section on the WAL page. While it's not really
related to WAL it still seems a much more natural place than the "Error
handling" page. Especially because of the description of this subheading:

> This section describes the settings that apply to recovery in general,
> affecting crash recovery, streaming replication and archive-based
> replication.

The only recovery related GUC that exists that's not on the WAL page is
recovery_min_apply_delay, which is under the Replication->Standby
section. Since that GUC is only valid on standbys that seems like a
sensible choice.
---
 doc/src/sgml/config.sgml | 78 ++++++++++++++++++++--------------------
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index cdfe8e376f0..a38747c937e 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -3991,6 +3991,45 @@ include_dir 'conf.d'
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-recovery-init-sync-method" xreflabel="recovery_init_sync_method">
+      <term><varname>recovery_init_sync_method</varname> (<type>enum</type>)
+       <indexterm>
+        <primary><varname>recovery_init_sync_method</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        When set to <literal>fsync</literal>, which is the default,
+        <productname>PostgreSQL</productname> will recursively open and
+        synchronize all files in the data directory before crash recovery
+        begins.  The search for files will follow symbolic links for the WAL
+        directory and each configured tablespace (but not any other symbolic
+        links).  This is intended to make sure that all WAL and data files are
+        durably stored on disk before replaying changes.  This applies whenever
+        starting a database cluster that did not shut down cleanly, including
+        copies created with <application>pg_basebackup</application>.
+       </para>
+       <para>
+        On Linux, <literal>syncfs</literal> may be used instead, to ask the
+        operating system to synchronize the file systems that contain the
+        data directory, the WAL files and each tablespace (but not any other
+        file systems that may be reachable through symbolic links).  This may
+        be a lot faster than the <literal>fsync</literal> setting, because it
+        doesn't need to open each file one by one.  On the other hand, it may
+        be slower if a file system is shared by other applications that
+        modify a lot of files, since those files will also be written to disk.
+        Furthermore, on versions of Linux before 5.8, I/O errors encountered
+        while writing data to disk may not be reported to
+        <productname>PostgreSQL</productname>, and relevant error messages may
+        appear only in kernel logs.
+       </para>
+       <para>
+        This parameter can only be set in the
+        <filename>postgresql.conf</filename> file or on the server command line.
+       </para>
+      </listitem>
+     </varlistentry>
+
     </variablelist>
    </sect2>
 
@@ -11714,45 +11753,6 @@ dynamic_library_path = '/usr/local/lib/postgresql:$libdir'
       </listitem>
      </varlistentry>
 
-     <varlistentry id="guc-recovery-init-sync-method" xreflabel="recovery_init_sync_method">
-      <term><varname>recovery_init_sync_method</varname> (<type>enum</type>)
-       <indexterm>
-        <primary><varname>recovery_init_sync_method</varname> configuration parameter</primary>
-       </indexterm>
-      </term>
-      <listitem>
-       <para>
-        When set to <literal>fsync</literal>, which is the default,
-        <productname>PostgreSQL</productname> will recursively open and
-        synchronize all files in the data directory before crash recovery
-        begins.  The search for files will follow symbolic links for the WAL
-        directory and each configured tablespace (but not any other symbolic
-        links).  This is intended to make sure that all WAL and data files are
-        durably stored on disk before replaying changes.  This applies whenever
-        starting a database cluster that did not shut down cleanly, including
-        copies created with <application>pg_basebackup</application>.
-       </para>
-       <para>
-        On Linux, <literal>syncfs</literal> may be used instead, to ask the
-        operating system to synchronize the file systems that contain the
-        data directory, the WAL files and each tablespace (but not any other
-        file systems that may be reachable through symbolic links).  This may
-        be a lot faster than the <literal>fsync</literal> setting, because it
-        doesn't need to open each file one by one.  On the other hand, it may
-        be slower if a file system is shared by other applications that
-        modify a lot of files, since those files will also be written to disk.
-        Furthermore, on versions of Linux before 5.8, I/O errors encountered
-        while writing data to disk may not be reported to
-        <productname>PostgreSQL</productname>, and relevant error messages may
-        appear only in kernel logs.
-       </para>
-       <para>
-        This parameter can only be set in the
-        <filename>postgresql.conf</filename> file or on the server command line.
-       </para>
-      </listitem>
-     </varlistentry>
-
     </variablelist>
 
    </sect1>

base-commit: 094b61ce3ebbb1258675cb9b4eca9198628e2177
-- 
2.52.0

---

From: Andreas Karlsson <[email-masked]>
Date: Sun, 4 Jan 2026 00:55:05 +0100

> <Moving this discussion to pgsql-docs, with accompanying patch>
If we move the GUC in the documentation shouldn't we also move it in 
postgresql.conf.sample? The sections in the documentation and the 
sections in the sample config file seem to be the same.

Andreas

---

From: Tom Lane <[email-masked]>
Date: Sat, 03 Jan 2026 19:02:13 -0500

> sections in the sample config file seem to be the same.

You would also need to change the group that the GUC is assigned to
in guc_parameters.dat.  So this isn't really a docs-only patch.
(I agree that the GUC seems misclassified as-is.)

			regards, tom lane

---

From: "Jelte Fennema-Nio" <[email-masked]>
Date: Sun, 04 Jan 2026 11:15:41 +0100

> (I agree that the GUC seems misclassified as-is.)

Good points. Attached an updated patch that changes
postgresql.conf.sample and the group too. 

I didn't move the thread back to pgsql-hackers though, since changing
the location once more seemed counterproductive. Especially since it's
still a docs change at heart.
From a5a7213ea2394208a2d69c1dcec26017948d2279 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <[email-masked]>
Date: Sun, 4 Jan 2026 00:09:13 +0100
Subject: [PATCH v2] Move recovery_init_sync_method GUC to WAL_RECOVERY group

> affecting crash recovery, streaming replication and archive-based

To make this doc change it also updates the group and place in
postgresql.conf accordingly. The latter of which also required changing
the section header in postgresql.conf.sample to match the header in the
docs.

The only recovery related GUC that exists that's not on the WAL page is
recovery_min_apply_delay, which is under the Replication->Standby
section. Since that GUC is only valid on standbys that seems like a
sensible choice.
---
 doc/src/sgml/config.sgml                      | 78 +++++++++----------
 src/backend/utils/misc/guc_parameters.dat     |  2 +-
 src/backend/utils/misc/postgresql.conf.sample | 10 +--
 3 files changed, 45 insertions(+), 45 deletions(-)

 

    </sect1>
diff --git a/src/backend/utils/misc/guc_parameters.dat b/src/backend/utils/misc/guc_parameters.dat
index cf87c09ca3b..13295737b49 100644
--- a/src/backend/utils/misc/guc_parameters.dat
+++ b/src/backend/utils/misc/guc_parameters.dat
@@ -2321,7 +2321,7 @@
   boot_val => '""',
 },
 
-{ name => 'recovery_init_sync_method', type => 'enum', context => 'PGC_SIGHUP', group => 'ERROR_HANDLING_OPTIONS',
+{ name => 'recovery_init_sync_method', type => 'enum', context => 'PGC_SIGHUP', group => 'WAL_RECOVERY',
   short_desc => 'Sets the method for synchronizing the data directory before crash recovery.',
   variable => 'recovery_init_sync_method',
   boot_val => 'DATA_DIR_SYNC_METHOD_FSYNC',
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index dc9e2255f8a..6e7472181b3 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -267,11 +267,12 @@
 #max_wal_size = 1GB
 #min_wal_size = 80MB
 
-# - Prefetching during recovery -
+# - Recovery -
 
-#recovery_prefetch = try        # prefetch pages referenced in the WAL?
-#wal_decode_buffer_size = 512kB # lookahead window used for prefetching
-                                # (change requires restart)
+#recovery_prefetch = try                # prefetch pages referenced in the WAL?
+#wal_decode_buffer_size = 512kB         # lookahead window used for prefetching
+                                        # (change requires restart)
+#recovery_init_sync_method = fsync      # fsync, syncfs (Linux 5.8+)
 
 # - Archiving -
 
@@ -868,7 +869,6 @@
 #data_sync_retry = off                  # retry or panic on failure to fsync
                                         # data?
                                         # (change requires restart)
-#recovery_init_sync_method = fsync      # fsync, syncfs (Linux 5.8+)

 #------------------------------------------------------------------------------

---

From: Andreas Karlsson <[email-masked]>
Date: Wed, 14 Jan 2026 07:43:35 +0100

> postgresql.conf.sample and the group too.

Nice, I think this makes things a lot clearer!

Andreas