@@ -1071,8 +1071,8 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
1071
1071
{
1072
1072
PGresult * res ;
1073
1073
const char * params [2 ];
1074
- uint32 xlogid ;
1075
- uint32 xrecoff ;
1074
+ uint32 lsn_hi ;
1075
+ uint32 lsn_lo ;
1076
1076
PGconn * conn ;
1077
1077
1078
1078
params [0 ] = label ;
@@ -1100,9 +1100,9 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
1100
1100
backup_in_progress = true;
1101
1101
1102
1102
/* Extract timeline and LSN from results of pg_start_backup() */
1103
- XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & xlogid , & xrecoff );
1103
+ XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & lsn_hi , & lsn_lo );
1104
1104
/* Calculate LSN */
1105
- backup -> start_lsn = (XLogRecPtr ) (( uint64 ) xlogid << 32 ) | xrecoff ;
1105
+ backup -> start_lsn = (( uint64 ) lsn_hi ) << 32 | lsn_lo ;
1106
1106
1107
1107
PQclear (res );
1108
1108
@@ -1585,8 +1585,8 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
1585
1585
while (true)
1586
1586
{
1587
1587
PGresult * res ;
1588
- uint32 xlogid ;
1589
- uint32 xrecoff ;
1588
+ uint32 lsn_hi ;
1589
+ uint32 lsn_lo ;
1590
1590
XLogRecPtr replica_lsn ;
1591
1591
1592
1592
/*
@@ -1617,9 +1617,9 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
1617
1617
}
1618
1618
1619
1619
/* Extract timeline and LSN from result */
1620
- XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & xlogid , & xrecoff );
1620
+ XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & lsn_hi , & lsn_lo );
1621
1621
/* Calculate LSN */
1622
- replica_lsn = (XLogRecPtr ) (( uint64 ) xlogid << 32 ) | xrecoff ;
1622
+ replica_lsn = (( uint64 ) lsn_hi ) << 32 | lsn_lo ;
1623
1623
PQclear (res );
1624
1624
1625
1625
/* target lsn was replicated */
@@ -1653,10 +1653,10 @@ pg_stop_backup(pgBackup *backup)
1653
1653
PGconn * conn ;
1654
1654
PGresult * res ;
1655
1655
PGresult * tablespace_map_content = NULL ;
1656
- uint32 xlogid ;
1657
- uint32 xrecoff ;
1656
+ uint32 lsn_hi ;
1657
+ uint32 lsn_lo ;
1658
1658
XLogRecPtr restore_lsn = InvalidXLogRecPtr ;
1659
- int pg_stop_backup_timeout = 0 ;
1659
+ int pg_stop_backup_timeout = 0 ;
1660
1660
char path [MAXPGPATH ];
1661
1661
char backup_label [MAXPGPATH ];
1662
1662
FILE * fp ;
@@ -1699,6 +1699,10 @@ pg_stop_backup(pgBackup *backup)
1699
1699
1700
1700
res = pgut_execute (conn , "SELECT pg_catalog.pg_create_restore_point($1)" ,
1701
1701
1 , params );
1702
+ /* Extract timeline and LSN from the result */
1703
+ XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & lsn_hi , & lsn_lo );
1704
+ /* Calculate LSN */
1705
+ restore_lsn = ((uint64 ) lsn_hi ) << 32 | lsn_lo ;
1702
1706
PQclear (res );
1703
1707
}
1704
1708
@@ -1731,7 +1735,6 @@ pg_stop_backup(pgBackup *backup)
1731
1735
}
1732
1736
else
1733
1737
{
1734
-
1735
1738
stop_backup_query = "SELECT"
1736
1739
" pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
1737
1740
" current_timestamp(0)::timestamptz,"
@@ -1750,6 +1753,8 @@ pg_stop_backup(pgBackup *backup)
1750
1753
*/
1751
1754
if (pg_stop_backup_is_sent && !in_cleanup )
1752
1755
{
1756
+ res = NULL ;
1757
+
1753
1758
while (1 )
1754
1759
{
1755
1760
if (!PQconsumeInput (conn ) || PQisBusy (conn ))
@@ -1791,8 +1796,11 @@ pg_stop_backup(pgBackup *backup)
1791
1796
{
1792
1797
switch (PQresultStatus (res ))
1793
1798
{
1799
+ /*
1800
+ * We should expect only PGRES_TUPLES_OK since pg_stop_backup
1801
+ * returns tuples.
1802
+ */
1794
1803
case PGRES_TUPLES_OK :
1795
- case PGRES_COMMAND_OK :
1796
1804
break ;
1797
1805
default :
1798
1806
elog (ERROR , "query failed: %s query was: %s" ,
@@ -1804,9 +1812,9 @@ pg_stop_backup(pgBackup *backup)
1804
1812
backup_in_progress = false;
1805
1813
1806
1814
/* Extract timeline and LSN from results of pg_stop_backup() */
1807
- XLogDataFromLSN (PQgetvalue (res , 0 , 2 ), & xlogid , & xrecoff );
1815
+ XLogDataFromLSN (PQgetvalue (res , 0 , 2 ), & lsn_hi , & lsn_lo );
1808
1816
/* Calculate LSN */
1809
- stop_backup_lsn = (XLogRecPtr ) (( uint64 ) xlogid << 32 ) | xrecoff ;
1817
+ stop_backup_lsn = (( uint64 ) lsn_hi ) << 32 | lsn_lo ;
1810
1818
1811
1819
if (!XRecOffIsValid (stop_backup_lsn ))
1812
1820
{
@@ -2617,16 +2625,16 @@ get_last_ptrack_lsn(void)
2617
2625
2618
2626
{
2619
2627
PGresult * res ;
2620
- uint32 xlogid ;
2621
- uint32 xrecoff ;
2628
+ uint32 lsn_hi ;
2629
+ uint32 lsn_lo ;
2622
2630
XLogRecPtr lsn ;
2623
2631
2624
2632
res = pgut_execute (backup_conn , "select pg_catalog.pg_ptrack_control_lsn()" , 0 , NULL );
2625
2633
2626
2634
/* Extract timeline and LSN from results of pg_start_backup() */
2627
- XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & xlogid , & xrecoff );
2635
+ XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & lsn_hi , & lsn_lo );
2628
2636
/* Calculate LSN */
2629
- lsn = (XLogRecPtr ) (( uint64 ) xlogid << 32 ) | xrecoff ;
2637
+ lsn = (( uint64 ) lsn_hi ) << 32 | lsn_lo ;
2630
2638
2631
2639
PQclear (res );
2632
2640
return lsn ;
0 commit comments