Skip to content

Commit c5ff05a

Browse files
committed
Merge branch 'master' into stable
2 parents 3b03593 + fae522d commit c5ff05a

File tree

8 files changed

+110
-13
lines changed

8 files changed

+110
-13
lines changed

src/backup.c

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ do_backup(void)
867867
current.status = BACKUP_STATUS_DONE;
868868
pgBackupWriteBackupControlFile(&current);
869869

870-
elog(LOG, "Backup completed. Total bytes : " INT64_FORMAT "",
871-
current.data_bytes);
870+
//elog(LOG, "Backup completed. Total bytes : " INT64_FORMAT "",
871+
// current.data_bytes);
872872

873873
pgBackupValidate(&current);
874874

@@ -910,7 +910,8 @@ check_server_version(void)
910910
server_version % 100, "9.6");
911911

912912
/* Do exclusive backup only for PostgreSQL 9.5 */
913-
exclusive_backup = server_version < 90600;
913+
exclusive_backup = server_version < 90600 ||
914+
current.backup_mode == BACKUP_MODE_DIFF_PTRACK;
914915

915916
/* Save server_version to use it in future */
916917
res = pgut_execute(backup_conn, "show server_version", 0, NULL);
@@ -1401,13 +1402,19 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
14011402
timeout = archive_timeout;
14021403
}
14031404

1405+
if (wait_prev_segment)
1406+
elog(LOG, "Looking for segment: %s", wal_segment);
1407+
else
1408+
elog(LOG, "Looking for LSN: %X/%X in segment: %s", (uint32) (lsn >> 32), (uint32) lsn, wal_segment);
1409+
14041410
/* Wait until target LSN is archived or streamed */
14051411
while (true)
14061412
{
14071413
bool file_exists = fileExists(wal_segment_full_path);
14081414

14091415
if (file_exists)
14101416
{
1417+
elog(LOG, "Found segment: %s", wal_segment);
14111418
/* Do not check LSN for previous WAL segment */
14121419
if (wait_prev_segment)
14131420
return;
@@ -1418,7 +1425,10 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
14181425
if ((stream_wal && wal_contains_lsn(wal_dir, lsn, tli)) ||
14191426
(!stream_wal && wal_contains_lsn(arclog_path, lsn, tli)))
14201427
/* Target LSN was found */
1428+
{
1429+
elog(LOG, "Found LSN: %X/%X", (uint32) (lsn >> 32), (uint32) lsn);
14211430
return;
1431+
}
14221432
}
14231433

14241434
sleep(1);
@@ -1653,6 +1663,8 @@ pg_stop_backup(pgBackup *backup)
16531663
}
16541664
if (!res)
16551665
elog(ERROR, "pg_stop backup() failed");
1666+
else
1667+
elog(INFO, "pg_stop backup() successfully executed");
16561668
}
16571669

