@@ -52,7 +52,9 @@ static pthread_mutex_t start_stream_mut = PTHREAD_MUTEX_INITIALIZER;
52
52
static pthread_t stream_thread ;
53
53
54
54
static int is_ptrack_enable = false;
55
+ bool is_ptrack_support = false;
55
56
bool is_checksum_enabled = false;
57
+ bool exclusive_backup = false;
56
58
57
59
/* Backup connections */
58
60
static PGconn * backup_conn = NULL ;
@@ -63,7 +65,6 @@ static PGconn *backup_conn_replication = NULL;
63
65
static int server_version = 0 ;
64
66
static char server_version_str [100 ] = "" ;
65
67
66
- static bool exclusive_backup = false;
67
68
/* Is pg_start_backup() was executed */
68
69
static bool backup_in_progress = false;
69
70
/* Is pg_stop_backup() was sent */
@@ -505,7 +506,7 @@ do_backup_instance(void)
505
506
506
507
/*
507
508
* It`s illegal to take PTRACK backup if LSN from ptrack_control() is not equal to
508
- * start_backup LSN of previous backup
509
+ * stort_backup LSN of previous backup
509
510
*/
510
511
if (current .backup_mode == BACKUP_MODE_DIFF_PTRACK )
511
512
{
@@ -622,7 +623,7 @@ do_backup_instance(void)
622
623
else
623
624
dir_name = file -> path ;
624
625
625
- elog (LOG , "Create directory \"%s\"" , dir_name );
626
+ elog (VERBOSE , "Create directory \"%s\"" , dir_name );
626
627
pgBackupGetPath (& current , database_path , lengthof (database_path ),
627
628
DATABASE_DIR );
628
629
@@ -653,9 +654,10 @@ do_backup_instance(void)
653
654
}
654
655
655
656
/* Run threads */
657
+ elog (LOG , "Start transfering data files" );
656
658
for (i = 0 ; i < num_threads ; i ++ )
657
659
{
658
- elog (LOG , "Start thread num:%i" , i );
660
+ elog (VERBOSE , "Start thread num: %i" , i );
659
661
660
662
if (!is_remote_backup )
661
663
pthread_create (& backup_threads [i ], NULL ,
@@ -671,10 +673,9 @@ do_backup_instance(void)
671
673
for (i = 0 ; i < num_threads ; i ++ )
672
674
{
673
675
pthread_join (backup_threads [i ], NULL );
674
- if (backup_threads_args [i ]-> thread_backup_conn != NULL )
675
- pgut_disconnect (backup_threads_args [i ]-> thread_backup_conn );
676
676
pg_free (backup_threads_args [i ]);
677
677
}
678
+ elog (LOG , "Data files are transfered" );
678
679
679
680
/* clean previous backup file list */
680
681
if (prev_backup_filelist )
@@ -743,7 +744,6 @@ do_backup_instance(void)
743
744
int
744
745
do_backup (time_t start_time )
745
746
{
746
- bool is_ptrack_support ;
747
747
748
748
/* PGDATA and BACKUP_MODE are always required */
749
749
if (pgdata == NULL )
@@ -771,6 +771,14 @@ do_backup(time_t start_time)
771
771
current .checksum_version = get_data_checksum_version (true);
772
772
773
773
is_checksum_enabled = pg_checksum_enable ();
774
+
775
+ if (is_checksum_enabled )
776
+ elog (LOG , "This PostgreSQL instance initialized with data block checksums. "
777
+ "Data block corruption will be detected" );
778
+ else
779
+ elog (WARNING , "This PostgreSQL instance initialized without data block checksums. "
780
+ "pg_probackup have no way to detect data block corruption without them. "
781
+ "Reinitialize PGDATA with option '--data-checksums'." );
774
782
775
783
StrNCpy (current .server_version , server_version_str ,
776
784
sizeof (current .server_version ));
@@ -857,7 +865,7 @@ do_backup(time_t start_time)
857
865
* After successfil backup completion remove backups
858
866
* which are expired according to retention policies
859
867
*/
860
- if (delete_expired )
868
+ if (delete_expired || delete_wal )
861
869
do_retention_purge ();
862
870
863
871
return 0 ;
@@ -1592,25 +1600,19 @@ pg_stop_backup(pgBackup *backup)
1592
1600
*/
1593
1601
sent = pgut_send (conn ,
1594
1602
"SELECT"
1595
- " labelfile,"
1596
1603
" txid_snapshot_xmax(txid_current_snapshot()),"
1597
1604
" current_timestamp(0)::timestamptz,"
1598
1605
" lsn,"
1606
+ " labelfile,"
1599
1607
" spcmapfile"
1600
1608
" FROM pg_stop_backup(false)" ,
1601
1609
0 , NULL , WARNING );
1602
1610
}
1603
1611
else
1604
1612
{
1605
1613
1606
- tablespace_map_content = pgut_execute (conn ,
1607
- "SELECT pg_read_file('tablespace_map', 0, size, true)"
1608
- " FROM pg_stat_file('tablespace_map', true)" ,
1609
- 0 , NULL , true);
1610
-
1611
1614
sent = pgut_send (conn ,
1612
1615
"SELECT"
1613
- " pg_read_file('backup_label') as labelfile,"
1614
1616
" txid_snapshot_xmax(txid_current_snapshot()),"
1615
1617
" current_timestamp(0)::timestamptz,"
1616
1618
" pg_stop_backup() as lsn" ,
@@ -1668,7 +1670,7 @@ pg_stop_backup(pgBackup *backup)
1668
1670
backup_in_progress = false;
1669
1671
1670
1672
/* Extract timeline and LSN from results of pg_stop_backup() */
1671
- XLogDataFromLSN (PQgetvalue (res , 0 , 3 ), & xlogid , & xrecoff );
1673
+ XLogDataFromLSN (PQgetvalue (res , 0 , 2 ), & xlogid , & xrecoff );
1672
1674
/* Calculate LSN */
1673
1675
stop_backup_lsn = (XLogRecPtr ) ((uint64 ) xlogid << 32 ) | xrecoff ;
1674
1676
@@ -1682,61 +1684,57 @@ pg_stop_backup(pgBackup *backup)
1682
1684
(uint32 ) (stop_backup_lsn >> 32 ), (uint32 ) (stop_backup_lsn ));
1683
1685
1684
1686
/* Write backup_label and tablespace_map */
1685
- Assert (PQnfields (res ) >= 4 );
1686
- pgBackupGetPath (& current , path , lengthof (path ), DATABASE_DIR );
1687
-
1688
- /* Write backup_label */
1689
- join_path_components (backup_label , path , PG_BACKUP_LABEL_FILE );
1690
- fp = fopen (backup_label , "w" );
1691
- if (fp == NULL )
1692
- elog (ERROR , "can't open backup label file \"%s\": %s" ,
1693
- backup_label , strerror (errno ));
1694
-
1695
- len = strlen (PQgetvalue (res , 0 , 0 ));
1696
- if (fwrite (PQgetvalue (res , 0 , 0 ), 1 , len , fp ) != len ||
1697
- fflush (fp ) != 0 ||
1698
- fsync (fileno (fp )) != 0 ||
1699
- fclose (fp ))
1700
- elog (ERROR , "can't write backup label file \"%s\": %s" ,
1701
- backup_label , strerror (errno ));
1702
-
1703
- /*
1704
- * It's vital to check if backup_files_list is initialized,
1705
- * because we could get here because the backup was interrupted
1706
- */
1707
- if (backup_files_list )
1687
+ if (!exclusive_backup )
1708
1688
{
1709
- file = pgFileNew (backup_label , true);
1710
- calc_file_checksum (file );
1711
- free (file -> path );
1712
- file -> path = strdup (PG_BACKUP_LABEL_FILE );
1713
- 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
+ }
1714
1719
}
1715
1720
1716
- if (sscanf (PQgetvalue (res , 0 , 1 ), XID_FMT , & recovery_xid ) != 1 )
1721
+ if (sscanf (PQgetvalue (res , 0 , 0 ), XID_FMT , & recovery_xid ) != 1 )
1717
1722
elog (ERROR ,
1718
1723
"result of txid_snapshot_xmax() is invalid: %s" ,
1719
1724
PQerrorMessage (conn ));
1720
- if (!parse_time (PQgetvalue (res , 0 , 2 ), & recovery_time ))
1725
+ if (!parse_time (PQgetvalue (res , 0 , 1 ), & recovery_time ))
1721
1726
elog (ERROR ,
1722
1727
"result of current_timestamp is invalid: %s" ,
1723
1728
PQerrorMessage (conn ));
1724
1729
1725
- /* Get content for tablespace_map from pg_read_file('tablespace_map') in case of exclusive
1726
- * 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
1727
1732
*/
1728
- if (exclusive_backup )
1729
- {
1730
- Assert (tablespace_map_content );
1731
-
1732
- if (PQresultStatus (tablespace_map_content ) == PGRES_TUPLES_OK )
1733
- val = PQgetvalue (tablespace_map_content , 0 , 0 );
1734
- }
1735
- else
1733
+ if (!exclusive_backup )
1736
1734
val = PQgetvalue (res , 0 , 4 );
1737
1735
1738
1736
/* Write tablespace_map */
1739
- if (val && strlen (val ) > 0 )
1737
+ if (! exclusive_backup && val && strlen (val ) > 0 )
1740
1738
{
1741
1739
char tablespace_map [MAXPGPATH ];
1742
1740
@@ -1958,7 +1956,7 @@ backup_files(void *arg)
1958
1956
current .backup_mode ))
1959
1957
{
1960
1958
file -> write_size = BYTES_INVALID ;
1961
- elog (LOG , "File \"%s\" was not copied to backup" , file -> path );
1959
+ elog (VERBOSE , "File \"%s\" was not copied to backup" , file -> path );
1962
1960
continue ;
1963
1961
}
1964
1962
}
@@ -1967,7 +1965,7 @@ backup_files(void *arg)
1967
1965
file ))
1968
1966
{
1969
1967
file -> write_size = BYTES_INVALID ;
1970
- elog (LOG , "File \"%s\" was not copied to backup" , file -> path );
1968
+ elog (VERBOSE , "File \"%s\" was not copied to backup" , file -> path );
1971
1969
continue ;
1972
1970
}
1973
1971
@@ -1977,6 +1975,11 @@ backup_files(void *arg)
1977
1975
else
1978
1976
elog (LOG , "unexpected file type %d" , buf .st_mode );
1979
1977
}
1978
+
1979
+ /* Close connection */
1980
+ if (arguments -> thread_backup_conn )
1981
+ pgut_disconnect (arguments -> thread_backup_conn );
1982
+
1980
1983
}
1981
1984
1982
1985
/*
@@ -2264,6 +2267,8 @@ set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i)
2264
2267
char * relative_prev_file ;
2265
2268
2266
2269
cfs_tblspc_path = strdup (relative );
2270
+ if (!cfs_tblspc_path )
2271
+ elog (ERROR , "Out of memory" );
2267
2272
len = strlen ("/pg_compression" );
2268
2273
cfs_tblspc_path [strlen (cfs_tblspc_path ) - len ] = 0 ;
2269
2274
elog (VERBOSE , "CFS DIRECTORY %s, pg_compression path: %s" , cfs_tblspc_path , relative );
@@ -2398,6 +2403,7 @@ make_pagemap_from_ptrack(parray *files)
2398
2403
char * ptrack_nonparsed = NULL ;
2399
2404
size_t ptrack_nonparsed_size = 0 ;
2400
2405
2406
+ elog (LOG , "Compiling pagemap" );
2401
2407
for (i = 0 ; i < parray_num (files ); i ++ )
2402
2408
{
2403
2409
pgFile * file = (pgFile * ) parray_get (files , i );
@@ -2492,6 +2498,9 @@ make_pagemap_from_ptrack(parray *files)
2492
2498
}
2493
2499
}
2494
2500
}
2501
+ elog (LOG , "Pagemap compiled" );
2502
+ // res = pgut_execute(backup_conn, "SET client_min_messages = warning;", 0, NULL, true);
2503
+ // PQclear(pgut_execute(backup_conn, "CHECKPOINT;", 0, NULL, true));
2495
2504
}
2496
2505
2497
2506
@@ -2711,7 +2720,9 @@ pg_ptrack_get_block(backup_files_args *arguments,
2711
2720
{
2712
2721
arguments -> thread_backup_conn = pgut_connect (pgut_dbname );
2713
2722
}
2714
- arguments -> thread_cancel_conn = PQgetCancel (arguments -> thread_backup_conn );
2723
+
2724
+ if (arguments -> thread_cancel_conn == NULL )
2725
+ arguments -> thread_cancel_conn = PQgetCancel (arguments -> thread_backup_conn );
2715
2726
2716
2727
//elog(LOG, "db %i pg_ptrack_get_block(%i, %i, %u)",dbOid, tblsOid, relOid, blknum);
2717
2728
res = pgut_execute_parallel (arguments -> thread_backup_conn ,
0 commit comments