@@ -54,6 +54,7 @@ static pthread_t stream_thread;
5454static int is_ptrack_enable = false;
5555bool is_ptrack_support = false;
5656bool is_checksum_enabled = false;
57+ bool exclusive_backup = false;
5758
5859/* Backup connections */
5960static PGconn * backup_conn = NULL ;
@@ -64,7 +65,6 @@ static PGconn *backup_conn_replication = NULL;
6465static int server_version = 0 ;
6566static char server_version_str [100 ] = "" ;
6667
67- static bool exclusive_backup = false;
6868/* Is pg_start_backup() was executed */
6969static bool backup_in_progress = false;
7070/* Is pg_stop_backup() was sent */
@@ -1600,25 +1600,19 @@ pg_stop_backup(pgBackup *backup)
16001600 */
16011601 sent = pgut_send (conn ,
16021602 "SELECT"
1603- " labelfile,"
16041603 " txid_snapshot_xmax(txid_current_snapshot()),"
16051604 " current_timestamp(0)::timestamptz,"
16061605 " lsn,"
1606+ " labelfile,"
16071607 " spcmapfile"
16081608 " FROM pg_stop_backup(false)" ,
16091609 0 , NULL , WARNING );
16101610 }
16111611 else
16121612 {
16131613
1614- tablespace_map_content = pgut_execute (conn ,
1615- "SELECT pg_read_file('tablespace_map', 0, size, true)"
1616- " FROM pg_stat_file('tablespace_map', true)" ,
1617- 0 , NULL , true);
1618-
16191614 sent = pgut_send (conn ,
16201615 "SELECT"
1621- " pg_read_file('backup_label') as labelfile,"
16221616 " txid_snapshot_xmax(txid_current_snapshot()),"
16231617 " current_timestamp(0)::timestamptz,"
16241618 " pg_stop_backup() as lsn" ,
@@ -1676,7 +1670,7 @@ pg_stop_backup(pgBackup *backup)
16761670 backup_in_progress = false;
16771671
16781672 /* Extract timeline and LSN from results of pg_stop_backup() */
1679- XLogDataFromLSN (PQgetvalue (res , 0 , 3 ), & xlogid , & xrecoff );
1673+ XLogDataFromLSN (PQgetvalue (res , 0 , 2 ), & xlogid , & xrecoff );
16801674 /* Calculate LSN */
16811675 stop_backup_lsn = (XLogRecPtr ) ((uint64 ) xlogid << 32 ) | xrecoff ;
16821676
@@ -1690,61 +1684,57 @@ pg_stop_backup(pgBackup *backup)
16901684 (uint32 ) (stop_backup_lsn >> 32 ), (uint32 ) (stop_backup_lsn ));
16911685
16921686 /* Write backup_label and tablespace_map */
1693- Assert (PQnfields (res ) >= 4 );
1694- pgBackupGetPath (& current , path , lengthof (path ), DATABASE_DIR );
1695-
1696- /* Write backup_label */
1697- join_path_components (backup_label , path , PG_BACKUP_LABEL_FILE );
1698- fp = fopen (backup_label , "w" );
1699- if (fp == NULL )
1700- elog (ERROR , "can't open backup label file \"%s\": %s" ,
1701- backup_label , strerror (errno ));
1702-
1703- len = strlen (PQgetvalue (res , 0 , 0 ));
1704- if (fwrite (PQgetvalue (res , 0 , 0 ), 1 , len , fp ) != len ||
1705- fflush (fp ) != 0 ||
1706- fsync (fileno (fp )) != 0 ||
1707- fclose (fp ))
1708- elog (ERROR , "can't write backup label file \"%s\": %s" ,
1709- backup_label , strerror (errno ));
1710-
1711- /*
1712- * It's vital to check if backup_files_list is initialized,
1713- * because we could get here because the backup was interrupted
1714- */
1715- if (backup_files_list )
1687+ if (!exclusive_backup )
17161688 {
1717- file = pgFileNew (backup_label , true);
1718- calc_file_checksum (file );
1719- free (file -> path );
1720- file -> path = strdup (PG_BACKUP_LABEL_FILE );
1721- parray_append (backup_files_list , file );
1689+ Assert (PQnfields (res ) >= 4 );
1690+ pgBackupGetPath (& current , path , lengthof (path ), DATABASE_DIR );
1691+
1692+ /* Write backup_label */
1693+ join_path_components (backup_label , path , PG_BACKUP_LABEL_FILE );
1694+ fp = fopen (backup_label , "w" );
1695+ if (fp == NULL )
1696+ elog (ERROR , "can't open backup label file \"%s\": %s" ,
1697+ backup_label , strerror (errno ));
1698+
1699+ len = strlen (PQgetvalue (res , 0 , 3 ));
1700+ if (fwrite (PQgetvalue (res , 0 , 3 ), 1 , len , fp ) != len ||
1701+ fflush (fp ) != 0 ||
1702+ fsync (fileno (fp )) != 0 ||
1703+ fclose (fp ))
1704+ elog (ERROR , "can't write backup label file \"%s\": %s" ,
1705+ backup_label , strerror (errno ));
1706+
1707+ /*
1708+ * It's vital to check if backup_files_list is initialized,
1709+ * because we could get here because the backup was interrupted
1710+ */
1711+ if (backup_files_list )
1712+ {
1713+ file = pgFileNew (backup_label , true);
1714+ calc_file_checksum (file );
1715+ free (file -> path );
1716+ file -> path = strdup (PG_BACKUP_LABEL_FILE );
1717+ parray_append (backup_files_list , file );
1718+ }
17221719 }
17231720
1724- if (sscanf (PQgetvalue (res , 0 , 1 ), XID_FMT , & recovery_xid ) != 1 )
1721+ if (sscanf (PQgetvalue (res , 0 , 0 ), XID_FMT , & recovery_xid ) != 1 )
17251722 elog (ERROR ,
17261723 "result of txid_snapshot_xmax() is invalid: %s" ,
17271724 PQerrorMessage (conn ));
1728- if (!parse_time (PQgetvalue (res , 0 , 2 ), & recovery_time ))
1725+ if (!parse_time (PQgetvalue (res , 0 , 1 ), & recovery_time ))
17291726 elog (ERROR ,
17301727 "result of current_timestamp is invalid: %s" ,
17311728 PQerrorMessage (conn ));
17321729
1733- /* Get content for tablespace_map from pg_read_file('tablespace_map') in case of exclusive
1734- * or from stop_backup results in case of non-exclusive backup
1730+ /* Get content for tablespace_map from stop_backup results
1731+ * in case of non-exclusive backup
17351732 */
1736- if (exclusive_backup )
1737- {
1738- Assert (tablespace_map_content );
1739-
1740- if (PQresultStatus (tablespace_map_content ) == PGRES_TUPLES_OK )
1741- val = PQgetvalue (tablespace_map_content , 0 , 0 );
1742- }
1743- else
1733+ if (!exclusive_backup )
17441734 val = PQgetvalue (res , 0 , 4 );
17451735
17461736 /* Write tablespace_map */
1747- if (val && strlen (val ) > 0 )
1737+ if (! exclusive_backup && val && strlen (val ) > 0 )
17481738 {
17491739 char tablespace_map [MAXPGPATH ];
17501740
0 commit comments