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

Commit e9d42b1

Browse files
committed
Merge commit '435b5ee2ff304a4405c9292bc55aec058bfa68a5' into PGPRO10
2 parents 4cc73f7 + 435b5ee commit e9d42b1

File tree

8 files changed

+125
-104
lines changed

8 files changed

+125
-104
lines changed

contrib/pg_probackup/src/backup.c

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,8 @@ do_backup_instance(void)
547547

548548
/* notify start of backup to PostgreSQL server */
549549
time2iso(label, lengthof(label), current.start_time);
550-
strncat(label, " with pg_probackup", lengthof(label));
550+
strncat(label, " with pg_probackup", lengthof(label) -
551+
strlen(" with pg_probackup"));
551552
pg_start_backup(label, smooth_checkpoint, &current);
552553

553554
pgBackupGetPath(&current, database_path, lengthof(database_path),
@@ -934,6 +935,8 @@ do_backup(time_t start_time)
934935
static void
935936
check_server_version(void)
936937
{
938+
PGresult *res;
939+
937940
/* confirm server version */
938941
server_version = PQserverVersion(backup_conn);
939942

@@ -958,6 +961,39 @@ check_server_version(void)
958961
"server version is %s, must be %s or higher for backup from replica",
959962
server_version_str, "9.6");
960963

964+
res = pgut_execute_extended(backup_conn, "SELECT pgpro_edition()",
965+
0, NULL, true, true);
966+
967+
/*
968+
* Check major version of connected PostgreSQL and major version of
969+
* compiled PostgreSQL.
970+
*/
971+
#ifdef PGPRO_VERSION
972+
if (PQresultStatus(res) == PGRES_FATAL_ERROR)
973+
/* It seems we connected to PostgreSQL (not Postgres Pro) */
974+
elog(ERROR, "%s was built with Postgres Pro %s %s, "
975+
"but connection made with PostgreSQL %s",
976+
PROGRAM_NAME, PG_MAJORVERSION, PGPRO_EDITION, server_version_str);
977+
else if (strcmp(server_version_str, PG_MAJORVERSION) != 0 &&
978+
strcmp(PQgetvalue(res, 0, 0), PGPRO_EDITION) != 0)
979+
elog(ERROR, "%s was built with Postgres Pro %s %s, "
980+
"but connection made with Postgres Pro %s %s",
981+
PROGRAM_NAME, PG_MAJORVERSION, PGPRO_EDITION,
982+
server_version_str, PQgetvalue(res, 0, 0));
983+
#else
984+
if (PQresultStatus(res) != PGRES_FATAL_ERROR)
985+
/* It seems we connected to Postgres Pro (not PostgreSQL) */
986+
elog(ERROR, "%s was built with PostgreSQL %s, "
987+
"but connection made with Postgres Pro %s %s",
988+
PROGRAM_NAME, PG_MAJORVERSION,
989+
server_version_str, PQgetvalue(res, 0, 0));
990+
else if (strcmp(server_version_str, PG_MAJORVERSION) != 0)
991+
elog(ERROR, "%s was built with PostgreSQL %s, but connection made with %s",
992+
PROGRAM_NAME, PG_MAJORVERSION, server_version_str);
993+
#endif
994+
995+
PQclear(res);
996+
961997
/* Do exclusive backup only for PostgreSQL 9.5 */
962998
exclusive_backup = server_version < 90600 ||
963999
current.backup_mode == BACKUP_MODE_DIFF_PTRACK;
@@ -997,7 +1033,7 @@ confirm_block_size(const char *name, int blcksz)
9971033
char *endp;
9981034
int block_size;
9991035

1000-
res = pgut_execute(backup_conn, "SELECT pg_catalog.current_setting($1)", 1, &name, true);
1036+
res = pgut_execute(backup_conn, "SELECT pg_catalog.current_setting($1)", 1, &name);
10011037
if (PQntuples(res) != 1 || PQnfields(res) != 1)
10021038
elog(ERROR, "cannot get %s: %s", name, PQerrorMessage(backup_conn));
10031039

@@ -1033,14 +1069,12 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
10331069
res = pgut_execute(conn,
10341070
"SELECT pg_catalog.pg_start_backup($1, $2, false)",
10351071
2,
1036-
params,
1037-
true);
1072+
params);
10381073
else
10391074
res = pgut_execute(conn,
10401075
"SELECT pg_catalog.pg_start_backup($1, $2)",
10411076
2,
1042-
params,
1043-
true);
1077+
params);
10441078

10451079
/* Extract timeline and LSN from results of pg_start_backup() */
10461080
XLogDataFromLSN(PQgetvalue(res, 0, 0), &xlogid, &xrecoff);
@@ -1091,13 +1125,13 @@ pg_switch_wal(PGconn *conn)
10911125
PGresult *res;
10921126

