diff --git a/bin/pg_repack.c b/bin/pg_repack.c index f266539..2ca5567 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -219,6 +219,7 @@ static bool analyze = true; static bool alldb = false; static bool noorder = false; static SimpleStringList table_list = {NULL, NULL}; +static SimpleStringList schema_list = {NULL, NULL}; static char *orderby = NULL; static char *tablespace = NULL; static bool moveidx = false; @@ -239,6 +240,7 @@ static pgut_option options[] = { { 'b', 'a', "all", &alldb }, { 'l', 't', "table", &table_list }, + { 'l', 'c', "schema", &schema_list }, { 'b', 'n', "no-order", &noorder }, { 's', 'o', "order-by", &orderby }, { 's', 's', "tablespace", &tablespace }, @@ -312,6 +314,10 @@ main(int argc, char *argv[]) ereport(ERROR, (errcode(EINVAL), errmsg("cannot repack specific table(s) in all databases"))); + if (schema_list.head) + ereport(ERROR, + (errcode(EINVAL), + errmsg("cannot repack specific schema(s) in all databases"))); repack_all_databases(orderby); } else @@ -555,12 +561,14 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) const char **params = NULL; int iparam = 0; size_t num_tables; + size_t num_schemas; size_t num_params; num_tables = simple_string_list_size(table_list); + num_schemas = simple_string_list_size(schema_list); /* 1st param is the user-specified tablespace */ - num_params = num_tables + 1; + num_params = num_tables + num_schemas + 1; params = pgut_malloc(num_params * sizeof(char *)); initStringInfo(&sql); @@ -596,6 +604,19 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) } appendStringInfoString(&sql, ")"); } + else if (num_schemas) + { + appendStringInfoString(&sql, "schemaname IN ("); + for (cell = schema_list.head; cell; cell = cell->next) + { + /* Construct schema name placeholders to be used by PQexecParams */ + appendStringInfo(&sql, "$%d", iparam + 1); + params[iparam++] = cell->val; + if (cell->next) + appendStringInfoString(&sql, ", "); + } + appendStringInfoString(&sql, ")"); + } else { appendStringInfoString(&sql, "pkid IS NOT NULL"); @@ -1895,6 +1916,7 @@ pgut_help(bool details) printf("Options:\n"); printf(" -a, --all repack all databases\n"); printf(" -t, --table=TABLE repack specific table only\n"); + printf(" -c, --schema=SCHEMA repack specific schema only\n"); printf(" -s, --tablespace=TBLSPC move repacked tables to a new tablespace\n"); printf(" -S, --moveidx move repacked indexes to TBLSPC too\n"); printf(" -o, --order-by=COLUMNS order by columns instead of cluster keys\n");