pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Haas <rhaas@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add new block-by-block strategy for CREATE DATABASE.
Date: Tue, 29 Mar 2022 15:53:40 +0000
Message-ID: <E1nZEA7-001vFV-Lj@gemulon.postgresql.org> (raw)

Add new block-by-block strategy for CREATE DATABASE.

Because this strategy logs changes on a block-by-block basis, it
avoids the need to checkpoint before and after the operation.
However, because it logs each changed block individually, it might
generate a lot of extra write-ahead logging if the template database
is large. Therefore, the older strategy remains available via a new
STRATEGY parameter to CREATE DATABASE, and a corresponding --strategy
option to createdb.

Somewhat controversially, this patch assembles the list of relations
to be copied to the new database by reading the pg_class relation of
the template database. Cross-database access like this isn't normally
possible, but it can be made to work here because there can't be any
connections to the database being copied, nor can it contain any
in-doubt transactions. Even so, we have to use lower-level interfaces
than normal, since the table scan and relcache interfaces will not
work for a database to which we're not connected. The advantage of
this approach is that we do not need to rely on the filesystem to
determine what ought to be copied, but instead on PostgreSQL's own
knowledge of the database structure. This avoids, for example,
copying stray files that happen to be located in the source database
directory.

Dilip Kumar, with a fairly large number of cosmetic changes by me.
Reviewed and tested by Ashutosh Sharma, Andres Freund, John Naylor,
Greg Nancarrow, Neha Sharma. Additional feedback from Bruce Momjian,
Heikki Linnakangas, Julien Rouhaud, Adam Brusselback, Kyotaro
Horiguchi, Tomas Vondra, Andrew Dunstan, Álvaro Herrera, and others.

Discussion: http://postgr.es/m/CA+TgmoYtcdxBjLh31DLxUXHxFVMPGzrU5_T=CYCvRyFHywSBUQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9c08aea6a3090a396be334cc58c511edab05776a

Modified Files
--------------
contrib/bloom/blinsert.c                 |   2 +-
doc/src/sgml/monitoring.sgml             |   4 +
doc/src/sgml/ref/create_database.sgml    |  22 +
doc/src/sgml/ref/createdb.sgml           |  11 +
src/backend/access/heap/heapam_handler.c |   6 +-
src/backend/access/nbtree/nbtree.c       |   2 +-
src/backend/access/rmgrdesc/dbasedesc.c  |  20 +-
src/backend/access/transam/xlogutils.c   |   6 +-
src/backend/catalog/heap.c               |   2 +-
src/backend/catalog/storage.c            |  34 +-
src/backend/commands/dbcommands.c        | 769 ++++++++++++++++++++++++++-----
src/backend/commands/tablecmds.c         |   2 +-
src/backend/storage/buffer/bufmgr.c      | 172 ++++++-
src/backend/storage/lmgr/lmgr.c          |  28 ++
src/backend/utils/activity/wait_event.c  |   3 +
src/backend/utils/cache/relcache.c       |   2 +-
src/backend/utils/cache/relmapper.c      |  64 +++
src/bin/pg_rewind/parsexlog.c            |   9 +-
src/bin/psql/tab-complete.c              |   4 +-
src/bin/scripts/createdb.c               |  10 +-
src/bin/scripts/t/020_createdb.pl        |  20 +
src/include/catalog/storage.h            |   4 +-
src/include/commands/dbcommands_xlog.h   |  25 +-
src/include/storage/bufmgr.h             |   6 +-
src/include/storage/lmgr.h               |   1 +
src/include/utils/relmapper.h            |   4 +-
src/include/utils/wait_event.h           |   1 +
src/tools/pgindent/typedefs.list         |   5 +-
28 files changed, 1081 insertions(+), 157 deletions(-)



Message-ID: <E1nZEA7-001vFV-Lj@gemulon.postgresql.org>
Permalink:  ../E1nZEA7-001vFV-Lj@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nZEA7-001vFV-Lj@gemulon.postgresql.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: rhaas@postgresql.org
  Subject: Re: pgsql: Add new block-by-block strategy for CREATE DATABASE.
  In-Reply-To: <E1nZEA7-001vFV-Lj@gemulon.postgresql.org>
  References: <E1nZEA7-001vFV-Lj@gemulon.postgresql.org>

* 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