16581670
backup_in_progress = false;
@@ -1990,13 +2002,15 @@ backup_files(void *arg)
19902002
/*
19912003
* Extract information about files in backup_list parsing their names:
19922004
* - remove temp tables from the list
2005+
* - remove unlogged tables from the list (leave the _init fork)
19932006
* - set flags for database directories
19942007
* - set flags for datafiles
19952008
*/
19962009
static void
19972010
parse_backup_filelist_filenames(parray *files, const char *root)
19982011
{
19992012
size_t i;
2013+
Oid unlogged_file_reloid = 0;
20002014

20012015
for (i = 0; i < parray_num(files); i++)
20022016
{
@@ -2157,13 +2171,46 @@ parse_backup_filelist_filenames(parray *files, const char *root)
21572171
/* auxiliary fork of the relfile */
21582172
sscanf(filename, "%u_%s", &(file->relOid), file->forkName);
21592173
elog(VERBOSE, "relOid %u, forkName %s, filepath %s", file->relOid, file->forkName, relative);
2160-
if (strcmp(file->forkName, "ptrack") == 0)
2174+
2175+
/* handle unlogged relations */
2176+
if (strcmp(file->forkName, "init") == 0)
2177+
{
2178+
/*
2179+
* Do not backup files of unlogged relations.
2180+
* scan filelist backward and exclude these files.
2181+
*/
2182+
int unlogged_file_num = i-1;
2183+
pgFile *unlogged_file = (pgFile *) parray_get(files, unlogged_file_num);
2184+
2185+
unlogged_file_reloid = file->relOid;
2186+
2187+
while (unlogged_file_num >= 0 &&
2188+
(unlogged_file_reloid != 0) &&
2189+
(unlogged_file->relOid == unlogged_file_reloid))
2190+
{
2191+
unlogged_file->size = 0;
2192+
pgFileFree(unlogged_file);
2193+
parray_remove(files, unlogged_file_num);
2194+
unlogged_file_num--;
2195+
i--;
2196+
unlogged_file = (pgFile *) parray_get(files, unlogged_file_num);
2197+
}
2198+
}
2199+
else if (strcmp(file->forkName, "ptrack") == 0)
21612200
{
21622201
/* Do not backup ptrack files */
21632202
pgFileFree(file);
21642203
parray_remove(files, i);
21652204
i--;
21662205
}
2206+
else if ((unlogged_file_reloid != 0) &&
2207+
(file->relOid == unlogged_file_reloid))
2208+
{
2209+
/* Do not backup forks of unlogged relations */
2210+
pgFileFree(file);
2211+
parray_remove(files, i);
2212+
i--;
2213+
}
21672214
continue;
21682215
}
21692216

@@ -2201,6 +2248,15 @@ parse_backup_filelist_filenames(parray *files, const char *root)
22012248
*/
22022249
elog(VERBOSE, "relOid %u, segno %d, suffix %s, filepath %s", file->relOid, file->segno, suffix, relative);
22032250
}
2251+
2252+
if ((unlogged_file_reloid != 0) &&
2253+
(file->relOid == unlogged_file_reloid))
2254+
{
2255+
/* Do not backup segments of unlogged files */
2256+
pgFileFree(file);
2257+
parray_remove(files, i);
2258+
i--;
2259+
}
22042260
}
22052261
}
22062262
}

