Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 81efcfa

Browse files
committed
Merge branch 'PGPROEE9_6' into PGPROEE9_6_partition
2 parents 542cbdb + 5e35a93 commit 81efcfa

File tree

15 files changed

+172
-68
lines changed

15 files changed

+172
-68
lines changed

contrib/pg_probackup/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ some overhead to PostgreSQL performance. On our experiments it appears to be
101101
less than 3%.
102102

103103
These two approaches were implemented in this fork of pg_probackup. The second
104-
approach requires [patch for PostgreSQL 9.5](https://gist.github.com/stalkerg/44703dbcbac1da08f448b7e6966646c0) or
105-
[patch for PostgreSQL 10](https://gist.github.com/stalkerg/ab833d94e2f64df241f1835651e06e4b).
104+
approach requires [patch for PostgreSQL 9.6.2](https://gist.github.com/alubennikova/9daacf35790eca1a09b63a1bca86d836) or
105+
[patch for PostgreSQL 10 (master)](https://gist.github.com/alubennikova/d24f61804525f0248fa71a1075158c21).
106106

107107
Testing block level incremental backup
108108
--------------------------------------
109109

110-
You need build and install [PGPRO9_5 or PGPRO9_6 branch of PostgreSQL](https://github.com/postgrespro/postgrespro) or apply this patch to
111-
[PostgreSQL 9.5](https://gist.github.com/stalkerg/44703dbcbac1da08f448b7e6966646c0) or [PostgreSQL 10](https://gist.github.com/stalkerg/ab833d94e2f64df241f1835651e06e4b).
110+
You need to apply ptrack patch to [PostgreSQL 9.6.2](https://gist.github.com/alubennikova/9daacf35790eca1a09b63a1bca86d836)
111+
or [PostgreSQL 10 (master)](https://gist.github.com/alubennikova/d24f61804525f0248fa71a1075158c21).
112+
Or you can build and install [PGPRO9_5 or PGPRO9_6 branch of PostgreSQL](https://github.com/postgrespro/postgrespro).
113+
Note that PGPRO branches currently contain old version of ptrack.
112114

113115
### Retrieving changed blocks from WAL archive
114116

contrib/pg_probackup/backup.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
111111
/* repack the options */
112112
pgBackup *prev_backup = NULL;
113113

114-
/* Block backup operations on a standby */
115-
from_replica = pg_is_in_recovery();
116-
if (pg_is_standby() && !from_replica)
117-
elog(ERROR, "Backup cannot run on a standby.");
118-
119114
elog(LOG, "database backup start");
120115

121116
/* Initialize size summary */
@@ -423,6 +418,15 @@ do_backup(bool smooth_checkpoint)
423418
/* setup cleanup callback function */
424419
in_backup = true;
425420

421+
/* Block backup operations on a standby */
422+
from_replica = pg_is_in_recovery();
423+
if (pg_is_standby() && !from_replica)
424+
elog(ERROR, "backup is not allowed for standby");
425+
426+
/* Page backup is not allowed for replica instance */
427+
if (from_replica && current.backup_mode == BACKUP_MODE_DIFF_PAGE)
428+
elog(ERROR, "page backup is not allowed for standby");
429+
426430
/* show configuration actually used */
427431
elog(LOG, "========================================");
428432
elog(LOG, "backup start");

contrib/pg_probackup/catalog.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ unlink_lock_atexit(void)
4242
/*
4343
* Create a lockfile.
4444
*/
45-
int
45+
void
4646
catalog_lock(bool check_catalog)
4747
{
4848
int fd;
@@ -220,8 +220,6 @@ catalog_lock(bool check_catalog)
220220
elog(ERROR, "Backup directory was initialized for system id = %ld, but target system id = %ld",
221221
system_identifier, id);
222222
}
223-
224-
return 0;
225223
}
226224

227225
/*

contrib/pg_probackup/dir.c

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,59 @@
2020
#include "pgut/pgut-port.h"
2121
#include "datapagemap.h"
2222

23-
/* directory exclusion list for backup mode listing */
23+
/*
24+
* The contents of these directories are removed or recreated during server
25+
* start so they are not included in backups. The directories themselves are
26+
* kept and included as empty to preserve access permissions.
27+
*/
2428
const char *pgdata_exclude_dir[] =
2529
{
26-
"pg_xlog",
27-
"pg_stat_tmp",
28-
"pgsql_tmp",
29-
NULL, /* pg_log will be set later */
30-
NULL
30+
"pg_xlog",
31+
/*
32+
* Skip temporary statistics files. PG_STAT_TMP_DIR must be skipped even
33+
* when stats_temp_directory is set because PGSS_TEXT_FILE is always created
34+
* there.
35+
*/
36+
"pg_stat_tmp",
37+
"pgsql_tmp",
38+
39+
/*
40+
* It is generally not useful to backup the contents of this directory even
41+
* if the intention is to restore to another master. See backup.sgml for a
42+
* more detailed description.
43+
*/
44+
"pg_replslot",
45+
46+
/* Contents removed on startup, see dsm_cleanup_for_mmap(). */
47+
"pg_dynshmem",
48+
49+
/* Contents removed on startup, see AsyncShmemInit(). */
50+
"pg_notify",
51+
52+
/*
53+
* Old contents are loaded for possible debugging but are not required for
54+
* normal operation, see OldSerXidInit().
55+
*/
56+
"pg_serial",
57+
58+
/* Contents removed on startup, see DeleteAllExportedSnapshotFiles(). */
59+
"pg_snapshots",
60+
61+
/* Contents zeroed on startup, see StartupSUBTRANS(). */
62+
"pg_subtrans",
63+
64+
/* end of list */
65+
NULL, /* pg_log will be set later */
66+
NULL
3167
};
3268

3369
static char *pgdata_exclude_files[] =
3470
{
71+
/* Skip auto conf temporary file. */
72+
"postgresql.auto.conf.tmp",
73+
74+
/* Skip current log file temporary file */
75+
"current_logfiles.tmp",
3576
"recovery.conf",
3677
"postmaster.pid",
3778
"postmaster.opts",
@@ -515,13 +556,7 @@ list_data_directories(parray *files, const char *path, bool is_root,
515556
elog(ERROR, "cannot stat file \"%s\": %s", child, strerror(errno));
516557

517558
if (!S_ISDIR(st.st_mode))
518-
{
519-
/* Stop reading the directory if we met file */
520-
if (!is_root)
521-
break;
522-
else
523-
continue;
524-
}
559+
continue;
525560

526561
/* Check for exclude for the first level of listing */
527562
if (is_root && exclude)

contrib/pg_probackup/doc/pg_probackup.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ This mode should be used with caution as it allows to delete WAL files required
291291

292292
### Backup from Standby
293293

294-
If replication is in use, starting with PostgreSQL 9.6 a backup can be taken not only from primary server, but also from standby. Backup taken from standby is absolutely interchangeable with backup taken from primary (bearing in mind possible replication delay).
294+
If replication is in use, starting with PostgreSQL 9.6 a backup can be taken not only from primary server, but also from standby. Backup taken from standby is absolutely interchangeable with backup taken from primary (bearing in mind possible replication delay). Page-level incremental backups are not allowed to perform from standby.
295295

296-
Currently it is required for primary database server to have full\_page\_writes turned on (in future this requirement may be relaxed in the case checksums are enabled on data pages).
296+
Currently it is required for primary database server to have `full_page_writes` turned `on` (in future this requirement may be relaxed in the case checksums are enabled on data pages).
297297

298-
The same backup directory can be used for pg\_probackup on both servers, primary and standby, as long as it is accessible in both server's file systems. This way all backups, taken from either primary or standby, are shown together and could be managed from one server or from the other.
298+
The same backup directory can be used for `pg_probackup` on both servers, primary and standby, as long as it is accessible in both server's file systems. This way all backups, taken from either primary or standby, are shown together and could be managed from one server or from the other.
299299

300-
A backup can be used to restore primary database server as well as standby. It depends on the server on which pg\_probackup is executed with restore command. Note that recovered PostgreSQL will always run as primary server if started right after the pg\_probackup. To run it as standby, edit recovery.conf file created by pg\_probackup: at least delete every parameter that specify recovery target (recovery\_target, recovery\_target\_time, and recovery\_target\_xid), change target timeline to 'latest', and add standby\_mode = 'on'. Probably primary\_conninfo should be added too for streaming replication, and hot\_standby = 'on' in database configuration parameters for hot standby mode.
300+
A backup can be used to restore primary database server as well as standby. It depends on the server on which `pg_probackup` is executed with restore command. Note that recovered PostgreSQL will always run as primary server if started right after the `pg_probackup`. To run it as standby, edit `recovery.conf` file created by `pg_probackup`: at least delete every parameter that specify recovery target (`recovery_target`, `recovery_target_time`, and `recovery_target_xid`), change target timeline to `latest`, and add `standby_mode = on`. Probably `primary_conninfo` should be added too for streaming replication, and `hot_standby = on` in database configuration parameters for hot standby mode.
301301

302302
### Backup Retention Policy
303303

@@ -480,11 +480,11 @@ Specifies whether to stop just after the specified recovery target (true), or ju
480480

481481
Specifies recovering into a particular timeline.
482482

483-
-T OLDDIR=NEWDIR
484-
--tablespace-mapping=OLDDIR=NEWDIR
483+
-T olddir=newdir
484+
--tablespace-mapping=olddir=newdir
485485

486-
Relocate the tablespace in directory `OLDDIR` to `NEWDIR` during restore. Both
487-
`OLDDIR` and `NEWDIR` must be absolute paths.
486+
Relocate the tablespace in directory `olddir` to `newdir` during restore. Both
487+
`olddir` and `newdir` must be absolute paths.
488488

489489
### Delete options:
490490

contrib/pg_probackup/pg_probackup.c

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

19-
const char *PROGRAM_VERSION = "1.0.1";
19+
const char *PROGRAM_VERSION = "1.1.0";
2020
const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
2121
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
2222

contrib/pg_probackup/pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ extern parray *catalog_get_backup_list(time_t backup_id);
300300
extern pgBackup *catalog_get_last_data_backup(parray *backup_list,
301301
TimeLineID tli);
302302

303-
extern int catalog_lock(bool check_catalog);
303+
extern void catalog_lock(bool check_catalog);
304304

305305
extern void pgBackupWriteConfigSection(FILE *out, pgBackup *backup);
306306
extern void pgBackupWriteResultSection(FILE *out, pgBackup *backup);

contrib/pg_probackup/pgut/pgut.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,12 @@ pgut_getopt(int argc, char **argv, pgut_option options[])
614614
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
615615
{
616616
help(true);
617-
exit_or_abort(1);
617+
exit_or_abort(0);
618618
}
619619
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
620620
{
621621
fprintf(stderr, "%s %s\n", PROGRAM_NAME, PROGRAM_VERSION);
622-
exit_or_abort(1);
622+
exit_or_abort(0);
623623
}
624624
}
625625

contrib/pg_probackup/restore.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ do_restore(time_t backup_id,
9191
pgBackup *base_backup = NULL;
9292
pgBackup *dest_backup = NULL;
9393
pgRecoveryTarget *rt = NULL;
94-
bool need_recovery_conf = false;
94+
bool need_recovery_conf = true;
9595

9696
/* PGDATA and ARCLOG_PATH are always required */
9797
if (pgdata == NULL)
@@ -200,16 +200,16 @@ do_restore(time_t backup_id,
200200
/* Tablespace directories checking */
201201
check_tablespace_mapping((pgBackup *) parray_get(backups, last_diff_index));
202202

203+
if (dest_backup && dest_backup->stream)
204+
need_recovery_conf = target_time != NULL || target_xid != NULL;
205+
203206
/* Restore backups from base_index to last_diff_index */
204-
need_recovery_conf = target_time != NULL || target_xid != NULL;
205207
for (i = base_index; i >= last_diff_index; i--)
206208
{
207209
pgBackup *backup = (pgBackup *) parray_get(backups, i);
208210

209211
if (backup->status == BACKUP_STATUS_OK)
210212
{
211-
need_recovery_conf = need_recovery_conf || !backup->stream;
212-
213213
print_backup_lsn(backup);
214214
restore_database(backup);
215215
}
@@ -416,7 +416,7 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
416416
link_name[len] = '\0';
417417
}
418418
else
419-
strcpy(link_name, link_ptr);
419+
goto create_directory;
420420

421421
tmp_ptr = dir->path;
422422
dir->path = link_name;
@@ -442,7 +442,13 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
442442
* create it second time.
443443
*/
444444
if (strcmp(dir_created, linked_path) == 0)
445-
continue;
445+
{
446+
/* Create rest of directories */
447+
if (link_sep && (link_sep + 1))
448+
goto create_directory;
449+
else
450+
continue;
451+
}
446452
else
447453
elog(ERROR, "tablespace directory \"%s\" of page backup does not "
448454
"match with previous created tablespace directory \"%s\" of symlink \"%s\"",
@@ -467,12 +473,6 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
467473

468474
/* Firstly, create linked directory */
469475
dir_create_dir(linked_path, DIR_PERMISSION);
470-
/* Create rest of directories */
471-
if (link_sep && (link_sep + 1))
472-
{
473-
join_path_components(to_path, linked_path, link_sep + 1);
474-
dir_create_dir(to_path, DIR_PERMISSION);
475-
}
476476

477477
join_path_components(to_path, pg_data_dir, PG_TBLSPC_DIR);
478478
/* Create pg_tblspc directory just in case */
@@ -487,10 +487,15 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
487487
/* Save linked directory */
488488
set_tablespace_created(link_name, linked_path);
489489

490+
/* Create rest of directories */
491+
if (link_sep && (link_sep + 1))
492+
goto create_directory;
493+
490494
continue;
491495
}
492496
}
493497

498+
create_directory:
494499
elog(LOG, "create directory \"%s\"", relative_ptr);
495500

496501
/* This is not symlink, create directory */

contrib/pg_probackup/show.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ do_show(time_t backup_id)
2828
*/
2929
if (backup_id != 0)
3030
{
31-
pgBackup *backup;
31+
pgBackup *backup;
3232

3333
backup = read_backup(backup_id);
3434
if (backup == NULL)
@@ -40,6 +40,7 @@ do_show(time_t backup_id)
4040
/* This is not error case */
4141
return 0;
4242
}
43+
4344
show_backup_detail(stdout, backup);
4445

4546
/* cleanup */
@@ -184,7 +185,7 @@ get_parent_tli(TimeLineID child_tli)
184185
static void
185186
show_backup_list(FILE *out, parray *backup_list)
186187
{
187-
int i;
188+
int i;
188189

189190
/* show header */
190191
fputs("=========================================================================================\n", out);
@@ -193,14 +194,12 @@ show_backup_list(FILE *out, parray *backup_list)
193194

194195
for (i = 0; i < parray_num(backup_list); i++)
195196
{
196-
pgBackup *backup;
197-
const char *modes[] = { "", "PAGE", "PTRACK", "FULL", "", "PAGE+STREAM", "PTRACK+STREAM", "FULL+STREAM"};
198-
TimeLineID parent_tli;
199-
char timestamp[20] = "----";
200-
char duration[20] = "----";
201-
char data_bytes_str[10] = "----";
202-
203-
backup = parray_get(backup_list, i);
197+
pgBackup *backup = parray_get(backup_list, i);
198+
const char *modes[] = {"", "PAGE", "PTRACK", "FULL", "", "PAGE+STREAM", "PTRACK+STREAM", "FULL+STREAM"};
199+
TimeLineID parent_tli;
200+
char timestamp[20] = "----";
201+
char duration[20] = "----";
202+
char data_bytes_str[10] = "----";
204203

205204
if (backup->recovery_time != (time_t) 0)
206205
time2iso(timestamp, lengthof(timestamp), backup->recovery_time);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pg_probackup 1.0
1+
pg_probackup 1.1.0

0 commit comments

Comments
 (0)