@@ -83,6 +83,7 @@ typedef enum CreateDBStrategy
8383{
8484 CREATEDB_WAL_LOG ,
8585 CREATEDB_FILE_COPY ,
86+ CREATEDB_COPY_FILE_RANGE ,
8687} CreateDBStrategy ;
8788
8889typedef struct
@@ -136,7 +137,8 @@ static CreateDBRelInfo *ScanSourceDatabasePgClassTuple(HeapTupleData *tuple,
136137static void CreateDirAndVersionFile (char * dbpath , Oid dbid , Oid tsid ,
137138 bool isRedo );
138139static void CreateDatabaseUsingFileCopy (Oid src_dboid , Oid dst_dboid ,
139- Oid src_tsid , Oid dst_tsid );
140+ Oid src_tsid , Oid dst_tsid ,
141+ bool range_copy );
140142static void recovery_create_dbdir (char * path , bool only_tblspc );
141143
142144/*
@@ -548,7 +550,7 @@ CreateDirAndVersionFile(char *dbpath, Oid dbid, Oid tsid, bool isRedo)
548550 */
549551static void
550552CreateDatabaseUsingFileCopy (Oid src_dboid , Oid dst_dboid , Oid src_tsid ,
551- Oid dst_tsid )
553+ Oid dst_tsid , bool range_copy )
552554{
553555 TableScanDesc scan ;
554556 Relation rel ;
@@ -608,7 +610,7 @@ CreateDatabaseUsingFileCopy(Oid src_dboid, Oid dst_dboid, Oid src_tsid,
608610 *
609611 * We don't need to copy subdirectories
610612 */
611- copydir (srcpath , dstpath , false);
613+ copydir (srcpath , dstpath , false, range_copy );
612614
613615 /* Record the filesystem change in XLOG */
614616 {
@@ -1022,6 +1024,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
10221024 dbstrategy = CREATEDB_WAL_LOG ;
10231025 else if (pg_strcasecmp (strategy , "file_copy" ) == 0 )
10241026 dbstrategy = CREATEDB_FILE_COPY ;
1027+ else if (pg_strcasecmp (strategy , "copy_file_range" ) == 0 )
1028+ dbstrategy = CREATEDB_COPY_FILE_RANGE ;
10251029 else
10261030 ereport (ERROR ,
10271031 (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
@@ -1508,9 +1512,12 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
15081512 if (dbstrategy == CREATEDB_WAL_LOG )
15091513 CreateDatabaseUsingWalLog (src_dboid , dboid , src_deftablespace ,
15101514 dst_deftablespace );
1515+ else if (dbstrategy == CREATEDB_COPY_FILE_RANGE )
1516+ CreateDatabaseUsingFileCopy (src_dboid , dboid , src_deftablespace ,
1517+ dst_deftablespace , true);
15111518 else
15121519 CreateDatabaseUsingFileCopy (src_dboid , dboid , src_deftablespace ,
1513- dst_deftablespace );
1520+ dst_deftablespace , false );
15141521
15151522 /*
15161523 * Close pg_database, but keep lock till commit.
@@ -2156,7 +2163,7 @@ movedb(const char *dbname, const char *tblspcname)
21562163 /*
21572164 * Copy files from the old tablespace to the new one
21582165 */
2159- copydir (src_dbpath , dst_dbpath , false);
2166+ copydir (src_dbpath , dst_dbpath , false, false );
21602167
21612168 /*
21622169 * Record the filesystem change in XLOG
@@ -3341,7 +3348,7 @@ dbase_redo(XLogReaderState *record)
33413348 *
33423349 * We don't need to copy subdirectories
33433350 */
3344- copydir (src_path , dst_path , false);
3351+ copydir (src_path , dst_path , false, false );
33453352
33463353 pfree (src_path );
33473354 pfree (dst_path );
0 commit comments