10931127
/* Remove annoying NOTICE messages generated by backend */
1094-
res = pgut_execute(conn, "SET client_min_messages = warning;", 0, NULL, true);
1128+
res = pgut_execute(conn, "SET client_min_messages = warning;", 0, NULL);
10951129
PQclear(res);
10961130

10971131
if (server_version >= 100000)
1098-
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_wal()", 0, NULL, true);
1132+
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_wal()", 0, NULL);
10991133
else
1100-
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_xlog()", 0, NULL, true);
1134+
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_xlog()", 0, NULL);
11011135

11021136
PQclear(res);
11031137
}
@@ -1113,7 +1147,7 @@ pg_ptrack_support(void)
11131147

11141148
res_db = pgut_execute(backup_conn,
11151149
"SELECT proname FROM pg_proc WHERE proname='ptrack_version'",
1116-
0, NULL, true);
1150+
0, NULL);
11171151
if (PQntuples(res_db) == 0)
11181152
{
11191153
PQclear(res_db);
@@ -1123,17 +1157,17 @@ pg_ptrack_support(void)
11231157

11241158
res_db = pgut_execute(backup_conn,
11251159
"SELECT pg_catalog.ptrack_version()",
1126-
0, NULL, true);
1160+
0, NULL);
11271161
if (PQntuples(res_db) == 0)
11281162
{
11291163
PQclear(res_db);
11301164
return false;
11311165
}
11321166

