- Notifications
You must be signed in to change notification settings - Fork86
[PGPRO-5612] Support for checkunique parameter of amcheck.bt_index_ch…#456
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
6fa0c47
[PGPRO-5612] Support for checkunique parameter of amcheck.bt_index_ch…
kulaginm5c4f1ea
[PGPRO-5612] ugly fix at the request of the reviewer
kulaginm87e3d5e
[PGPRO-5612] add --amcheck consistency checking
kulaginmc7bf7cd
[DOC] [PGPRO-5612] Added description of --checkunique option of proba…
indrups4762fe2
[PGPRO-5612] [ci skip] revert .travis.yml
kulaginmFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
35 changes: 27 additions & 8 deletionsdoc/pgprobackup.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
124 changes: 93 additions & 31 deletionssrc/checkdb.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -83,6 +83,7 @@ typedef struct pg_indexEntry | ||
char *name; | ||
char *namespace; | ||
bool heapallindexed_is_supported; | ||
bool checkunique_is_supported; | ||
/* schema where amcheck extension is located */ | ||
char *amcheck_nspname; | ||
/* lock for synchronization of parallel threads */ | ||
@@ -351,10 +352,14 @@ get_index_list(const char *dbname, bool first_db_with_amcheck, | ||
{ | ||
PGresult *res; | ||
char *amcheck_nspname = NULL; | ||
char *amcheck_extname = NULL; | ||
char *amcheck_extversion = NULL; | ||
int i; | ||
bool heapallindexed_is_supported = false; | ||
bool checkunique_is_supported = false; | ||
parray *index_list = NULL; | ||
/* Check amcheck extension version */ | ||
res = pgut_execute(db_conn, "SELECT " | ||
"extname, nspname, extversion " | ||
"FROM pg_catalog.pg_namespace n " | ||
@@ -379,24 +384,68 @@ get_index_list(const char *dbname, bool first_db_with_amcheck, | ||
return NULL; | ||
} | ||
amcheck_extname = pgut_malloc(strlen(PQgetvalue(res, 0, 0)) + 1); | ||
daniel-95 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
strcpy(amcheck_extname, PQgetvalue(res, 0, 0)); | ||
amcheck_nspname = pgut_malloc(strlen(PQgetvalue(res, 0, 1)) + 1); | ||
strcpy(amcheck_nspname, PQgetvalue(res, 0, 1)); | ||
amcheck_extversion = pgut_malloc(strlen(PQgetvalue(res, 0, 2)) + 1); | ||
strcpy(amcheck_extversion, PQgetvalue(res, 0, 2)); | ||
PQclear(res); | ||
/* heapallindexed_is_supported is database specific */ | ||
/* TODO this is wrong check, heapallindexed supported also in 1.1.1, 1.2 and 1.2.1... */ | ||
if (strcmp(amcheck_extversion, "1.0") != 0 && | ||
strcmp(amcheck_extversion, "1") != 0) | ||
heapallindexed_is_supported = true; | ||
elog(INFO, "Amchecking database '%s' using extension '%s' " | ||
"version %s from schema '%s'", | ||
dbname,amcheck_extname, | ||
amcheck_extversion, amcheck_nspname); | ||
if (!heapallindexed_is_supported && heapallindexed) | ||
elog(WARNING, "Extension '%s' version %s in schema '%s'" | ||
"do not support 'heapallindexed' option", | ||
amcheck_extname, amcheck_extversion, | ||
amcheck_nspname); | ||
#ifndef PGPRO_EE | ||
/* | ||
* Will support when the vanilla patch will commited https://commitfest.postgresql.org/32/2976/ | ||
*/ | ||
checkunique_is_supported = false; | ||
#else | ||
/* | ||
* Check bt_index_check function signature to determine support of checkunique parameter | ||
* This can't be exactly checked by checking extension version, | ||
* For example, 1.1.1 and 1.2.1 supports this parameter, but 1.2 doesn't (PGPROEE-12.4.1) | ||
*/ | ||
res = pgut_execute(db_conn, "SELECT " | ||
" oid " | ||
"FROM pg_catalog.pg_proc " | ||
"WHERE " | ||
" pronamespace = $1::regnamespace " | ||
"AND proname = 'bt_index_check' " | ||
"AND 'checkunique' = ANY(proargnames) " | ||
"AND (pg_catalog.string_to_array(proargtypes::text, ' ')::regtype[])[pg_catalog.array_position(proargnames, 'checkunique')] = 'bool'::regtype", | ||
1, (const char **) &amcheck_nspname); | ||
if (PQresultStatus(res) != PGRES_TUPLES_OK) | ||
{ | ||
PQclear(res); | ||
elog(ERROR, "Cannot check 'checkunique' option is supported in bt_index_check function %s: %s", | ||
dbname, PQerrorMessage(db_conn)); | ||
} | ||
checkunique_is_supported = PQntuples(res) >= 1; | ||
PQclear(res); | ||
#endif | ||
if (!checkunique_is_supported && checkunique) | ||
elog(WARNING, "Extension '%s' version %s in schema '%s' " | ||
"do not support 'checkunique' parameter", | ||
amcheck_extname, amcheck_extversion, | ||
amcheck_nspname); | ||
/* | ||
* In order to avoid duplicates, select global indexes | ||
@@ -453,6 +502,7 @@ get_index_list(const char *dbname, bool first_db_with_amcheck, | ||
strcpy(ind->namespace, namespace);/* enough buffer size guaranteed */ | ||
ind->heapallindexed_is_supported = heapallindexed_is_supported; | ||
ind->checkunique_is_supported = checkunique_is_supported; | ||
ind->amcheck_nspname = pgut_malloc(strlen(amcheck_nspname) + 1); | ||
strcpy(ind->amcheck_nspname, amcheck_nspname); | ||
pg_atomic_clear_flag(&ind->lock); | ||
@@ -464,6 +514,9 @@ get_index_list(const char *dbname, bool first_db_with_amcheck, | ||
} | ||
PQclear(res); | ||
free(amcheck_extversion); | ||
free(amcheck_nspname); | ||
free(amcheck_extname); | ||
return index_list; | ||
} | ||
@@ -473,46 +526,54 @@ static bool | ||
amcheck_one_index(check_indexes_arg *arguments, | ||
pg_indexEntry *ind) | ||
{ | ||
PGresult*res; | ||
char*params[3]; | ||
static const char*queries[] = { | ||
"SELECT %s.bt_index_check(index => $1)", | ||
"SELECT %s.bt_index_check(index => $1, heapallindexed => $2)", | ||
"SELECT %s.bt_index_check(index => $1, heapallindexed => $2, checkunique => $3)", | ||
}; | ||
intparams_count; | ||
char*query = NULL; | ||
if (interrupted) | ||
elog(ERROR, "Interrupted"); | ||
#define INDEXRELID 0 | ||
#define HEAPALLINDEXED 1 | ||
#define CHECKUNIQUE 2 | ||
/* first argument is index oid */ | ||
params[INDEXRELID] = palloc(64); | ||
sprintf(params[INDEXRELID], "%u", ind->indexrelid); | ||
/* second argument is heapallindexed */ | ||
params[HEAPALLINDEXED] = heapallindexed ? "true" : "false"; | ||
/* third optional argument is checkunique */ | ||
params[CHECKUNIQUE] = checkunique ? "true" : "false"; | ||
#undef CHECKUNIQUE | ||
#undef HEAPALLINDEXED | ||
params_count = ind->checkunique_is_supported ? | ||
3 : | ||
( ind->heapallindexed_is_supported ? 2 : 1 ); | ||
/* | ||
* Prepare query text with schema name | ||
* +1 for \0 and -2 for %s | ||
*/ | ||
query = palloc(strlen(ind->amcheck_nspname) + strlen(queries[params_count - 1]) + 1 - 2); | ||
daniel-95 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
sprintf(query, queries[params_count - 1], ind->amcheck_nspname); | ||
res = pgut_execute_parallel(arguments->conn_arg.conn, | ||
arguments->conn_arg.cancel_conn, | ||
query, params_count, (const char **)params, true, true, true); | ||
if (PQresultStatus(res) != PGRES_TUPLES_OK) | ||
{ | ||
elog(WARNING, "Thread [%d]. Amcheck failed in database '%s' for index: '%s.%s': %s", | ||
arguments->thread_num, arguments->conn_opt.pgdatabase, | ||
ind->namespace, ind->name, PQresultErrorMessage(res)); | ||
pfree(params[INDEXRELID]); | ||
pfree(query); | ||
PQclear(res); | ||
return false; | ||
@@ -522,7 +583,8 @@ amcheck_one_index(check_indexes_arg *arguments, | ||
arguments->thread_num, | ||
arguments->conn_opt.pgdatabase, ind->namespace, ind->name); | ||
pfree(params[INDEXRELID]); | ||
#undef INDEXRELID | ||
pfree(query); | ||
PQclear(res); | ||
return true; | ||
6 changes: 4 additions & 2 deletionssrc/help.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletionssrc/pg_probackup.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssrc/pg_probackup.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.