mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
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
This commit is contained in:
@@ -112,12 +112,14 @@ AddPendingSync(const RelFileNode *rnode)
|
||||
* modules that need them.
|
||||
*
|
||||
* This function is transactional. The creation is WAL-logged, and if the
|
||||
* transaction aborts later on, the storage will be destroyed.
|
||||
* transaction aborts later on, the storage will be destroyed. A caller
|
||||
* that does not want the storage to be destroyed in case of an abort may
|
||||
* pass register_delete = false.
|
||||
*/
|
||||
SMgrRelation
|
||||
RelationCreateStorage(RelFileNode rnode, char relpersistence)
|
||||
RelationCreateStorage(RelFileNode rnode, char relpersistence,
|
||||
bool register_delete)
|
||||
{
|
||||
PendingRelDelete *pending;
|
||||
SMgrRelation srel;
|
||||
BackendId backend;
|
||||
bool needs_wal;
|
||||
@@ -149,15 +151,23 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence)
|
||||
if (needs_wal)
|
||||
log_smgrcreate(&srel->smgr_rnode.node, MAIN_FORKNUM);
|
||||
|
||||
/* Add the relation to the list of stuff to delete at abort */
|
||||
pending = (PendingRelDelete *)
|
||||
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
|
||||
pending->relnode = rnode;
|
||||
pending->backend = backend;
|
||||
pending->atCommit = false; /* delete if abort */
|
||||
pending->nestLevel = GetCurrentTransactionNestLevel();
|
||||
pending->next = pendingDeletes;
|
||||
pendingDeletes = pending;
|
||||
/*
|
||||
* Add the relation to the list of stuff to delete at abort, if we are
|
||||
* asked to do so.
|
||||
*/
|
||||
if (register_delete)
|
||||
{
|
||||
PendingRelDelete *pending;
|
||||
|
||||
pending = (PendingRelDelete *)
|
||||
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
|
||||
pending->relnode = rnode;
|
||||
pending->backend = backend;
|
||||
pending->atCommit = false; /* delete if abort */
|
||||
pending->nestLevel = GetCurrentTransactionNestLevel();
|
||||
pending->next = pendingDeletes;
|
||||
pendingDeletes = pending;
|
||||
}
|
||||
|
||||
if (relpersistence == RELPERSISTENCE_PERMANENT && !XLogIsNeeded())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user