1133-
/* Now we support only ptrack version 1.5 */
1134-
if (strcmp(PQgetvalue(res_db, 0, 0), "1.5") != 0)
1167+
/* Now we support only ptrack versions upper than 1.5 */
1168+
if (strverscmp(PQgetvalue(res_db, 0, 0), "1.5") < 0)
11351169
{
1136-
elog(WARNING, "Update your ptrack to the version 1.5. Current version is %s", PQgetvalue(res_db, 0, 0));
1170+
elog(WARNING, "Update your ptrack to the version 1.5 or upper. Current version is %s", PQgetvalue(res_db, 0, 0));
11371171
PQclear(res_db);
11381172
return false;
11391173
}
@@ -1148,7 +1182,7 @@ pg_ptrack_enable(void)
11481182
{
11491183
PGresult *res_db;
11501184

1151-
res_db = pgut_execute(backup_conn, "show ptrack_enable", 0, NULL, true);
1185+
res_db = pgut_execute(backup_conn, "show ptrack_enable", 0, NULL);
11521186

11531187
if (strcmp(PQgetvalue(res_db, 0, 0), "on") != 0)
11541188
{
@@ -1165,7 +1199,7 @@ pg_checksum_enable(void)
11651199
{
11661200
PGresult *res_db;
11671201

1168-
res_db = pgut_execute(backup_conn, "show data_checksums", 0, NULL, true);
1202+
res_db = pgut_execute(backup_conn, "show data_checksums", 0, NULL);
11691203

11701204
if (strcmp(PQgetvalue(res_db, 0, 0), "on") != 0)
11711205
{
@@ -1182,7 +1216,7 @@ pg_is_in_recovery(void)
11821216
{
11831217
PGresult *res_db;
11841218

1185-
res_db = pgut_execute(backup_conn, "SELECT pg_catalog.pg_is_in_recovery()", 0, NULL, true);
1219+
res_db = pgut_execute(backup_conn, "SELECT pg_catalog.pg_is_in_recovery()", 0, NULL);
11861220

11871221
if (PQgetvalue(res_db, 0, 0)[0] == 't')
11881222
{
@@ -1207,7 +1241,7 @@ pg_ptrack_clear(void)
12071241
params[0] = palloc(64);
12081242
params[1] = palloc(64);
12091243
res_db = pgut_execute(backup_conn, "SELECT datname, oid, dattablespace FROM pg_database",
1210-
0, NULL, true);
1244+
0, NULL);
12111245

12121246
for(i = 0; i < PQntuples(res_db); i++)
12131247
{
@@ -1221,12 +1255,12 @@ pg_ptrack_clear(void)
12211255
tblspcOid = atoi(PQgetvalue(res_db, i, 2));
12221256

12231257
tmp_conn = pgut_connect(dbname);
1224-
res = pgut_execute(tmp_conn, "SELECT pg_catalog.pg_ptrack_clear()", 0, NULL, true);
1258+
res = pgut_execute(tmp_conn, "SELECT pg_catalog.pg_ptrack_clear()", 0, NULL);
12251259

12261260
sprintf(params[0], "%i", dbOid);
12271261
sprintf(params[1], "%i", tblspcOid);
12281262
res = pgut_execute(tmp_conn, "SELECT pg_catalog.pg_ptrack_get_and_clear_db($1, $2)",
1229-
2, (const char **)params, true);
1263+
2, (const char **)params);
12301264
PQclear(res);
12311265

12321266
pgut_disconnect(tmp_conn);
@@ -1252,7 +1286,7 @@ pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid)
12521286
sprintf(params[0], "%i", dbOid);
12531287
res_db = pgut_execute(backup_conn,
12541288
"SELECT datname FROM pg_database WHERE oid=$1",
1255-
1, (const char **) params, true);
1289+
1, (const char **) params);
12561290
/*
12571291
* If database is not found, it's not an error.
12581292
* It could have been deleted since previous backup.
@@ -1273,7 +1307,7 @@ pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid)
12731307
sprintf(params[0], "%i", dbOid);
12741308
sprintf(params[1], "%i", tblspcOid);
12751309
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_ptrack_get_and_clear_db($1, $2)",
1276-
2, (const char **)params, true);
1310+
2, (const char **)params);
12771311

12781312
if (PQnfields(res) != 1)
12791313
elog(ERROR, "cannot perform pg_ptrack_get_and_clear_db()");
@@ -1318,7 +1352,7 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
13181352
sprintf(params[0], "%i", db_oid);
13191353
res_db = pgut_execute(backup_conn,
13201354
"SELECT datname FROM pg_database WHERE oid=$1",
1321-
1, (const char **) params, true);
1355+
1, (const char **) params);
13221356
/*
13231357
* If database is not found, it's not an error.
13241358
* It could have been deleted since previous backup.
@@ -1338,7 +1372,7 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
13381372
sprintf(params[0], "%i", tablespace_oid);
13391373
sprintf(params[1], "%i", rel_filenode);
13401374
res = pgut_execute(tmp_conn, "SELECT pg_catalog.pg_ptrack_get_and_clear($1, $2)",
1341-
2, (const char **)params, true);
1375+
2, (const char **)params);
13421376

13431377
if (PQnfields(res) != 1)
13441378
elog(ERROR, "cannot get ptrack file from database \"%s\" by tablespace oid %u and relation oid %u",
@@ -1356,7 +1390,7 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
13561390
sprintf(params[0], "%i", tablespace_oid);
13571391
sprintf(params[1], "%i", rel_filenode);
13581392
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_ptrack_get_and_clear($1, $2)",
1359-
2, (const char **)params, true);
1393+
2, (const char **)params);
13601394

13611395
if (PQnfields(res) != 1)
13621396
elog(ERROR, "cannot get ptrack file from pg_global tablespace and relation oid %u",
@@ -1537,10 +1571,10 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
15371571
{
15381572
if (server_version >= 100000)
15391573
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_wal_replay_lsn()",
1540-
0, NULL, true);
1574+
0, NULL);
15411575
else
15421576
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_xlog_replay_location()",
1543-
0, NULL, true);
1577+
0, NULL);
15441578
}
15451579
/*
15461580
* For lsn from pg_stop_backup() we need it only to be received by
@@ -1550,10 +1584,10 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
15501584
{
15511585
if (server_version >= 100000)
15521586
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_wal_receive_lsn()",
1553-
0, NULL, true);
1587+
0, NULL);
15541588
else
15551589
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_xlog_receive_location()",
1556-
0, NULL, true);
1590+
0, NULL);
15571591
}
15581592

15591593
/* Extract timeline and LSN from result */
@@ -1620,7 +1654,7 @@ pg_stop_backup(pgBackup *backup)
16201654

16211655
/* Remove annoying NOTICE messages generated by backend */
16221656
res = pgut_execute(conn, "SET client_min_messages = warning;",
1623-
0, NULL, true);
1657+
0, NULL);
16241658
PQclear(res);
16251659

16261660
/* Create restore point */
@@ -1638,7 +1672,7 @@ pg_stop_backup(pgBackup *backup)
16381672
params[0] = name;
16391673

16401674
res = pgut_execute(conn, "SELECT pg_catalog.pg_create_restore_point($1)",
1641-
1, params, true);
1675+
1, params);
16421676
PQclear(res);
16431677
}
16441678

@@ -1901,7 +1935,7 @@ checkpoint_timeout(void)
19011935
const char *hintmsg;
19021936
int val_int;
19031937

1904-
res = pgut_execute(backup_conn, "show checkpoint_timeout", 0, NULL, true);
1938+
res = pgut_execute(backup_conn, "show checkpoint_timeout", 0, NULL);
19051939
val = PQgetvalue(res, 0, 0);
19061940

19071941
if (!parse_int(val, &val_int, OPTION_UNIT_S, &hintmsg))
@@ -2586,7 +2620,7 @@ get_last_ptrack_lsn(void)
25862620
uint32 xrecoff;
25872621
XLogRecPtr lsn;
25882622

