Re: [Proposal] Fully WAL logged CREATE DATABASE - No Checkpoints
Dilip Kumar <dilipbalaut@gmail.com>
Attachments
- v3-0002-Extend-relmap-interfaces.patch (application/octet-stream) patch v3-0002
- v3-0003-Refactor-index_copy_data.patch (application/octet-stream) patch v3-0003
- v3-0004-Extend-bufmgr-interfaces.patch (application/octet-stream) patch v3-0004
- v3-0001-Refactor-relmap-load-and-relmap-write-functions.patch (application/octet-stream) patch v3-0001
- v3-0005-New-interface-to-lock-relation-id.patch (application/octet-stream) patch v3-0005
- v3-0006-WAL-logged-CREATE-DATABASE.patch (application/octet-stream) patch v3-0006
On Thu, Sep 2, 2021 at 8:52 PM Robert Haas <robertmhaas@gmail.com> wrote: PFA, updated version of the patch, where I have fixed the issues reported by you and also done some more refactoring and patch split, next I am planning to post the patch with another approach where we scan the directory instead of scanning the pg_class for identifying the relfilenodes. For specific comments please find my response inline, > Andres pointed out that this approach ends up accessing relations > without taking a lock on them. It doesn't look like you did anything > about that. Now I have acquired a lock before scanning the pg_class as well as other relfilenode. > > + /* Built-in oids are mapped directly */ > + if (classForm->oid < FirstGenbkiObjectId) > + relfilenode = classForm->oid; > + else if (OidIsValid(classForm->relfilenode)) > + relfilenode = classForm->relfilenode; > + else > + continue; > > Am I missing something, or is this totally busted? Handled the mapped relation using relmapper. > /* > + * Now drop all buffers holding data of the target database; they should > + * no longer be dirty so DropDatabaseBuffers is safe. > > The way things worked before, this was true, but now AFAICS it's > false. I'm not sure whether that means that DropDatabaseBuffers() here > is actually unsafe or whether it just means that you haven't updated > the comment to explain the reason. Now we can only drop the buffer specific to old tablespace not the new tablespace so can not directly use the dboid, so extended the DropDatabaseBuffers interface to take tablespace oid as and input and updated the comments accordingly. > + * Since we copy the file directly without looking at the shared buffers, > + * we'd better first flush out any pages of the source relation that are > + * in shared buffers. We assume no new changes will be made while we are > + * holding exclusive lock on the rel. > > Ditto. I think these comments is related to index_copy_data() and this is still valid, it is showing in the patch due to some refactoring so I have separated out this refactoring patch as 0003 to avoid confusion. > > + /* As always, WAL must hit the disk before the data update does. */ > > Actually, the way it's coded now, part of the on-disk changes are done > before WAL is issued, and part are done after. I doubt that's the > right idea. There's nothing special about writing the actual payload > bytes vs. the other on-disk changes (creating directories and files). > In any case the ordering deserves a better-considered comment than > this one. Changed, now WAL first and then disk change. Open question: - Scan pg_class vs scan directories - Whether to retain the old created database mechanism as option or not. -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com
Commits
-
When using the WAL-logged CREATE DATABASE strategy, bulk extend.
- 3e63e8462f31 16.0 landed
- 576bb0fc9342 15.0 landed
-
Avoid using a fake relcache entry to own an SmgrRelation.
- 1b94f8f232f6 15.0 landed
- 76733b399c49 16.0 landed
-
Fix data-corruption hazard in WAL-logged CREATE DATABASE.
- 692df425b688 16.0 landed
- 811203d4aff5 15.0 landed
-
initdb: When running CREATE DATABASE, use STRATEGY = WAL_COPY.
- ad43a413c4f7 15.0 landed
-
Simplify a needlessly-complicated regular expression.
- c6863b858291 15.0 landed
-
In 020_createdb.pl, change order of command-line arguments.
- 3d067c53b26d 15.0 landed
-
Add new block-by-block strategy for CREATE DATABASE.
- 9c08aea6a309 15.0 landed
-
Fix replay of create database records on standby
- 49d9cfc68bf4 15.0 cited
-
Refactor code for reading and writing relation map files.
- 39f0c4bd670c 15.0 landed
-
Replace RelationOpenSmgr() with RelationGetSmgr().
- f10f0ae420ee 15.0 cited
-
Refactor the fsync queue for wider use.
- 3eb77eba5a51 12.0 cited