initdb: When running CREATE DATABASE, use STRATEGY = WAL_COPY.
authorRobert Haas <rhaas@postgresql.org>
Thu, 31 Mar 2022 19:15:11 +0000 (15:15 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 31 Mar 2022 19:15:11 +0000 (15:15 -0400)
Dilip Kumar, reviewed by Andres Freund and by me.

Discussion: http://postgr.es/m/20220330011757.wr544o5y5my7ssoa@alap3.anarazel.de

src/bin/initdb/initdb.c

index 5e36943ef3bf364faf2416128097b9f9386d9d97..9dd4a8de9a83f824677030cca6106482e73003dc 100644 (file)
@@ -1860,10 +1860,15 @@ make_template0(FILE *cmdfd)
         * objects in the old cluster, the problem scenario only exists if the OID
         * that is in use in the old cluster is also used in the new cluster - and
         * the new cluster should be the result of a fresh initdb.)
+        *
+        * We use "STRATEGY = file_copy" here because checkpoints during initdb
+        * are cheap. "STRATEGY = wal_log" would generate more WAL, which would
+        * be a little bit slower and make the new cluster a little bit bigger.
         */
        static const char *const template0_setup[] = {
                "CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false OID = "
-               CppAsString2(Template0ObjectId) ";\n\n",
+               CppAsString2(Template0ObjectId)
+               " STRATEGY = file_copy;\n\n",
 
                /*
                 * template0 shouldn't have any collation-dependent objects, so unset
@@ -1906,9 +1911,12 @@ make_postgres(FILE *cmdfd)
 {
        const char *const *line;
 
-       /* Assign a fixed OID to postgres, for the same reasons as template0 */
+       /*
+        * Just as we did for template0, and for the same reasons, assign a fixed
+        * OID to postgres and select the file_copy strategy.
+        */
        static const char *const postgres_setup[] = {
-               "CREATE DATABASE postgres OID = " CppAsString2(PostgresObjectId) ";\n\n",
+               "CREATE DATABASE postgres OID = " CppAsString2(PostgresObjectId) " STRATEGY = file_copy;\n\n",
                "COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n",
                NULL
        };