From e463b81d488af91a4ef58625a8ada415a4e0e7c8 Mon Sep 17 00:00:00 2001 From: Dhatta Sai Chanuka Sista <113626707+chanukya571@users.noreply.github.com> Date: Tue, 20 Dec 2022 14:51:02 +0100 Subject: [PATCH 1/2] error messages for system tables to use VACUUM FULL. --- bin/pg_repack.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 377d3e49..74289b7a 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -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,51 @@ 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 +533,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); From 2fb32615efd2df5a256a7a2cfb54db2f899949c9 Mon Sep 17 00:00:00 2001 From: Dhatta Sai Chanuka Sista <113626707+chanukya571@users.noreply.github.com> Date: Tue, 20 Dec 2022 14:56:47 +0100 Subject: [PATCH 2/2] code alignment --- bin/pg_repack.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 74289b7a..bed8427d 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -426,12 +426,11 @@ bool check_systemtables() { - PGresult *query_result = NULL; - int num; - SimpleStringListCell *cell; - StringInfoData sql; - int iparam = 0; - + PGresult *query_result = NULL; + int num; + SimpleStringListCell *cell; + StringInfoData sql; + int iparam = 0; num = simple_string_list_size(table_list); @@ -439,7 +438,6 @@ check_systemtables() 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); @@ -450,17 +448,15 @@ check_systemtables() appendStringInfoString(&sql,")"); - query_result = execute_elevel(sql.data,0,NULL, DEBUG2); if (PQresultStatus(query_result) == PGRES_TUPLES_OK) + { + if (PQntuples(query_result) >= 1) { - - if (PQntuples(query_result) >= 1) - { - return true; - } + return true; } + } CLEARPGRES(query_result);