@@ -32,9 +32,6 @@ parray *backup_files_list = NULL;
32
32
/* We need critical section for datapagemap_add() in case of using threads */
33
33
static pthread_mutex_t backup_pagemap_mutex = PTHREAD_MUTEX_INITIALIZER ;
34
34
35
- // TODO: move to PGnodeInfo
36
- bool exclusive_backup = false;
37
-
38
35
/* Is pg_start_backup() was executed */
39
36
bool backup_in_progress = false;
40
37
@@ -80,7 +77,7 @@ backup_stopbackup_callback(bool fatal, void *userdata)
80
77
{
81
78
elog (WARNING , "backup in progress, stop backup" );
82
79
/* 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 );
84
81
}
85
82
}
86
83
@@ -493,10 +490,10 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
493
490
/* Notify end of backup */
494
491
pg_stop_backup (instanceState , & current , backup_conn , nodeInfo );
495
492
496
- /* In case of backup from replica >= 9.6 we must fix minRecPoint,
493
+ /* In case of backup from replica we must fix minRecPoint,
497
494
* First we must find pg_control in backup_files_list.
498
495
*/
499
- if (current .from_replica && ! exclusive_backup )
496
+ if (current .from_replica )
500
497
{
501
498
pgFile * pg_control = NULL ;
502
499
@@ -781,11 +778,6 @@ do_backup(InstanceState *instanceState, pgSetBackupParams *set_backup_params,
781
778
}
782
779
}
783
780
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
-
789
781
/* add note to backup if requested */
790
782
if (set_backup_params && set_backup_params -> note )
791
783
add_note (& current , set_backup_params -> note );
@@ -866,22 +858,12 @@ check_server_version(PGconn *conn, PGNodeInfo *nodeInfo)
866
858
elog (ERROR , "Unknown server version %d" , nodeInfo -> server_version );
867
859
868
860
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 )
877
861
elog (ERROR ,
878
862
"server version is %s, must be %s or higher" ,
879
- nodeInfo -> server_version_str , "9.5 " );
863
+ nodeInfo -> server_version_str , "10 " );
880
864
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 );
885
867
886
868
if (nodeInfo -> pgpro_support )
887
869
res = pgut_execute (conn , "SELECT pg_catalog.pgpro_edition()" , 0 , NULL );
@@ -922,9 +904,6 @@ check_server_version(PGconn *conn, PGNodeInfo *nodeInfo)
922
904
923
905
if (res )
924
906
PQclear (res );
925
-
926
- /* Do exclusive backup only for PostgreSQL 9.5 */
927
- exclusive_backup = nodeInfo -> server_version < 90600 ;
928
907
}
929
908
930
909
/*
@@ -1006,16 +985,10 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
1006
985
1007
986
/* 2nd argument is 'fast'*/
1008
987
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 );
1019
992
1020
993
/*
1021
994
* 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,
1034
1007
PQclear (res );
1035
1008
1036
1009
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 )
1040
1011
/*
1041
1012
* Switch to a new WAL segment. It is necessary to get archived WAL
1042
1013
* 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)
1045
1014
*/
1046
1015
pg_switch_wal (conn );
1047
1016
}
@@ -1546,20 +1515,9 @@ pg_create_restore_point(PGconn *conn, time_t backup_start_time)
1546
1515
}
1547
1516
1548
1517
void
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 )
1550
1519
{
1551
1520
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" ,
1563
1521
stop_backup_on_master_query [] =
1564
1522
"SELECT"
1565
1523
" 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
1568
1526
" labelfile,"
1569
1527
" spcmapfile"
1570
1528
" 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)" ,
1579
1529
/*
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
1581
1531
* and stop_backup LSN, so we use latest replayed LSN as STOP LSN.
1582
1532
*/
1583
1533
stop_backup_on_replica_query [] =
@@ -1587,28 +1537,12 @@ pg_stop_backup_send(PGconn *conn, int server_version, bool is_started_on_replica
1587
1537
" pg_catalog.pg_last_wal_replay_lsn(),"
1588
1538
" labelfile,"
1589
1539
" 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)" ;
1599
1541
1600
1542
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 ?
1605
1544
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 ;
1612
1546
bool sent = false;
1613
1547
1614
1548
/* 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
1641
1575
*/
1642
1576
void
1643
1577
pg_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 ,
1645
1579
PGStopBackupResult * result )
1646
1580
{
1647
1581
PGresult * query_result ;
@@ -1743,28 +1677,18 @@ pg_stop_backup_consume(PGconn *conn, int server_version,
1743
1677
/* get backup_label_content */
1744
1678
result -> backup_label_content = NULL ;
1745
1679
// 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 );
1755
1684
1756
1685
/* get tablespace_map_content */
1757
1686
result -> tablespace_map_content = NULL ;
1758
1687
// 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 );
1768
1692
}
1769
1693
1770
1694
/*
@@ -1832,21 +1756,18 @@ pg_stop_backup(InstanceState *instanceState, pgBackup *backup, PGconn *pg_startb
1832
1756
1833
1757
/* Create restore point
1834
1758
* Only if backup is from master.
1835
- * For PG 9.5 create restore point only if pguser is superuser.
1836
1759
*/
1837
- if (!backup -> from_replica &&
1838
- !(nodeInfo -> server_version < 90600 &&
1839
- !nodeInfo -> is_superuser )) //TODO: check correctness
1760
+ if (!backup -> from_replica )
1840
1761
pg_create_restore_point (pg_startbackup_conn , backup -> start_time );
1841
1762
1842
1763
/* 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 );
1844
1765
1845
1766
/*
1846
1767
* Wait for the result of pg_stop_backup(), but no longer than
1847
1768
* archive_timeout seconds
1848
1769
*/
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 );
1850
1771
1851
1772
if (backup -> stream )
1852
1773
{
@@ -1859,28 +1780,25 @@ pg_stop_backup(InstanceState *instanceState, pgBackup *backup, PGconn *pg_startb
1859
1780
wait_wal_and_calculate_stop_lsn (xlog_path , stop_backup_result .lsn , backup );
1860
1781
1861
1782
/* 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 )
1863
1795
{
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 ,
1869
1798
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 ;
1884
1802
}
1885
1803
1886
1804
if (backup -> stream )
0 commit comments