Skip to content

Commit b8f73df

Browse files
committed
Do not filter by relkind in vacuumdb's catalog query if --table is used
If a user specifies a relation name which cannot be processed, then the backend can warn directly about what is wrong with it. This fixes an oversight from e0c2933. Author: Nathan Bossart Discussion: https://postgr.es/m/32049A78-C429-4742-AEC1-941C9ABDE7B8@amazon.com
1 parent fa2cf16 commit b8f73df

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/bin/scripts/t/100_vacuumdb.pl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use PostgresNode;
55
use TestLib;
6-
use Test::More tests => 35;
6+
use Test::More tests => 38;
77

88
program_help_ok('vacuumdb');
99
program_version_ok('vacuumdb');
@@ -64,6 +64,7 @@
6464
'postgres', q|
6565
CREATE TABLE "need""q(uot" (")x" text);
6666
CREATE TABLE vactable (a int, b int);
67+
CREATE VIEW vacview AS SELECT 1 as a;
6768
6869
CREATE FUNCTION f0(int) RETURNS int LANGUAGE SQL AS 'SELECT $1 * $1';
6970
CREATE FUNCTION f1(int) RETURNS int LANGUAGE SQL AS 'SELECT f0($1)';
@@ -88,3 +89,9 @@
8889
[ 'vacuumdb', '--analyze-only', '--table', 'vactable(b)', 'postgres' ],
8990
qr/statement: ANALYZE public.vactable\(b\);/,
9091
'vacuumdb --analyze-only with partial column list');
92+
$node->command_checks_all(
93+
[ 'vacuumdb', '--analyze', '--table', 'vacview', 'postgres' ],
94+
0,
95+
[qr/^.*vacuuming database "postgres"/],
96+
[qr/^WARNING.*cannot vacuum non-tables or special system tables/s],
97+
'vacuumdb with view');

src/bin/scripts/vacuumdb.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,16 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
484484
appendPQExpBuffer(&catalog_query, " JOIN listed_tables"
485485
" ON listed_tables.table_oid OPERATOR(pg_catalog.=) c.oid\n");
486486

487-
appendPQExpBuffer(&catalog_query, " WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array["
488-
CppAsString2(RELKIND_RELATION) ", "
489-
CppAsString2(RELKIND_MATVIEW) "])\n");
487+
/*
488+
* If no tables were listed, filter for the relevant relation types. If
489+
* tables were given via --table, don't bother filtering by relation type.
490+
* Instead, let the server decide whether a given relation can be
491+
* processed in which case the user will know about it.
492+
*/
493+
if (!tables_listed)
494+
appendPQExpBuffer(&catalog_query, " WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array["
495+
CppAsString2(RELKIND_RELATION) ", "
496+
CppAsString2(RELKIND_MATVIEW) "])\n");
490497

491498
/*
492499
* Execute the catalog query. We use the default search_path for this

0 commit comments

Comments
 (0)