-
Notifications
You must be signed in to change notification settings - Fork 176
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
Handling system tables errors #327
Open
chanukya571
wants to merge
17
commits into
reorg:master
Choose a base branch
from
adjust:handling-system-tables-errors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fed2faf
allow build with PostgreSQL 12
Melkij 32d32e5
PostgreSQL 12 has no more OIDS support for user tables. relhasoids wa…
Melkij 6732338
simplify relhasoids with replace from Makefile
Melkij 91fe63e
tablespace test varian with qualified table name and without "TABLESP…
Melkij 9e68b06
support for PostgreSQL 12: documentation changes, adding PG 12 to tra…
Melkij 1cb05a1
Ubuntu trusty is EOL, try move to bionic 18.04 release
Melkij c3e3a79
try travis on xenial with all supported versions
Melkij d52c633
yet another try to make travis works
Melkij 58614f1
one missed sudo, yet another try
Melkij ee5f24a
Merge branch 'master' of https://github.com/reorg/pg_repack into reor…
za-arthur 9aa8b69
Merge branch 'reorg-master'
za-arthur 7513317
Take ACCESS EXCLUSIVE LOCK carefully (#8)
za-arthur 95dd7fc
Raise ERROR message during repack_drop() (#9)
za-arthur 0b2ecf7
Merge upstream (#10)
za-arthur 254ba8b
Merge remote-tracking branch 'reorg/master'
za-arthur e463b81
error messages for system tables to use VACUUM FULL.
chanukya571 2fb3261
code alignment
chanukya571 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -211,6 +211,7 @@ typedef struct repack_table | |
|
||
static bool is_superuser(void); | ||
static void check_tablespace(void); | ||
static bool check_systemtables(void); | ||
static bool preliminary_checks(char *errbuf, size_t errsize); | ||
static bool is_requested_relation_exists(char *errbuf, size_t errsize); | ||
static void repack_all_databases(const char *order_by); | ||
|
@@ -421,6 +422,47 @@ is_superuser(void) | |
return false; | ||
} | ||
|
||
bool | ||
check_systemtables() | ||
|
||
{ | ||
PGresult *query_result = NULL; | ||
int num; | ||
SimpleStringListCell *cell; | ||
StringInfoData sql; | ||
int iparam = 0; | ||
|
||
num = simple_string_list_size(table_list); | ||
|
||
initStringInfo(&sql); | ||
|
||
appendStringInfoString(&sql, "select 1 from pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace where n.nspname IN ('pg_catalog','information_schema') AND c.oid IN ("); | ||
|
||
for (cell = table_list.head; cell; cell = cell->next) | ||
{ | ||
appendStringInfo(&sql, "'%s'::regclass::oid", cell->val); | ||
iparam++; | ||
if (iparam < num) | ||
appendStringInfoChar(&sql, ','); | ||
} | ||
|
||
appendStringInfoString(&sql,")"); | ||
|
||
query_result = execute_elevel(sql.data,0,NULL, DEBUG2); | ||
|
||
if (PQresultStatus(query_result) == PGRES_TUPLES_OK) | ||
{ | ||
if (PQntuples(query_result) >= 1) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
CLEARPGRES(query_result); | ||
|
||
return false; | ||
} | ||
|
||
/* | ||
* Check if the tablespace requested exists. | ||
* | ||
|
@@ -487,6 +529,12 @@ preliminary_checks(char *errbuf, size_t errsize){ | |
goto cleanup; | ||
} | ||
|
||
if (check_systemtables()) { | ||
if (errbuf) | ||
snprintf(errbuf, errsize, "For System Tables Use VACUUM FULL."); | ||
goto cleanup; | ||
} | ||
|
||
/* Query the extension version. Exit if no match */ | ||
res = execute_elevel("select repack.version(), repack.version_sql()", | ||
0, NULL, DEBUG2); | ||
|
@@ -1276,7 +1324,7 @@ repack_one_table(repack_table *table, const char *orderby) | |
return; | ||
|
||
/* push repack_cleanup_callback() on stack to clean temporary objects */ | ||
pgut_atexit_push(repack_cleanup_callback, &table->target_oid); | ||
pgut_atexit_push(repack_cleanup_callback, table); | ||
|
||
/* | ||
* 1. Setup advisory lock and trigger on main table. | ||
|
@@ -1966,7 +2014,8 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta | |
void | ||
repack_cleanup_callback(bool fatal, void *userdata) | ||
{ | ||
Oid target_table = *(Oid *) userdata; | ||
repack_table *table = (repack_table *) userdata; | ||
Oid target_table = table->target_oid; | ||
const char *params[2]; | ||
char buffer[12]; | ||
char num_buff[12]; | ||
|
@@ -1981,7 +2030,16 @@ repack_cleanup_callback(bool fatal, void *userdata) | |
* so just use an unconditional reconnect(). | ||
*/ | ||
reconnect(ERROR); | ||
|
||
command("BEGIN ISOLATION LEVEL READ COMMITTED", 0, NULL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you included non-relevant changes. Can you remove them? |
||
if (!(lock_exclusive(connection, params[0], table->lock_table, false))) | ||
{ | ||
elog(ERROR, "lock_exclusive() failed in connection for %s during cleanup callback", | ||
table->target_name); | ||
} | ||
|
||
command("SELECT repack.repack_drop($1, $2)", 2, params); | ||
command("COMMIT", 0, NULL); | ||
temp_obj_num = 0; /* reset temporary object counter after cleanup */ | ||
} | ||
} | ||
|
@@ -2011,7 +2069,16 @@ repack_cleanup(bool fatal, const repack_table *table) | |
/* do cleanup */ | ||
params[0] = utoa(table->target_oid, buffer); | ||
params[1] = utoa(temp_obj_num, num_buff); | ||
|
||
command("BEGIN ISOLATION LEVEL READ COMMITTED", 0, NULL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. This looks like a non-relevant change. |
||
if (!(lock_exclusive(connection, params[0], table->lock_table, false))) | ||
{ | ||
elog(ERROR, "lock_exclusive() failed in connection for %s during cleanup", | ||
table->target_name); | ||
} | ||
|
||
command("SELECT repack.repack_drop($1, $2)", 2, params); | ||
command("COMMIT", 0, NULL); | ||
temp_obj_num = 0; /* reset temporary object counter after cleanup */ | ||
} | ||
} | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would make sense to make this check inside
repack_one_table
andrepack_table_indexes
only? That way this check won't interrupt pg_repack completely, and it will skip only system tables.