Skip to content

Vacuumdb schema only #1

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add -n | --schema and -N | --exclude-schema options to vacuumdb
  • Loading branch information
darold committed Apr 20, 2022
commit f8092171d9f06aaac874a453a7084a8f03b28071
64 changes: 64 additions & 0 deletions doc/src/sgml/ref/vacuumdb.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,40 @@ PostgreSQL documentation
<arg choice="opt"><replaceable>dbname</replaceable></arg>
</cmdsynopsis>

<cmdsynopsis>
<command>vacuumdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<arg rep="repeat"><replaceable>option</replaceable></arg>

<arg choice="plain" rep="repeat">
<arg choice="opt">
<group choice="plain">
<arg choice="plain">
<arg choice="opt">
<group choice="plain">
<arg choice="plain"><option>-n</option></arg>
<arg choice="plain"><option>--schema</option></arg>
</group>
<replaceable>schema</replaceable>
</arg>
</arg>

<arg choice="plain">
<arg choice="opt">
<group choice="plain">
<arg choice="plain"><option>-N</option></arg>
<arg choice="plain"><option>--exclude-schema</option></arg>
</group>
<replaceable>schema</replaceable>
</arg>
</arg>
</group>
</arg>
</arg>

<arg choice="opt"><replaceable>dbname</replaceable></arg>
</cmdsynopsis>

<cmdsynopsis>
<command>vacuumdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
Expand Down Expand Up @@ -244,6 +278,28 @@ PostgreSQL documentation
</listitem>
</varlistentry>

<varlistentry>
<term><option>-n <replaceable class="parameter">schema</replaceable></option></term>
<term><option>--schema=<replaceable class="parameter">schema</replaceable></option></term>
<listitem>
<para>
Clean or analyze all tables in <replaceable class="parameter">schema</replaceable> only.
Multiple schemas can be vacuumed by writing multiple <option>-n</option> switches.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>-N <replaceable class="parameter">schema</replaceable></option></term>
<term><option>--exclude-schema=<replaceable class="parameter">schema</replaceable></option></term>
<listitem>
<para>
Clean or analyze all tables NOT in <replaceable class="parameter">schema</replaceable>.
Multiple schemas can be excluded from the vacuum by writing multiple <option>-N</option> switches.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--no-index-cleanup</option></term>
<listitem>
Expand Down Expand Up @@ -619,6 +675,14 @@ PostgreSQL documentation
<prompt>$ </prompt><userinput>vacuumdb --analyze --verbose --table='foo(bar)' xyzzy</userinput>
</screen></para>

<para>
To clean all tables in the <literal>foo</literal> and <literal>bar</literal> schemas
only in a database named <literal>xyzzy</literal>:
<screen>
<prompt>$ </prompt><userinput>vacuumdb --schema='foo' --schema='bar' xyzzy</userinput>
</screen></para>


</refsect1>

<refsect1>
Expand Down
12 changes: 12 additions & 0 deletions src/bin/scripts/t/100_vacuumdb.pl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
CREATE TABLE funcidx (x int);
INSERT INTO funcidx VALUES (0),(1),(2),(3);
CREATE INDEX i0 ON funcidx ((f1(x)));
CREATE SCHEMA "Foo";
CREATE TABLE "Foo".bar(id int);
|);
$node->command_ok([qw|vacuumdb -Z --table="need""q(uot"(")x") postgres|],
'column list');
Expand Down Expand Up @@ -146,5 +148,15 @@
[ 'vacuumdb', '--min-xid-age', '2147483001', 'postgres' ],
qr/GREATEST.*relfrozenxid.*2147483001/,
'vacuumdb --table --min-xid-age');
$node->issues_sql_like(
[ 'vacuumdb', '--schema', '"Foo"', 'postgres' ],
qr/VACUUM "Foo".bar/,
'vacuumdb --schema schema only');
$node->command_fails(
[ 'vacuumdb', '-n', 'pg_catalog', '-t', 'pg_class', 'postgres' ],
'cannot vacuum all tables in schema(s) and specific table(s) at the same time');
$node->command_fails(
[ 'vacuumdb', '-n', 'pg_catalog', '-N', '"Foo"', 'postgres' ],
'cannot use option -n | --schema and -N | --exclude-schema at the same time');

done_testing();
3 changes: 3 additions & 0 deletions src/bin/scripts/t/101_vacuumdb_all.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
[ 'vacuumdb', '-a' ],
qr/statement: VACUUM.*statement: VACUUM/s,
'vacuum all databases');
$node->command_fails(
[ 'vacuumdb', '-a', '-n', 'pg_catalog' ],
'cannot vacuum specific schema(s) in all databases');

done_testing();
Loading