Re: [Proposal] vacuumdb --schema only - Mailing list pgsql-hackers

From Justin Pryzby
Subject Re: [Proposal] vacuumdb --schema only
Date
Msg-id 20220306150417.GO27651@telsasoft.com
Whole thread Raw
In response to Re: [Proposal] vacuumdb --schema only  (Gilles Darold <gilles@migops.com>)
Responses Re: [Proposal] vacuumdb --schema only  (Gilles Darold <gilles@migops.com>)
List pgsql-hackers
On Sun, Mar 06, 2022 at 09:39:37AM +0100, Gilles Darold wrote:
> Attached a new patch version that adds the -N | --exclude-schema option
> to the vacuumdb command as suggested. Documentation updated too.
> 
> +        pg_log_error("cannot vacuum all tables in schema(s) and and exclude specific schema(s) at the same time");

and and

It's odd that schema_exclusion is a global var, but schemas/excluded are not.

Also, it seems unnecessary to have two schemas vars, since they can't be used
together.  Maybe there's a better way than what I did in 003.

> +        for (cell = schemas ? schemas->head : NULL; cell; cell = cell->next)

It's preferred to write cell != NULL

> +       bool            schemas_listed = false;
...
> +        for (cell = schemas ? schemas->head : NULL; cell; cell = cell->next)
> +        {
> +            if (!schemas_listed) {
> +                appendPQExpBufferStr(&catalog_query,
> +                                     " AND pg_catalog.quote_ident(ns.nspname)");
> +                if (schema_exclusion)
> +                    appendPQExpBufferStr(&catalog_query, " NOT IN (");
> +                else
> +                    appendPQExpBufferStr(&catalog_query, " IN (");
> +
> +                schemas_listed = true;
> +            }
> +            else
> +                appendPQExpBufferStr(&catalog_query, ", ");
> +
> +            appendStringLiteralConn(&catalog_query, cell->val, conn);
> +            appendPQExpBufferStr(&catalog_query, "::pg_catalog.regnamespace::pg_catalog.name");
> +
> +        }
> +        /* Finish formatting schema filter */
> +        if (schemas_listed)
> +            appendPQExpBufferStr(&catalog_query, ")\n");
>      }

Maybe it's clearer to write this with =ANY() / != ALL() ?
See 002.

-- 
Justin

Attachment

pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: ltree_gist indexes broken after pg_upgrade from 12 to 13
Next
From: Robert Haas
Date:
Subject: Re: role self-revocation