Skip to content

Commit b5019b4

Browse files
committed
Merge branch 'master' into stable
2 parents ee7b993 + 76afcee commit b5019b4

File tree

17 files changed

+166
-167
lines changed

17 files changed

+166
-167
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ apt-get install pg-probackup-(10|9.6|9.5)
5252
#DEB-SRC Packages
5353
echo "deb-src [arch=amd64] http://repo.postgrespro.ru/pg_probackup/deb/ $(lsb_release -cs) main-$(lsb_release -cs)" >>\
5454
/etc/apt/sources.list.d/pg_probackup.list
55-
```
5655

57-
```shell
5856
#RPM Centos Packages
5957
rpm -ivh http://repo.postgrespro.ru/pg_probackup/keys/pg_probackup-repo-centos.noarch.rpm
6058
yum install pg_probackup-(10|9.6|9.5)
59+
60+
#SRPM Centos Packages
61+
yumdownloader --source pg_probackup-(10|9.6|9.5)
6162
```
6263

6364
To compile `pg_probackup`, you must have a PostgreSQL installation and raw source tree. To install `pg_probackup`, execute this in the module's directory:

src/backup.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -877,33 +877,33 @@ do_backup(time_t start_time)
877877
static void
878878
check_server_version(void)
879879
{
880-
PGresult *res;
881-
882880
/* confirm server version */
883881
server_version = PQserverVersion(backup_conn);
884882

883+
if (server_version == 0)
884+
elog(ERROR, "Unknown server version %d", server_version);
885+
886+
if (server_version < 100000)
887+
sprintf(server_version_str, "%d.%d",
888+
server_version / 10000,
889+
(server_version / 100) % 100);
890+
else
891+
sprintf(server_version_str, "%d",
892+
server_version / 10000);
893+
885894
if (server_version < 90500)
886895
elog(ERROR,
887-
"server version is %d.%d.%d, must be %s or higher",
888-
server_version / 10000,
889-
(server_version / 100) % 100,
890-
server_version % 100, "9.5");
896+
"server version is %s, must be %s or higher",
897+
server_version_str, "9.5");
891898

892899
if (from_replica && server_version < 90600)
893900
elog(ERROR,
894-
"server version is %d.%d.%d, must be %s or higher for backup from replica",
895-
server_version / 10000,
896-
(server_version / 100) % 100,
897-
server_version % 100, "9.6");
901+
"server version is %s, must be %s or higher for backup from replica",
902+
server_version_str, "9.6");
898903

899904
/* Do exclusive backup only for PostgreSQL 9.5 */
900905
exclusive_backup = server_version < 90600 ||
901906
current.backup_mode == BACKUP_MODE_DIFF_PTRACK;
902-
903-
/* Save server_version to use it in future */
904-
res = pgut_execute(backup_conn, "show server_version", 0, NULL, true);
905-
StrNCpy(server_version_str, PQgetvalue(res, 0, 0), sizeof(server_version_str));
906-
PQclear(res);
907907
}
908908

909909
/*
@@ -940,7 +940,7 @@ confirm_block_size(const char *name, int blcksz)
940940
char *endp;
941941
int block_size;
942942

943-
res = pgut_execute(backup_conn, "SELECT current_setting($1)", 1, &name, true);
943+
res = pgut_execute(backup_conn, "SELECT pg_catalog.current_setting($1)", 1, &name, true);
944944
if (PQntuples(res) != 1 || PQnfields(res) != 1)
945945
elog(ERROR, "cannot get %s: %s", name, PQerrorMessage(backup_conn));
946946

@@ -974,13 +974,13 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
974974
params[1] = smooth ? "false" : "true";
975975
if (!exclusive_backup)
976976
res = pgut_execute(conn,
977-
"SELECT pg_start_backup($1, $2, false)",
977+
"SELECT pg_catalog.pg_start_backup($1, $2, false)",
978978
2,
979979
params,
980980
true);
981981
else
982982
res = pgut_execute(conn,
983-
"SELECT pg_start_backup($1, $2)",
983+
"SELECT pg_catalog.pg_start_backup($1, $2)",
984984
2,
985985
params,
986986
true);
@@ -1038,9 +1038,9 @@ pg_switch_wal(PGconn *conn)
10381038
PQclear(res);
10391039

10401040
if (server_version >= 100000)
1041-
res = pgut_execute(conn, "SELECT * FROM pg_switch_wal()", 0, NULL, true);
1041+
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_wal()", 0, NULL, true);
10421042
else
1043-
res = pgut_execute(conn, "SELECT * FROM pg_switch_xlog()", 0, NULL, true);
1043+
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_xlog()", 0, NULL, true);
10441044

10451045
PQclear(res);
10461046
}
@@ -1065,7 +1065,7 @@ pg_ptrack_support(void)
10651065
PQclear(res_db);
10661066

10671067
res_db = pgut_execute(backup_conn,
1068-
"SELECT ptrack_version()",
1068+
"SELECT pg_catalog.ptrack_version()",
10691069
0, NULL, true);
10701070
if (PQntuples(res_db) == 0)
10711071
{
@@ -1125,7 +1125,7 @@ pg_is_in_recovery(void)
11251125
{
11261126
PGresult *res_db;
11271127

1128-
res_db = pgut_execute(backup_conn, "SELECT pg_is_in_recovery()", 0, NULL, true);
1128+
res_db = pgut_execute(backup_conn, "SELECT pg_catalog.pg_is_in_recovery()", 0, NULL, true);
11291129

11301130
if (PQgetvalue(res_db, 0, 0)[0] == 't')
11311131
{
@@ -1164,11 +1164,11 @@ pg_ptrack_clear(void)
11641164
tblspcOid = atoi(PQgetvalue(res_db, i, 2));
11651165

11661166
tmp_conn = pgut_connect(dbname);
1167-
res = pgut_execute(tmp_conn, "SELECT pg_ptrack_clear()", 0, NULL, true);
1167+
res = pgut_execute(tmp_conn, "SELECT pg_catalog.pg_ptrack_clear()", 0, NULL, true);
11681168

11691169
sprintf(params[0], "%i", dbOid);
11701170
sprintf(params[1], "%i", tblspcOid);
1171-
res = pgut_execute(tmp_conn, "SELECT pg_ptrack_get_and_clear_db($1, $2)",
1171+
res = pgut_execute(tmp_conn, "SELECT pg_catalog.pg_ptrack_get_and_clear_db($1, $2)",
11721172
2, (const char **)params, true);
11731173
PQclear(res);
11741174

@@ -1215,7 +1215,7 @@ pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid)
12151215

12161216
sprintf(params[0], "%i", dbOid);
12171217
sprintf(params[1], "%i", tblspcOid);
1218-
res = pgut_execute(backup_conn, "SELECT pg_ptrack_get_and_clear_db($1, $2)",
1218+
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_ptrack_get_and_clear_db($1, $2)",
12191219
2, (const char **)params, true);
12201220

12211221
if (PQnfields(res) != 1)
@@ -1276,7 +1276,7 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
12761276
tmp_conn = pgut_connect(dbname);
12771277
sprintf(params[0], "%i", tablespace_oid);
12781278
sprintf(params[1], "%i", rel_filenode);
1279-
res = pgut_execute(tmp_conn, "SELECT pg_ptrack_get_and_clear($1, $2)",
1279+
res = pgut_execute(tmp_conn, "SELECT pg_catalog.pg_ptrack_get_and_clear($1, $2)",
12801280
2, (const char **)params, true);
12811281

12821282
if (PQnfields(res) != 1)
@@ -1294,7 +1294,7 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
12941294
*/
12951295
sprintf(params[0], "%i", tablespace_oid);
12961296
sprintf(params[1], "%i", rel_filenode);
1297-
res = pgut_execute(backup_conn, "SELECT pg_ptrack_get_and_clear($1, $2)",
1297+
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_ptrack_get_and_clear($1, $2)",
12981298
2, (const char **)params, true);
12991299

13001300
if (PQnfields(res) != 1)
@@ -1475,10 +1475,10 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
14751475
if (is_start_backup)
14761476
{
14771477
if (server_version >= 100000)
1478-
res = pgut_execute(backup_conn, "SELECT pg_last_wal_replay_lsn()",
1478+
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_wal_replay_lsn()",
14791479
0, NULL, true);
14801480
else
1481-
res = pgut_execute(backup_conn, "SELECT pg_last_xlog_replay_location()",
1481+
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_xlog_replay_location()",
14821482
0, NULL, true);
14831483
}
14841484
/*
@@ -1488,10 +1488,10 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
14881488
else
14891489
{
14901490
if (server_version >= 100000)
1491-
res = pgut_execute(backup_conn, "SELECT pg_last_wal_receive_lsn()",
1491+
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_wal_receive_lsn()",
14921492
0, NULL, true);
14931493
else
1494-
res = pgut_execute(backup_conn, "SELECT pg_last_xlog_receive_location()",
1494+
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_xlog_receive_location()",
14951495
0, NULL, true);
14961496
}
14971497

@@ -1575,7 +1575,7 @@ pg_stop_backup(pgBackup *backup)
15751575
base36enc(backup->start_time));
15761576
params[0] = name;
15771577

1578-
res = pgut_execute(conn, "SELECT pg_create_restore_point($1)",
1578+
res = pgut_execute(conn, "SELECT pg_catalog.pg_create_restore_point($1)",
15791579
1, params, true);
15801580
PQclear(res);
15811581
}
@@ -1600,22 +1600,22 @@ pg_stop_backup(pgBackup *backup)
16001600
*/
16011601
sent = pgut_send(conn,
16021602
"SELECT"
1603-
" txid_snapshot_xmax(txid_current_snapshot()),"
1603+
" pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
16041604
" current_timestamp(0)::timestamptz,"
16051605
" lsn,"
16061606
" labelfile,"
16071607
" spcmapfile"
1608-
" FROM pg_stop_backup(false)",
1608+
" FROM pg_catalog.pg_stop_backup(false)",
16091609
0, NULL, WARNING);
16101610
}
16111611
else
16121612
{
16131613

16141614
sent = pgut_send(conn,
16151615
"SELECT"
1616-
" txid_snapshot_xmax(txid_current_snapshot()),"
1616+
" pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
16171617
" current_timestamp(0)::timestamptz,"
1618-
" pg_stop_backup() as lsn",
1618+
" pg_catalog.pg_stop_backup() as lsn",
16191619
0, NULL, WARNING);
16201620
}
16211621
pg_stop_backup_is_sent = true;
@@ -2118,8 +2118,8 @@ parse_backup_filelist_filenames(parray *files, const char *root)
21182118
continue;
21192119
}
21202120

2121-
/* Check files located inside database directories */
2122-
if (filename[0] != '\0' && file->dbOid != 0)
2121+
/* Check files located inside database directories including directory 'global' */
2122+
if (filename[0] != '\0' && file->tblspcOid != 0)
21232123
{
21242124
if (strcmp(filename, "pg_internal.init") == 0)
21252125
{
@@ -2679,7 +2679,7 @@ get_last_ptrack_lsn(void)
26792679
uint32 xrecoff;
26802680
XLogRecPtr lsn;
26812681

2682-
res = pgut_execute(backup_conn, "select pg_ptrack_control_lsn()", 0, NULL, true);
2682+
res = pgut_execute(backup_conn, "select pg_catalog.pg_ptrack_control_lsn()", 0, NULL, true);
26832683

26842684
/* Extract timeline and LSN from results of pg_start_backup() */
26852685
XLogDataFromLSN(PQgetvalue(res, 0, 0), &xlogid, &xrecoff);
@@ -2727,7 +2727,7 @@ pg_ptrack_get_block(backup_files_args *arguments,
27272727
//elog(LOG, "db %i pg_ptrack_get_block(%i, %i, %u)",dbOid, tblsOid, relOid, blknum);
27282728
res = pgut_execute_parallel(arguments->thread_backup_conn,
27292729
arguments->thread_cancel_conn,
2730-
"SELECT pg_ptrack_get_block_2($1, $2, $3, $4)",
2730+
"SELECT pg_catalog.pg_ptrack_get_block_2($1, $2, $3, $4)",
27312731
4, (const char **)params, true);
27322732

27332733
if (PQnfields(res) != 1)
@@ -2755,4 +2755,4 @@ pg_ptrack_get_block(backup_files_args *arguments,
27552755
pfree(params[3]);
27562756

27572757
return result;
2758-
}
2758+
}

src/data.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,9 @@ restore_data_file(const char *from_root,
602602
* Backup contains information that this block was truncated.
603603
* Truncate file to this length.
604604
*/
605-
ftruncate(fileno(out), header.block * BLCKSZ);
605+
if (ftruncate(fileno(out), header.block * BLCKSZ) != 0)
606+
elog(ERROR, "cannot truncate \"%s\": %s",
607+
file->path, strerror(errno));
606608
elog(VERBOSE, "truncate file %s to block %u", file->path, header.block);
607609
break;
608610
}

src/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fetchFile(PGconn *conn, const char *filename, size_t *filesize)
9595
int len;
9696

9797
params[0] = filename;
98-
res = pgut_execute(conn, "SELECT pg_read_binary_file($1)",
98+
res = pgut_execute(conn, "SELECT pg_catalog.pg_read_binary_file($1)",
9999
1, params, false);
100100

101101
/* sanity check the result set */

src/pg_probackup.c

Lines changed: 29 additions & 14 deletions
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.15";
20+
const char *PROGRAM_VERSION = "2.0.16";
2121
const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
2222
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
2323

@@ -176,7 +176,7 @@ static pgut_option options[] =
176176
int
177177
main(int argc, char *argv[])
178178
{
179-
char *command;
179+
char *command = NULL;
180180
char path[MAXPGPATH];
181181
/* Check if backup_path is directory. */
182182
struct stat stat_buf;
@@ -253,22 +253,29 @@ main(int argc, char *argv[])
253253
* Make command string before getopt_long() will call. It permutes the
254254
* content of argv.
255255
*/
256-
if (backup_subcmd == BACKUP)
256+
if (backup_subcmd == BACKUP ||
257+
backup_subcmd == RESTORE ||
258+
backup_subcmd == VALIDATE ||
259+
backup_subcmd == DELETE)
257260
{
258261
int i,
259-
len = 0;
262+
len = 0,
263+
allocated = 0;
260264

261-
command = (char *) palloc(sizeof(char) * MAXPGPATH);
262-
command[0] = '\0';
265+
allocated = sizeof(char) * MAXPGPATH;
266+
command = (char *) palloc(allocated);
263267

264268
for (i = 0; i < argc; i++)
265269
{
266270
int arglen = strlen(argv[i]);
267271

268-
if (arglen + len > MAXPGPATH)
269-
break;
272+
if (arglen + len > allocated)
273+
{
274+
allocated *= 2;
275+
command = repalloc(command, allocated);
276+
}
270277

271-
strncpy((command +len), argv[i], arglen);
278+
strncpy(command + len, argv[i], arglen);
272279
len += arglen;
273280
command[len++] = ' ';
274281
}
@@ -303,6 +310,18 @@ main(int argc, char *argv[])
303310
if (rc != -1 && !S_ISDIR(stat_buf.st_mode))
304311
elog(ERROR, "-B, --backup-path must be a path to directory");
305312

313+
/* Initialize logger */
314+
init_logger(backup_path);
315+
316+
/* command was initialized for a few commands */
317+
if (command)
318+
{
319+
elog_file(INFO, "command: %s", command);
320+
321+
pfree(command);
322+
command = NULL;
323+
}
324+
306325
/* Option --instance is required for all commands except init and show */
307326
if (backup_subcmd != INIT && backup_subcmd != SHOW && backup_subcmd != VALIDATE)
308327
{
@@ -353,9 +372,6 @@ main(int argc, char *argv[])
353372
if (pgdata != NULL && !is_absolute_path(pgdata))
354373
elog(ERROR, "-D, --pgdata must be an absolute path");
355374

356-
/* Initialize logger */
357-
init_logger(backup_path);
358-
359375
/* Sanity check of --backup-id option */
360376
if (backup_id_string_param != NULL)
361377
{
@@ -421,8 +437,7 @@ main(int argc, char *argv[])
421437

422438
elog(INFO, "Backup start, pg_probackup version: %s, backup ID: %s, backup mode: %s, instance: %s, stream: %s, remote: %s",
423439
PROGRAM_VERSION, base36enc(start_time), backup_mode, instance_name,
424-
current.stream ? "true" : "false", is_remote_backup ? "true" : "false");
425-
elog_file(INFO, "command: %s", command);
440+
stream_wal ? "true" : "false", is_remote_backup ? "true" : "false");
426441

427442
return do_backup(start_time);
428443
}

src/restore.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ do_restore_or_validate(time_t target_backup_id,
106106
elog(ERROR, "restore destination is not empty: \"%s\"", pgdata);
107107
}
108108

109+
if (instance_name == NULL)
110+
elog(ERROR, "required parameter not specified: --instance");
111+
109112
rt = parseRecoveryTargetOptions(target_time, target_xid, target_inclusive);
110113

111114
elog(LOG, "%s begin.", action);

0 commit comments

Comments
 (0)