@@ -547,7 +547,8 @@ do_backup_instance(void)
547
547
548
548
/* notify start of backup to PostgreSQL server */
549
549
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" ));
551
552
pg_start_backup (label , smooth_checkpoint , & current );
552
553
553
554
pgBackupGetPath (& current , database_path , lengthof (database_path ),
@@ -934,6 +935,8 @@ do_backup(time_t start_time)
934
935
static void
935
936
check_server_version (void )
936
937
{
938
+ PGresult * res ;
939
+
937
940
/* confirm server version */
938
941
server_version = PQserverVersion (backup_conn );
939
942
@@ -958,6 +961,39 @@ check_server_version(void)
958
961
"server version is %s, must be %s or higher for backup from replica" ,
959
962
server_version_str , "9.6" );
960
963
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
+
961
997
/* Do exclusive backup only for PostgreSQL 9.5 */
962
998
exclusive_backup = server_version < 90600 ||
963
999
current .backup_mode == BACKUP_MODE_DIFF_PTRACK ;
@@ -997,7 +1033,7 @@ confirm_block_size(const char *name, int blcksz)
997
1033
char * endp ;
998
1034
int block_size ;
999
1035
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 );
1001
1037
if (PQntuples (res ) != 1 || PQnfields (res ) != 1 )
1002
1038
elog (ERROR , "cannot get %s: %s" , name , PQerrorMessage (backup_conn ));
1003
1039
@@ -1033,14 +1069,12 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
1033
1069
res = pgut_execute (conn ,
1034
1070
"SELECT pg_catalog.pg_start_backup($1, $2, false)" ,
1035
1071
2 ,
1036
- params ,
1037
- true);
1072
+ params );
1038
1073
else
1039
1074
res = pgut_execute (conn ,
1040
1075
"SELECT pg_catalog.pg_start_backup($1, $2)" ,
1041
1076
2 ,
1042
- params ,
1043
- true);
1077
+ params );
1044
1078
1045
1079
/* Extract timeline and LSN from results of pg_start_backup() */
1046
1080
XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & xlogid , & xrecoff );
@@ -1091,13 +1125,13 @@ pg_switch_wal(PGconn *conn)
1091
1125
PGresult * res ;
1092
1126
1093
1127
/* 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 );
1095
1129
PQclear (res );
1096
1130
1097
1131
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 );
1099
1133
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 );
1101
1135
1102
1136
PQclear (res );
1103
1137
}
@@ -1113,7 +1147,7 @@ pg_ptrack_support(void)
1113
1147
1114
1148
res_db = pgut_execute (backup_conn ,
1115
1149
"SELECT proname FROM pg_proc WHERE proname='ptrack_version'" ,
1116
- 0 , NULL , true );
1150
+ 0 , NULL );
1117
1151
if (PQntuples (res_db ) == 0 )
1118
1152
{
1119
1153
PQclear (res_db );
@@ -1123,17 +1157,17 @@ pg_ptrack_support(void)
1123
1157
1124
1158
res_db = pgut_execute (backup_conn ,
1125
1159
"SELECT pg_catalog.ptrack_version()" ,
1126
- 0 , NULL , true );
1160
+ 0 , NULL );
1127
1161
if (PQntuples (res_db ) == 0 )
1128
1162
{
1129
1163
PQclear (res_db );
1130
1164
return false;
1131
1165
}
1132
1166
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 )
1135
1169
{
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 ));
1137
1171
PQclear (res_db );
1138
1172
return false;
1139
1173
}
@@ -1148,7 +1182,7 @@ pg_ptrack_enable(void)
1148
1182
{
1149
1183
PGresult * res_db ;
1150
1184
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 );
1152
1186
1153
1187
if (strcmp (PQgetvalue (res_db , 0 , 0 ), "on" ) != 0 )
1154
1188
{
@@ -1165,7 +1199,7 @@ pg_checksum_enable(void)
1165
1199
{
1166
1200
PGresult * res_db ;
1167
1201
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 );
1169
1203
1170
1204
if (strcmp (PQgetvalue (res_db , 0 , 0 ), "on" ) != 0 )
1171
1205
{
@@ -1182,7 +1216,7 @@ pg_is_in_recovery(void)
1182
1216
{
1183
1217
PGresult * res_db ;
1184
1218
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 );
1186
1220
1187
1221
if (PQgetvalue (res_db , 0 , 0 )[0 ] == 't' )
1188
1222
{
@@ -1207,7 +1241,7 @@ pg_ptrack_clear(void)
1207
1241
params [0 ] = palloc (64 );
1208
1242
params [1 ] = palloc (64 );
1209
1243
res_db = pgut_execute (backup_conn , "SELECT datname, oid, dattablespace FROM pg_database" ,
1210
- 0 , NULL , true );
1244
+ 0 , NULL );
1211
1245
1212
1246
for (i = 0 ; i < PQntuples (res_db ); i ++ )
1213
1247
{
@@ -1221,12 +1255,12 @@ pg_ptrack_clear(void)
1221
1255
tblspcOid = atoi (PQgetvalue (res_db , i , 2 ));
1222
1256
1223
1257
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 );
1225
1259
1226
1260
sprintf (params [0 ], "%i" , dbOid );
1227
1261
sprintf (params [1 ], "%i" , tblspcOid );
1228
1262
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 );
1230
1264
PQclear (res );
1231
1265
1232
1266
pgut_disconnect (tmp_conn );
@@ -1252,7 +1286,7 @@ pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid)
1252
1286
sprintf (params [0 ], "%i" , dbOid );
1253
1287
res_db = pgut_execute (backup_conn ,
1254
1288
"SELECT datname FROM pg_database WHERE oid=$1" ,
1255
- 1 , (const char * * ) params , true );
1289
+ 1 , (const char * * ) params );
1256
1290
/*
1257
1291
* If database is not found, it's not an error.
1258
1292
* It could have been deleted since previous backup.
@@ -1273,7 +1307,7 @@ pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid)
1273
1307
sprintf (params [0 ], "%i" , dbOid );
1274
1308
sprintf (params [1 ], "%i" , tblspcOid );
1275
1309
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 );
1277
1311
1278
1312
if (PQnfields (res ) != 1 )
1279
1313
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,
1318
1352
sprintf (params [0 ], "%i" , db_oid );
1319
1353
res_db = pgut_execute (backup_conn ,
1320
1354
"SELECT datname FROM pg_database WHERE oid=$1" ,
1321
- 1 , (const char * * ) params , true );
1355
+ 1 , (const char * * ) params );
1322
1356
/*
1323
1357
* If database is not found, it's not an error.
1324
1358
* 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,
1338
1372
sprintf (params [0 ], "%i" , tablespace_oid );
1339
1373
sprintf (params [1 ], "%i" , rel_filenode );
1340
1374
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 );
1342
1376
1343
1377
if (PQnfields (res ) != 1 )
1344
1378
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,
1356
1390
sprintf (params [0 ], "%i" , tablespace_oid );
1357
1391
sprintf (params [1 ], "%i" , rel_filenode );
1358
1392
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 );
1360
1394
1361
1395
if (PQnfields (res ) != 1 )
1362
1396
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)
1537
1571
{
1538
1572
if (server_version >= 100000 )
1539
1573
res = pgut_execute (backup_conn , "SELECT pg_catalog.pg_last_wal_replay_lsn()" ,
1540
- 0 , NULL , true );
1574
+ 0 , NULL );
1541
1575
else
1542
1576
res = pgut_execute (backup_conn , "SELECT pg_catalog.pg_last_xlog_replay_location()" ,
1543
- 0 , NULL , true );
1577
+ 0 , NULL );
1544
1578
}
1545
1579
/*
1546
1580
* 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)
1550
1584
{
1551
1585
if (server_version >= 100000 )
1552
1586
res = pgut_execute (backup_conn , "SELECT pg_catalog.pg_last_wal_receive_lsn()" ,
1553
- 0 , NULL , true );
1587
+ 0 , NULL );
1554
1588
else
1555
1589
res = pgut_execute (backup_conn , "SELECT pg_catalog.pg_last_xlog_receive_location()" ,
1556
- 0 , NULL , true );
1590
+ 0 , NULL );
1557
1591
}
1558
1592
1559
1593
/* Extract timeline and LSN from result */
@@ -1620,7 +1654,7 @@ pg_stop_backup(pgBackup *backup)
1620
1654
1621
1655
/* Remove annoying NOTICE messages generated by backend */
1622
1656
res = pgut_execute (conn , "SET client_min_messages = warning;" ,
1623
- 0 , NULL , true );
1657
+ 0 , NULL );
1624
1658
PQclear (res );
1625
1659
1626
1660
/* Create restore point */
@@ -1638,7 +1672,7 @@ pg_stop_backup(pgBackup *backup)
1638
1672
params [0 ] = name ;
1639
1673
1640
1674
res = pgut_execute (conn , "SELECT pg_catalog.pg_create_restore_point($1)" ,
1641
- 1 , params , true );
1675
+ 1 , params );
1642
1676
PQclear (res );
1643
1677
}
1644
1678
@@ -1901,7 +1935,7 @@ checkpoint_timeout(void)
1901
1935
const char * hintmsg ;
1902
1936
int val_int ;
1903
1937
1904
- res = pgut_execute (backup_conn , "show checkpoint_timeout" , 0 , NULL , true );
1938
+ res = pgut_execute (backup_conn , "show checkpoint_timeout" , 0 , NULL );
1905
1939
val = PQgetvalue (res , 0 , 0 );
1906
1940
1907
1941
if (!parse_int (val , & val_int , OPTION_UNIT_S , & hintmsg ))
@@ -2586,7 +2620,7 @@ get_last_ptrack_lsn(void)
2586
2620
uint32 xrecoff ;
2587
2621
XLogRecPtr lsn ;
2588
2622
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 );
2590
2624
2591
2625
/* Extract timeline and LSN from results of pg_start_backup() */
2592
2626
XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & xlogid , & xrecoff );
0 commit comments