src/data.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
140140
/*
141141
* Read the page and verify its header and checksum.
142142
* Under high write load it's possible that we've read partly
143-
* flushed page, so try several times befor throwing an error.
143+
* flushed page, so try several times before throwing an error.
144144
*/
145145
while(try_checksum--)
146146
{
@@ -152,6 +152,20 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
152152

153153
if (read_len != BLCKSZ)
154154
{
155+
if (read_len == 0)
156+
{
157+
elog(LOG, "File %s, block %u, file was truncated",
158+
file->path, blknum);
159+
return;
160+
}
161+
else if (try_checksum)
162+
{
163+
elog(LOG, "File: %s, block %u, expected block size %lu, but read %d, try again",
164+
file->path, blknum, read_len, BLCKSZ);
165+
usleep(100);
166+
continue;
167+
}
168+
155169
elog(ERROR, "File: %s, invalid block size of block %u : %lu",
156170
file->path, blknum, read_len);
157171
}
@@ -494,7 +508,7 @@ restore_data_file(const char *from_root,
494508
if (header.block < blknum)
495509
elog(ERROR, "backup is broken at block %u", blknum);
496510

497-
elog(VERBOSE, "file %s, header compressed size %d", file->path, header.compressed_size);
511+
//elog(VERBOSE, "file %s, header compressed size %d", file->path, header.compressed_size);
498512
Assert(header.compressed_size <= BLCKSZ);
499513

500514
read_len = fread(compressed_page.data, 1,

src/pg_probackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <sys/stat.h>
1818
#include <unistd.h>
1919

20-
const char *PROGRAM_VERSION = "2.0.11";
20+
const char *PROGRAM_VERSION = "2.0.12";
2121
const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
2222
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
2323

src/restore.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ do_restore_or_validate(time_t target_backup_id,
131131
if (target_backup_id && current_backup->start_time > target_backup_id)
132132
continue;
133133

134+
/*
135+
* [PGPRO-1164] If BACKUP_ID is not provided for restore command,
136+
* we must find the first valid(!) backup.
137+
*/
138+
139+
if (is_restore && target_backup_id == 0 && current_backup->status != BACKUP_STATUS_OK)
140+
{
141+
elog(WARNING, "Skipping backup %s, because it has non-valid status: %s",
142+
base36enc(current_backup->start_time), status2str(current_backup->status));
143+
continue;
144+
}
145+
134146
/*
135147
* We found target backup. Check its status and
136148
* ensure that it satisfies recovery target.

src/utils/pgut.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static PGcancel *volatile cancel_conn = NULL;
4747
/* Interrupted by SIGINT (Ctrl+C) ? */
4848
bool interrupted = false;
4949
bool in_cleanup = false;
50+
bool in_password = false;
5051

5152
static bool parse_pair(const char buffer[], char key[], char value[]);
5253

@@ -1080,7 +1081,8 @@ parse_pair(const char buffer[], char key[], char value[])
10801081
static void
10811082
prompt_for_password(const char *username)
10821083
{
1083-
pqsignal(SIGINT, oldhandler);
1084+
in_password = true;
1085+
10841086
if (password)
10851087
{
10861088
free(password);
@@ -1107,7 +1109,8 @@ prompt_for_password(const char *username)
11071109
password = simple_prompt(message, 100, false);
11081110
}
11091111
#endif
1110-
init_cancel_handler();
1112+
1113+
in_password = false;
11111114
}
11121115

11131116
PGconn *
@@ -1238,6 +1241,8 @@ pgut_connect_replication_extended(const char *pghost, const char *pgport,
12381241
{
12391242
PQfinish(tmpconn);
12401243
prompt_for_password(username);
1244+
keywords[i] = "password";
1245+
values[i] = password;
12411246
continue;
12421247
}
12431248

@@ -1525,6 +1530,15 @@ on_interrupt(void)
15251530
/* Set interruped flag */
15261531
interrupted = true;
15271532

1533+
/* User promts password, call on_cleanup() byhand */
1534+
if (in_password)
1535+
{
1536+
on_cleanup();
1537+
1538+
pqsignal(SIGINT, oldhandler);
1539+
kill(0, SIGINT);
1540+
}
1541+
15281542
/* Send QueryCancel if we are processing a database query */
15291543
if (!in_cleanup && cancel_conn != NULL &&
15301544
PQcancel(cancel_conn, errbuf, sizeof(errbuf)))

src/utils/pgut.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ extern bool prompt_password;
105105

106106
extern bool interrupted;
107107
extern bool in_cleanup;
108+
extern bool in_password; /* User prompts password */
108109

109110
extern int pgut_getopt(int argc, char **argv, pgut_option options[]);
110111
extern void pgut_readopt(const char *path, pgut_option options[], int elevel);

src/validate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ pgBackupValidate(pgBackup *backup)
5151
return;
5252
}
5353

54-
elog(LOG, "Validate backup %s", backup_id_string);
54+
elog(INFO, "Validating backup %s", backup_id_string);
5555

5656
if (backup->backup_mode != BACKUP_MODE_FULL &&
5757
backup->backup_mode != BACKUP_MODE_DIFF_PAGE &&
5858
backup->backup_mode != BACKUP_MODE_DIFF_PTRACK)
59-
elog(LOG, "Invalid backup_mode of backup %s", backup_id_string);
59+
elog(INFO, "Invalid backup_mode of backup %s", backup_id_string);
6060

6161
pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR);
6262
pgBackupGetPath(backup, path, lengthof(path), DATABASE_FILE_LIST);
@@ -99,7 +99,7 @@ pgBackupValidate(pgBackup *backup)
9999
if (corrupted)
100100
elog(WARNING, "Backup %s is corrupted", backup_id_string);
101101
else
102-
elog(LOG, "Backup %s is valid", backup_id_string);
102+
elog(INFO, "Backup %s is valid", backup_id_string);
103103
free(backup_id_string);
104104
}
105105

tests/expected/option_version.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pg_probackup 2.0.11
1+
pg_probackup 2.0.12

0 commit comments

Comments
 (0)