Skip to content

Commit ad43a41

Browse files
committed
initdb: When running CREATE DATABASE, use STRATEGY = WAL_COPY.
Dilip Kumar, reviewed by Andres Freund and by me. Discussion: http://postgr.es/m/20220330011757.wr544o5y5my7ssoa@alap3.anarazel.de
1 parent f3dd9fe commit ad43a41

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/bin/initdb/initdb.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,10 +1860,15 @@ make_template0(FILE *cmdfd)
18601860
* objects in the old cluster, the problem scenario only exists if the OID
18611861
* that is in use in the old cluster is also used in the new cluster - and
18621862
* the new cluster should be the result of a fresh initdb.)
1863+
*
1864+
* We use "STRATEGY = file_copy" here because checkpoints during initdb
1865+
* are cheap. "STRATEGY = wal_log" would generate more WAL, which would
1866+
* be a little bit slower and make the new cluster a little bit bigger.
18631867
*/
18641868
static const char *const template0_setup[] = {
18651869
"CREATE DATABASE template0 IS_TEMPLATE = true ALLOW_CONNECTIONS = false OID = "
1866-
CppAsString2(Template0ObjectId) ";\n\n",
1870+
CppAsString2(Template0ObjectId)
1871+
" STRATEGY = file_copy;\n\n",
18671872

18681873
/*
18691874
* template0 shouldn't have any collation-dependent objects, so unset
@@ -1906,9 +1911,12 @@ make_postgres(FILE *cmdfd)
19061911
{
19071912
const char *const *line;
19081913

1909-
/* Assign a fixed OID to postgres, for the same reasons as template0 */
1914+
/*
1915+
* Just as we did for template0, and for the same reasons, assign a fixed
1916+
* OID to postgres and select the file_copy strategy.
1917+
*/
19101918
static const char *const postgres_setup[] = {
1911-
"CREATE DATABASE postgres OID = " CppAsString2(PostgresObjectId) ";\n\n",
1919+
"CREATE DATABASE postgres OID = " CppAsString2(PostgresObjectId) " STRATEGY = file_copy;\n\n",
19121920
"COMMENT ON DATABASE postgres IS 'default administrative connection database';\n\n",
19131921
NULL
19141922
};

0 commit comments

Comments
 (0)