@@ -32,9 +32,6 @@ parray *backup_files_list = NULL;
3232/* We need critical section for datapagemap_add() in case of using threads */
3333static pthread_mutex_t backup_pagemap_mutex = PTHREAD_MUTEX_INITIALIZER ;
3434
35- // TODO: move to PGnodeInfo
36- bool exclusive_backup = false;
37-
3835/* Is pg_start_backup() was executed */
3936bool backup_in_progress = false;
4037
@@ -80,7 +77,7 @@ backup_stopbackup_callback(bool fatal, void *userdata)
8077 {
8178 elog (WARNING , "backup in progress, stop backup" );
8279 /* don't care about stop_lsn in case of error */
83- pg_stop_backup_send (st -> conn , st -> server_version , current .from_replica , exclusive_backup , NULL );
80+ pg_stop_backup_send (st -> conn , st -> server_version , current .from_replica , NULL );
8481 }
8582}
8683
@@ -493,10 +490,10 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
493490 /* Notify end of backup */
494491 pg_stop_backup (instanceState , & current , backup_conn , nodeInfo );
495492
496- /* In case of backup from replica >= 9.6 we must fix minRecPoint,
493+ /* In case of backup from replica we must fix minRecPoint,
497494 * First we must find pg_control in backup_files_list.
498495 */
499- if (current .from_replica && ! exclusive_backup )
496+ if (current .from_replica )
500497 {
501498 pgFile * pg_control = NULL ;
502499
@@ -781,11 +778,6 @@ do_backup(InstanceState *instanceState, pgSetBackupParams *set_backup_params,
781778 }
782779 }
783780
784- if (current .from_replica && exclusive_backup )
785- /* Check master connection options */
786- if (instance_config .master_conn_opt .pghost == NULL )
787- elog (ERROR , "Options for connection to master must be provided to perform backup from replica" );
788-
789781 /* add note to backup if requested */
790782 if (set_backup_params && set_backup_params -> note )
791783 add_note (& current , set_backup_params -> note );
@@ -866,22 +858,12 @@ check_server_version(PGconn *conn, PGNodeInfo *nodeInfo)
866858 elog (ERROR , "Unknown server version %d" , nodeInfo -> server_version );
867859
868860 if (nodeInfo -> server_version < 100000 )
869- sprintf (nodeInfo -> server_version_str , "%d.%d" ,
870- nodeInfo -> server_version / 10000 ,
871- (nodeInfo -> server_version / 100 ) % 100 );
872- else
873- sprintf (nodeInfo -> server_version_str , "%d" ,
874- nodeInfo -> server_version / 10000 );
875-
876- if (nodeInfo -> server_version < 90500 )
877861 elog (ERROR ,
878862 "server version is %s, must be %s or higher" ,
879- nodeInfo -> server_version_str , "9.5 " );
863+ nodeInfo -> server_version_str , "10 " );
880864
881- if (current .from_replica && nodeInfo -> server_version < 90600 )
882- elog (ERROR ,
883- "server version is %s, must be %s or higher for backup from replica" ,
884- nodeInfo -> server_version_str , "9.6" );
865+ sprintf (nodeInfo -> server_version_str , "%d" ,
866+ nodeInfo -> server_version / 10000 );
885867
886868 if (nodeInfo -> pgpro_support )
887869 res = pgut_execute (conn , "SELECT pg_catalog.pgpro_edition()" , 0 , NULL );
@@ -922,9 +904,6 @@ check_server_version(PGconn *conn, PGNodeInfo *nodeInfo)
922904
923905 if (res )
924906 PQclear (res );
925-
926- /* Do exclusive backup only for PostgreSQL 9.5 */
927- exclusive_backup = nodeInfo -> server_version < 90600 ;
928907}
929908
930909/*
@@ -1006,16 +985,10 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
1006985
1007986 /* 2nd argument is 'fast'*/
1008987 params [1 ] = smooth ? "false" : "true" ;
1009- if (!exclusive_backup )
1010- res = pgut_execute (conn ,
1011- "SELECT pg_catalog.pg_start_backup($1, $2, false)" ,
1012- 2 ,
1013- params );
1014- else
1015- res = pgut_execute (conn ,
1016- "SELECT pg_catalog.pg_start_backup($1, $2)" ,
1017- 2 ,
1018- params );
988+ res = pgut_execute (conn ,
989+ "SELECT pg_catalog.pg_start_backup($1, $2, false)" ,
990+ 2 ,
991+ params );
1019992
1020993 /*
1021994 * Set flag that pg_start_backup() was called. If an error will happen it
@@ -1034,14 +1007,10 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
10341007 PQclear (res );
10351008
10361009 if ((!backup -> stream || backup -> backup_mode == BACKUP_MODE_DIFF_PAGE ) &&
1037- !backup -> from_replica &&
1038- !(nodeInfo -> server_version < 90600 &&
1039- !nodeInfo -> is_superuser ))
1010+ !backup -> from_replica )
10401011 /*
10411012 * Switch to a new WAL segment. It is necessary to get archived WAL
10421013 * segment, which includes start LSN of current backup.
1043- * Don`t do this for replica backups and for PG 9.5 if pguser is not superuser
1044- * (because in 9.5 only superuser can switch WAL)
10451014 */
10461015 pg_switch_wal (conn );
10471016}
@@ -1546,20 +1515,9 @@ pg_create_restore_point(PGconn *conn, time_t backup_start_time)
15461515}
15471516
15481517void
1549- pg_stop_backup_send (PGconn * conn , int server_version , bool is_started_on_replica , bool is_exclusive , char * * query_text )
1518+ pg_stop_backup_send (PGconn * conn , int server_version , bool is_started_on_replica , char * * query_text )
15501519{
15511520 static const char
1552- stop_exlusive_backup_query [] =
1553- /*
1554- * Stop the non-exclusive backup. Besides stop_lsn it returns from
1555- * pg_stop_backup(false) copy of the backup label and tablespace map
1556- * so they can be written to disk by the caller.
1557- * TODO, question: add NULLs as backup_label and tablespace_map?
1558- */
1559- "SELECT"
1560- " pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
1561- " current_timestamp(0)::timestamptz,"
1562- " pg_catalog.pg_stop_backup() as lsn" ,
15631521 stop_backup_on_master_query [] =
15641522 "SELECT"
15651523 " pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
@@ -1568,16 +1526,8 @@ pg_stop_backup_send(PGconn *conn, int server_version, bool is_started_on_replica
15681526 " labelfile,"
15691527 " spcmapfile"
15701528 " FROM pg_catalog.pg_stop_backup(false, false)" ,
1571- stop_backup_on_master_before10_query [] =
1572- "SELECT"
1573- " pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
1574- " current_timestamp(0)::timestamptz,"
1575- " lsn,"
1576- " labelfile,"
1577- " spcmapfile"
1578- " FROM pg_catalog.pg_stop_backup(false)" ,
15791529 /*
1580- * In case of backup from replica >= 9.6 we do not trust minRecPoint
1530+ * In case of backup from replica we do not trust minRecPoint
15811531 * and stop_backup LSN, so we use latest replayed LSN as STOP LSN.
15821532 */
15831533 stop_backup_on_replica_query [] =
@@ -1587,28 +1537,12 @@ pg_stop_backup_send(PGconn *conn, int server_version, bool is_started_on_replica
15871537 " pg_catalog.pg_last_wal_replay_lsn(),"
15881538 " labelfile,"
15891539 " spcmapfile"
1590- " FROM pg_catalog.pg_stop_backup(false, false)" ,
1591- stop_backup_on_replica_before10_query [] =
1592- "SELECT"
1593- " pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
1594- " current_timestamp(0)::timestamptz,"
1595- " pg_catalog.pg_last_xlog_replay_location(),"
1596- " labelfile,"
1597- " spcmapfile"
1598- " FROM pg_catalog.pg_stop_backup(false)" ;
1540+ " FROM pg_catalog.pg_stop_backup(false, false)" ;
15991541
16001542 const char * const stop_backup_query =
1601- is_exclusive ?
1602- stop_exlusive_backup_query :
1603- server_version >= 100000 ?
1604- (is_started_on_replica ?
1543+ is_started_on_replica ?
16051544 stop_backup_on_replica_query :
1606- stop_backup_on_master_query
1607- ) :
1608- (is_started_on_replica ?
1609- stop_backup_on_replica_before10_query :
1610- stop_backup_on_master_before10_query
1611- );
1545+ stop_backup_on_master_query ;
16121546 bool sent = false;
16131547
16141548 /* Make proper timestamp format for parse_time(recovery_time) */
@@ -1641,7 +1575,7 @@ pg_stop_backup_send(PGconn *conn, int server_version, bool is_started_on_replica
16411575 */
16421576void
16431577pg_stop_backup_consume (PGconn * conn , int server_version ,
1644- bool is_exclusive , uint32 timeout , const char * query_text ,
1578+ uint32 timeout , const char * query_text ,
16451579 PGStopBackupResult * result )
16461580{
16471581 PGresult * query_result ;
@@ -1743,28 +1677,18 @@ pg_stop_backup_consume(PGconn *conn, int server_version,
17431677 /* get backup_label_content */
17441678 result -> backup_label_content = NULL ;
17451679 // if (!PQgetisnull(query_result, 0, backup_label_colno))
1746- if (!is_exclusive )
1747- {
1748- result -> backup_label_content_len = PQgetlength (query_result , 0 , backup_label_colno );
1749- if (result -> backup_label_content_len > 0 )
1750- result -> backup_label_content = pgut_strndup (PQgetvalue (query_result , 0 , backup_label_colno ),
1751- result -> backup_label_content_len );
1752- } else {
1753- result -> backup_label_content_len = 0 ;
1754- }
1680+ result -> backup_label_content_len = PQgetlength (query_result , 0 , backup_label_colno );
1681+ if (result -> backup_label_content_len > 0 )
1682+ result -> backup_label_content = pgut_strndup (PQgetvalue (query_result , 0 , backup_label_colno ),
1683+ result -> backup_label_content_len );
17551684
17561685 /* get tablespace_map_content */
17571686 result -> tablespace_map_content = NULL ;
17581687 // if (!PQgetisnull(query_result, 0, tablespace_map_colno))
1759- if (!is_exclusive )
1760- {
1761- result -> tablespace_map_content_len = PQgetlength (query_result , 0 , tablespace_map_colno );
1762- if (result -> tablespace_map_content_len > 0 )
1763- result -> tablespace_map_content = pgut_strndup (PQgetvalue (query_result , 0 , tablespace_map_colno ),
1764- result -> tablespace_map_content_len );
1765- } else {
1766- result -> tablespace_map_content_len = 0 ;
1767- }
1688+ result -> tablespace_map_content_len = PQgetlength (query_result , 0 , tablespace_map_colno );
1689+ if (result -> tablespace_map_content_len > 0 )
1690+ result -> tablespace_map_content = pgut_strndup (PQgetvalue (query_result , 0 , tablespace_map_colno ),
1691+ result -> tablespace_map_content_len );
17681692}
17691693
17701694/*
@@ -1832,21 +1756,18 @@ pg_stop_backup(InstanceState *instanceState, pgBackup *backup, PGconn *pg_startb
18321756
18331757 /* Create restore point
18341758 * Only if backup is from master.
1835- * For PG 9.5 create restore point only if pguser is superuser.
18361759 */
1837- if (!backup -> from_replica &&
1838- !(nodeInfo -> server_version < 90600 &&
1839- !nodeInfo -> is_superuser )) //TODO: check correctness
1760+ if (!backup -> from_replica )
18401761 pg_create_restore_point (pg_startbackup_conn , backup -> start_time );
18411762
18421763 /* Execute pg_stop_backup using PostgreSQL connection */
1843- pg_stop_backup_send (pg_startbackup_conn , nodeInfo -> server_version , backup -> from_replica , exclusive_backup , & query_text );
1764+ pg_stop_backup_send (pg_startbackup_conn , nodeInfo -> server_version , backup -> from_replica , & query_text );
18441765
18451766 /*
18461767 * Wait for the result of pg_stop_backup(), but no longer than
18471768 * archive_timeout seconds
18481769 */
1849- pg_stop_backup_consume (pg_startbackup_conn , nodeInfo -> server_version , exclusive_backup , timeout , query_text , & stop_backup_result );
1770+ pg_stop_backup_consume (pg_startbackup_conn , nodeInfo -> server_version , timeout , query_text , & stop_backup_result );
18501771
18511772 if (backup -> stream )
18521773 {
@@ -1859,28 +1780,25 @@ pg_stop_backup(InstanceState *instanceState, pgBackup *backup, PGconn *pg_startb
18591780 wait_wal_and_calculate_stop_lsn (xlog_path , stop_backup_result .lsn , backup );
18601781
18611782 /* Write backup_label and tablespace_map */
1862- if (!exclusive_backup )
1783+ Assert (stop_backup_result .backup_label_content != NULL );
1784+
1785+ /* Write backup_label */
1786+ pg_stop_backup_write_file_helper (backup -> database_dir , PG_BACKUP_LABEL_FILE , "backup label" ,
1787+ stop_backup_result .backup_label_content , stop_backup_result .backup_label_content_len ,
1788+ backup_files_list );
1789+ free (stop_backup_result .backup_label_content );
1790+ stop_backup_result .backup_label_content = NULL ;
1791+ stop_backup_result .backup_label_content_len = 0 ;
1792+
1793+ /* Write tablespace_map */
1794+ if (stop_backup_result .tablespace_map_content != NULL )
18631795 {
1864- Assert (stop_backup_result .backup_label_content != NULL );
1865-
1866- /* Write backup_label */
1867- pg_stop_backup_write_file_helper (backup -> database_dir , PG_BACKUP_LABEL_FILE , "backup label" ,
1868- stop_backup_result .backup_label_content , stop_backup_result .backup_label_content_len ,
1796+ pg_stop_backup_write_file_helper (backup -> database_dir , PG_TABLESPACE_MAP_FILE , "tablespace map" ,
1797+ stop_backup_result .tablespace_map_content , stop_backup_result .tablespace_map_content_len ,
18691798 backup_files_list );
1870- free (stop_backup_result .backup_label_content );
1871- stop_backup_result .backup_label_content = NULL ;
1872- stop_backup_result .backup_label_content_len = 0 ;
1873-
1874- /* Write tablespace_map */
1875- if (stop_backup_result .tablespace_map_content != NULL )
1876- {
1877- pg_stop_backup_write_file_helper (backup -> database_dir , PG_TABLESPACE_MAP_FILE , "tablespace map" ,
1878- stop_backup_result .tablespace_map_content , stop_backup_result .tablespace_map_content_len ,
1879- backup_files_list );
1880- free (stop_backup_result .tablespace_map_content );
1881- stop_backup_result .tablespace_map_content = NULL ;
1882- stop_backup_result .tablespace_map_content_len = 0 ;
1883- }
1799+ free (stop_backup_result .tablespace_map_content );
1800+ stop_backup_result .tablespace_map_content = NULL ;
1801+ stop_backup_result .tablespace_map_content_len = 0 ;
18841802 }
18851803
18861804 if (backup -> stream )
0 commit comments