@@ -74,6 +74,7 @@ static int is_ptrack_enable = false;
74
74
bool is_ptrack_support = false;
75
75
bool is_checksum_enabled = false;
76
76
bool exclusive_backup = false;
77
+ bool heapallindexed_is_supported = false;
77
78
78
79
/* Backup connections */
79
80
static PGconn * backup_conn = NULL ;
@@ -1044,6 +1045,7 @@ do_amcheck(void)
1044
1045
int n_databases = 0 ;
1045
1046
bool first_db_with_amcheck = true;
1046
1047
PGconn * db_conn = NULL ;
1048
+ bool db_skipped = false;
1047
1049
1048
1050
pgBackupGetPath (& current , database_path , lengthof (database_path ),
1049
1051
DATABASE_DIR );
@@ -1076,6 +1078,7 @@ do_amcheck(void)
1076
1078
{
1077
1079
if (db_conn )
1078
1080
pgut_disconnect (db_conn );
1081
+ db_skipped = true;
1079
1082
continue ;
1080
1083
}
1081
1084
@@ -1125,17 +1128,14 @@ do_amcheck(void)
1125
1128
}
1126
1129
1127
1130
/* TODO write better info message */
1128
- if (check_isok )
1131
+ if (check_isok && ! db_skipped )
1129
1132
elog (INFO , "Indexes are valid" );
1130
- else
1133
+
1134
+ if (!check_isok )
1131
1135
elog (ERROR , "Some indexes are corrupted" );
1132
1136
1133
- //if (backup_files_list)
1134
- //{
1135
- // parray_walk(backup_files_list, pgFileFree);
1136
- // parray_free(backup_files_list);
1137
- // backup_files_list = NULL;
1138
- //}
1137
+ if (db_skipped )
1138
+ elog (ERROR , "Some databases were not checked" );
1139
1139
}
1140
1140
1141
1141
/* Entry point of pg_probackup CHECKDB subcommand. */
@@ -1156,6 +1156,7 @@ do_checkdb(bool need_amcheck)
1156
1156
if (need_amcheck )
1157
1157
do_amcheck ();
1158
1158
1159
+ /* need to exit with 1 if some corruption is found */
1159
1160
return 0 ;
1160
1161
}
1161
1162
@@ -3487,12 +3488,16 @@ get_index_list(PGresult *res_db, int db_number,
3487
3488
dbname ,
3488
3489
instance_config .pguser );
3489
3490
3490
- res = pgut_execute (db_conn , "SELECT extname, nspname, extversion "
3491
+ res = pgut_execute (db_conn , "SELECT "
3492
+ "extname, nspname, extversion, "
3493
+ "extversion::numeric in (1.1, 1) as old_version "
3491
3494
"FROM pg_namespace n "
3492
3495
"JOIN pg_extension e "
3493
3496
"ON n.oid=e.extnamespace "
3494
- "WHERE e.extname='amcheck'" ,
3495
- 0 , NULL );
3497
+ "WHERE e.extname IN ('amcheck', 'amcheck_next') "
3498
+ "ORDER BY extversion DESC "
3499
+ "LIMIT 1" ,
3500
+ 0 , NULL );
3496
3501
3497
3502
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
3498
3503
{
@@ -3503,13 +3508,21 @@ get_index_list(PGresult *res_db, int db_number,
3503
3508
3504
3509
if (PQntuples (res ) < 1 )
3505
3510
{
3506
- elog (WARNING , "Extension amcheck is not installed in database %s" , dbname );
3511
+ elog (WARNING , "Extension ' amcheck' or 'amcheck_next' are not installed in database %s" , dbname );
3507
3512
return NULL ;
3508
3513
}
3509
3514
3510
3515
nspname = pgut_malloc (strlen (PQgetvalue (res , 0 , 1 )) + 1 );
3511
3516
strcpy (nspname , PQgetvalue (res , 0 , 1 ));
3512
3517
3518
+ /* heapallindexed_is_supported is database specific */
3519
+ if (strcmp (PQgetvalue (res , 0 , 2 ), "1.0" ) != 0 &&
3520
+ strcmp (PQgetvalue (res , 0 , 2 ), "1" ) != 0 )
3521
+ heapallindexed_is_supported = true;
3522
+
3523
+ elog (INFO , "Checking database %s using module '%s' version %s from schema '%s'" ,
3524
+ dbname , PQgetvalue (res , 0 , 0 ), PQgetvalue (res , 0 , 2 ), PQgetvalue (res , 0 , 1 ));
3525
+
3513
3526
/*
3514
3527
* In order to avoid duplicates, select global indexes
3515
3528
* (tablespace pg_global with oid 1664) only once
@@ -3566,8 +3579,6 @@ get_index_list(PGresult *res_db, int db_number,
3566
3579
3567
3580
PQclear (res );
3568
3581
3569
- elog (INFO , "Amcheck database '%s'" , dbname );
3570
-
3571
3582
return index_list ;
3572
3583
}
3573
3584
@@ -3577,18 +3588,34 @@ amcheck_one_index(backup_files_arg *arguments,
3577
3588
pg_indexEntry * ind )
3578
3589
{
3579
3590
PGresult * res ;
3580
- char * params [1 ];
3581
- char * query ;
3591
+ char * params [2 ];
3592
+ char * query = NULL ;
3593
+
3582
3594
params [0 ] = palloc (64 );
3583
3595
3596
+ /* first argument is index oid */
3584
3597
sprintf (params [0 ], "%i" , ind -> indexrelid );
3598
+ /* second argument is heapallindexed */
3599
+ params [1 ] = heapallindexed ? "true" : "false" ;
3585
3600
3586
- query = palloc (strlen (ind -> amcheck_nspname )+ strlen ("SELECT .bt_index_check($1)" )+ 1 );
3587
- sprintf (query , "SELECT %s.bt_index_check($1)" , ind -> amcheck_nspname );
3601
+ if (heapallindexed_is_supported )
3602
+ {
3603
+ query = palloc (strlen (ind -> amcheck_nspname )+ strlen ("SELECT .bt_index_check($1, $2)" )+ 1 );
3604
+ sprintf (query , "SELECT %s.bt_index_check($1, $2)" , ind -> amcheck_nspname );
3588
3605
3589
- res = pgut_execute_parallel (arguments -> backup_conn ,
3606
+ res = pgut_execute_parallel (arguments -> backup_conn ,
3607
+ arguments -> cancel_conn ,
3608
+ query , 2 , (const char * * )params , true, true);
3609
+ }
3610
+ else
3611
+ {
3612
+ query = palloc (strlen (ind -> amcheck_nspname )+ strlen ("SELECT .bt_index_check($1)" )+ 1 );
3613
+ sprintf (query , "SELECT %s.bt_index_check($1)" , ind -> amcheck_nspname );
3614
+
3615
+ res = pgut_execute_parallel (arguments -> backup_conn ,
3590
3616
arguments -> cancel_conn ,
3591
3617
query , 1 , (const char * * )params , true, true);
3618
+ }
3592
3619
3593
3620
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
3594
3621
{
0 commit comments