Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To support PostgreSQL v15 #229

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0213aed
developments for postgresql v15
zwyan0 Jun 9, 2022
683524f
changed build.yml
zwyan0 Jun 9, 2022
65f7203
modityed the version
zwyan0 Jun 10, 2022
21fd0ec
change some comment
zwyan0 Jul 21, 2022
c25ff60
changed some comment
zwyan0 Jul 27, 2022
d466f13
Changed some comments
zwyan0 Jul 28, 2022
66bc214
Add notes to take a backup at standby-site (#223)
mikecaat Aug 26, 2022
6958642
Add documents of --pgconf-path parameter (#222)
mikecaat Aug 26, 2022
31b1e57
Fix the fail if a tablespace path has PGDATA(#141) (#210)
mikecaat Sep 5, 2022
802c593
Add description for compress target to doc (#235)
kiskk Nov 15, 2022
e0c0036
developments for postgresql v15
zwyan0 Jun 9, 2022
a2c8872
changed build.yml
zwyan0 Jun 9, 2022
2ce8c2e
modityed the version
zwyan0 Jun 10, 2022
b1f359a
change some comment
zwyan0 Jul 21, 2022
05456ba
changed some comment
zwyan0 Jul 27, 2022
bdc7e73
Changed some comments
zwyan0 Jul 28, 2022
9050f90
Fix to work --hard-copy #236 (#237)
mikecaat Dec 9, 2022
9c2619c
Modified the build.yml and comment
zwyan0 Dec 12, 2022
a0e488d
merge
zwyan0 Dec 12, 2022
054bbaf
developments for postgresql v15
zwyan0 Jun 9, 2022
412f68d
changed build.yml
zwyan0 Jun 9, 2022
e1c8d89
modityed the version
zwyan0 Jun 10, 2022
b5150d2
change some comment
zwyan0 Jul 21, 2022
7587614
changed some comment
zwyan0 Jul 27, 2022
0576a52
Changed some comments
zwyan0 Jul 28, 2022
16f58d6
Modified the build.yml and comment
zwyan0 Dec 12, 2022
90a0632
change some comment
zwyan0 Jul 21, 2022
05a99fb
change comment
zwyan0 Dec 12, 2022
6ac01c2
Merge branch 'test_pg15_bate1' of https://github.com/zwyan0/pg_rman i…
zwyan0 Dec 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
shell: bash -xe {0}
run: |
declare -A versions=(
["master"]="14.0"
["master"]="15beta1"
mikecaat marked this conversation as resolved.
Show resolved Hide resolved
["REL_14_STABLE"]="14.0"
["REL_13_STABLE"]="13.4"
["REL_12_STABLE"]="12.8"
Expand Down
57 changes: 26 additions & 31 deletions backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static parray *do_backup_database(parray *backup_list, pgBackupOption bkupopt);
static parray *do_backup_arclog(parray *backup_list);
static parray *do_backup_srvlog(parray *backup_list);
static void confirm_block_size(const char *name, int blcksz);
static void pg_start_backup(const char *label, bool smooth, pgBackup *backup);
static parray *pg_stop_backup(pgBackup *backup);
static void pg_backup_start(const char *label, bool smooth, pgBackup *backup);
static parray *pg_backup_stop(pgBackup *backup);
static void pg_switch_wal(pgBackup *backup);
static void get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn);
static void get_xid(PGresult *res, uint32 *xid);
Expand Down Expand Up @@ -135,14 +135,14 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
/* notify start of backup to PostgreSQL server */
time2iso(label, lengthof(label), current.start_time);
strncat(label, " with pg_rman", lengthof(label) - strlen(label) - 1);
pg_start_backup(label, smooth_checkpoint, &current);
pg_backup_start(label, smooth_checkpoint, &current);

/* Execute restartpoint on standby once replay reaches the backup LSN */
if (current.is_from_standby && !execute_restartpoint(bkupopt, &current))
{
/*
* Disconnecting automatically aborts a non-exclusive backup, so no
* need to call pg_stop_backup() do it for us.
* need to call pg_backup_stop() do it for us.
*/
disconnect();
ereport(ERROR,
Expand Down Expand Up @@ -266,7 +266,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
* Notify end of backup and save the backup_label and tablespace_map
* files.
*/
stop_backup_files = pg_stop_backup(&current);
stop_backup_files = pg_backup_stop(&current);

/* stop_backup_files must be listed in file_database.txt. */
files = parray_concat(stop_backup_files, files);
Expand All @@ -284,14 +284,14 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
parray *tblspc_list; /* list of name of TABLESPACE backup from snapshot */
parray *tblspcmp_list; /* list of mounted directory of TABLESPACE in snapshot volume */
PGresult *tblspc_res; /* contain spcname and oid in TABLESPACE */
parray *stop_backup_files; /* list of files that pg_stop_backup() wrote */
parray *stop_backup_files; /* list of files that pg_backup_stop() wrote */

/* if backup is from standby, snapshot backup is unsupported */
if (current.is_from_standby)
{
/*
* Disconnecting automatically aborts a non-exclusive backup, so no
* need to call pg_stop_backup() do it for us.
* need to call pg_backup_stop() do it for us.
*/
disconnect();
ereport(ERROR,
Expand Down Expand Up @@ -384,7 +384,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
* Notify end of backup and write backup_label and tablespace_map
* files to backup destination directory.
*/
stop_backup_files = pg_stop_backup(&current);
stop_backup_files = pg_backup_stop(&current);
files = parray_concat(stop_backup_files, files);

/* create file list of non-snapshot objects */
Expand Down Expand Up @@ -569,7 +569,7 @@ execute_restartpoint(pgBackupOption bkupopt, pgBackup *backup)

/*
* Wait for standby server to replay WAL up to the LSN returned by
* pg_start_backup()
* pg_backup_start()
*/
res = execute("SELECT * FROM pg_last_wal_replay_lsn()", 0, NULL);
sscanf(PQgetvalue(res, 0, 0), "%X/%X", &xlogid, &xrecoff);
Expand Down Expand Up @@ -647,7 +647,7 @@ do_backup_arclog(parray *backup_list)
files = parray_new();
dir_list_file(files, arclog_path, NULL, true, false);

/* remove WALs archived after pg_stop_backup()/pg_switch_wal() */
/* remove WALs archived after pg_backup_stop()/pg_switch_wal() */
xlog_fname(last_wal, lengthof(last_wal), current.tli, &current.stop_lsn,
wal_segment_size);
for (i = 0; i < parray_num(files); i++)
Expand Down Expand Up @@ -922,7 +922,7 @@ do_backup(pgBackupOption bkupopt)

/* initialize backup result */
current.status = BACKUP_STATUS_RUNNING;
current.tli = 0; /* get from result of pg_start_backup() */
current.tli = 0; /* get from result of pg_backup_start() */
current.start_lsn = current.stop_lsn = (XLogRecPtr) 0;
current.start_time = time(NULL);
current.end_time = (time_t) 0;
Expand Down Expand Up @@ -1107,13 +1107,13 @@ confirm_block_size(const char *name, int blcksz)
* case of taking a backup from standby.
*/
static void
pg_start_backup(const char *label, bool smooth, pgBackup *backup)
pg_backup_start(const char *label, bool smooth, pgBackup *backup)
{
PGresult *res;
const char *params[3];
const char *params[2];
params[0] = label;

elog(DEBUG, "executing pg_start_backup()");
elog(DEBUG, "executing pg_backup_start()");

/*
* Establish new connection to send backup control commands. The same
Expand All @@ -1122,14 +1122,9 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
*/
reconnect();

/* Assumes PG version >= 8.4 */

/* 2nd argument is 'fast' (IOW, !smooth) */
mikecaat marked this conversation as resolved.
Show resolved Hide resolved
params[1] = smooth ? "false" : "true";

/* 3rd argument is 'non-exclusive' (assumes PG version >= 9.6) */
mikecaat marked this conversation as resolved.
Show resolved Hide resolved
params[2] = "false";
res = execute("SELECT * from pg_walfile_name_offset(pg_start_backup($1, $2, $3))", 3, params);
res = execute("SELECT * from pg_walfile_name_offset(pg_backup_start($1, $2))", 2, params);

if (backup != NULL)
get_lsn(res, &backup->tli, &backup->start_lsn);
Expand Down Expand Up @@ -1207,19 +1202,19 @@ wait_for_archive(pgBackup *backup, const char *sql, int nParams,
/*
* Notify the end of backup to PostgreSQL server.
*
* Contacts the primary server and issues pg_stop_backup(), then waits for
* Contacts the primary server and issues pg_backup_stop(), then waits for
* either the primary or standby server to successfully archive the last
* needed WAL segment to be archived. Returns once that's been done.
*
* As of PG version 9.6, pg_stop_backup() returns 2 more fields in addition
* As of PG version from 15.0, pg_backup_stop() returns 2 more fields in addition
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the version number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted this comment.

* to the backup end LSN: backup_label text and tablespace_map text which
* need to be written to files in the backup root directory.
*
* Returns an array of pgFile structs of files written so that caller can add
* it to the backup file list.
*/
static parray *
pg_stop_backup(pgBackup *backup)
pg_backup_stop(pgBackup *backup)
{
parray *result = parray_new();
pgFile *file;
Expand All @@ -1231,12 +1226,12 @@ pg_stop_backup(pgBackup *backup)
int tblspcmap_len;
const char *params[1];

elog(DEBUG, "executing pg_stop_backup()");
elog(DEBUG, "executing pg_backup_stop()");

/*
* Non-exclusive backup requires to use same connection as the one
* used to issue pg_start_backup(). Remember we did not disconnect
* in pg_start_backup() nor did we lose our connection when issuing
* used to issue pg_backup_start(). Remember we did not disconnect
* in pg_backup_start() nor did we lose our connection when issuing
* commands to standby.
*/
Assert(connection != NULL);
Expand All @@ -1245,13 +1240,13 @@ pg_stop_backup(pgBackup *backup)
res = execute("SET client_min_messages = warning;", 0, NULL);
PQclear(res);

params[0] = "false";
res = execute("SELECT * FROM pg_stop_backup($1)", 1, params);
params[0] = "true";
mikecaat marked this conversation as resolved.
Show resolved Hide resolved
res = execute("SELECT * FROM pg_backup_stop($1)", 1, params);

if (res == NULL || PQntuples(res) != 1 || PQnfields(res) != 3)
ereport(ERROR,
(errcode(ERROR_PG_COMMAND),
errmsg("result of pg_stop_backup($1) is invalid: %s",
errmsg("result of pg_backup_stop($1) is invalid: %s",
PQerrorMessage(connection))));

backup_lsn = PQgetvalue(res, 0, 0);
Expand Down Expand Up @@ -1313,7 +1308,7 @@ get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
errmsg("result of pg_walfile_name_offset() is invalid: %s",
PQerrorMessage(connection))));

/* get TimeLineID, LSN from result of pg_stop_backup() */
/* get TimeLineID, LSN from result of pg_backup_stop() */
if (sscanf(PQgetvalue(res, 0, 0), "%08X%08X%08X",
timeline, &xlogid, &off_upper) != 3 ||
sscanf(PQgetvalue(res, 0, 1), "%u", &xrecoff) != 1)
Expand All @@ -1332,7 +1327,7 @@ get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
}

/*
* Get XID from result of txid_current() after pg_stop_backup().
* Get XID from result of txid_current() after pg_backup_stop().
*/
static void
get_xid(PGresult *res, uint32 *xid)
Expand Down
1 change: 1 addition & 0 deletions pgut/pgut.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <pwd.h>

#include "pgut.h"

Expand Down
1 change: 1 addition & 0 deletions sql/arc_srv_log_management.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ wal_level = hot_standby
log_directory = '${SRVLOG_PATH}'
archive_mode = on
archive_command = 'cp %p ${ARCLOG_PATH}/%f'
log_checkpoints = off
EOF

# start PostgreSQL
Expand Down