2589-
res = pgut_execute(backup_conn, "select pg_catalog.pg_ptrack_control_lsn()", 0, NULL, true);
2623+
res = pgut_execute(backup_conn, "select pg_catalog.pg_ptrack_control_lsn()", 0, NULL);
25902624

25912625
/* Extract timeline and LSN from results of pg_start_backup() */
25922626
XLogDataFromLSN(PQgetvalue(res, 0, 0), &xlogid, &xrecoff);

contrib/pg_probackup/src/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ fetchFile(PGconn *conn, const char *filename, size_t *filesize)
9595
int len;
9696

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

101101
/* sanity check the result set */
102102
if (PQntuples(res) != 1 || PQgetisnull(res, 0, 0))

contrib/pg_probackup/src/parsexlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ validate_wal(pgBackup *backup,
333333
*/
334334
if (backup->stream)
335335
{
336-
sprintf(backup_xlog_path, "/%s/%s/%s/%s",
336+
snprintf(backup_xlog_path, sizeof(backup_xlog_path), "/%s/%s/%s/%s",
337337
backup_instance_path, backup_id, DATABASE_DIR, PG_XLOG_DIR);
338338

339339
validate_backup_wal_from_start_to_stop(backup, backup_xlog_path, tli);

contrib/pg_probackup/src/pg_probackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ main(int argc, char *argv[])
251251
if (argc == 2)
252252
{
253253
#ifdef PGPRO_VERSION
254-
fprintf(stderr, "%s %s (PostgresPro %s %s)\n",
254+
fprintf(stderr, "%s %s (Postgres Pro %s %s)\n",
255255
PROGRAM_NAME, PROGRAM_VERSION,
256256
PGPRO_VERSION, PGPRO_EDITION);
257257
#else

contrib/pg_probackup/src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ get_remote_system_identifier(PGconn *conn)
150150

151151
res = pgut_execute(conn,
152152
"SELECT system_identifier FROM pg_catalog.pg_control_system()",
153-
0, NULL, true);
153+
0, NULL);
154154
val = PQgetvalue(res, 0, 0);
155155
if (!parse_uint64(val, &system_id_conn, 0))
156156
{

contrib/pg_probackup/src/utils/pgut.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,11 +1690,19 @@ pgut_execute_parallel(PGconn* conn,
16901690

16911691
return res;
16921692
}
1693+
1694+
PGresult *
1695+
pgut_execute(PGconn* conn, const char *query, int nParams, const char **params)
1696+
{
1697+
return pgut_execute_extended(conn, query, nParams, params, true, false);
1698+
}
1699+
16931700
PGresult *
1694-
pgut_execute(PGconn* conn, const char *query, int nParams, const char **params,
1695-
bool text_result)
1701+
pgut_execute_extended(PGconn* conn, const char *query, int nParams,
1702+
const char **params, bool text_result, bool ok_error)
16961703
{
16971704
PGresult *res;
1705+
ExecStatusType res_status;
16981706

16991707
if (interrupted && !in_cleanup)
17001708
elog(ERROR, "interrupted");
@@ -1730,13 +1738,17 @@ pgut_execute(PGconn* conn, const char *query, int nParams, const char **params,
17301738
(text_result) ? 0 : 1);
17311739
on_after_exec(NULL);
17321740

1733-
switch (PQresultStatus(res))
1741+
res_status = PQresultStatus(res);
1742+
switch (res_status)
17341743
{
17351744
case PGRES_TUPLES_OK:
17361745
case PGRES_COMMAND_OK:
17371746
case PGRES_COPY_IN:
17381747
break;
17391748
default:
1749+
if (ok_error && res_status == PGRES_FATAL_ERROR)
1750+
break;
1751+
17401752
elog(ERROR, "query failed: %squery was: %s",
17411753
PQerrorMessage(conn), query);
17421754
break;

contrib/pg_probackup/src/utils/pgut.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ extern PGconn *pgut_connect_replication_extended(const char *pghost, const char
135135
const char *dbname, const char *pguser);
136136
extern void pgut_disconnect(PGconn *conn);
137137
extern PGresult *pgut_execute(PGconn* conn, const char *query, int nParams,
138-
const char **params, bool text_result);
138+
const char **params);
139+
extern PGresult *pgut_execute_extended(PGconn* conn, const char *query, int nParams,
140+
const char **params, bool text_result, bool ok_error);
139141
extern PGresult *pgut_execute_parallel(PGconn* conn, PGcancel* thread_cancel_conn,
140142
const char *query, int nParams,
141143
const char **params, bool text_result);

0 commit comments

Comments
 (0)