aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/scripts/t/100_vacuumdb.pl9
-rw-r--r--src/bin/scripts/vacuumdb.c13
2 files changed, 18 insertions, 4 deletions
diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl
index ff0d97971bd..5e87af2d519 100644
--- a/src/bin/scripts/t/100_vacuumdb.pl
+++ b/src/bin/scripts/t/100_vacuumdb.pl
@@ -3,7 +3,7 @@ use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 35;
+use Test::More tests => 38;
program_help_ok('vacuumdb');
program_version_ok('vacuumdb');
@@ -64,6 +64,7 @@ $node->safe_psql(
'postgres', q|
CREATE TABLE "need""q(uot" (")x" text);
CREATE TABLE vactable (a int, b int);
+ CREATE VIEW vacview AS SELECT 1 as a;
CREATE FUNCTION f0(int) RETURNS int LANGUAGE SQL AS 'SELECT $1 * $1';
CREATE FUNCTION f1(int) RETURNS int LANGUAGE SQL AS 'SELECT f0($1)';
@@ -88,3 +89,9 @@ $node->issues_sql_like(
[ 'vacuumdb', '--analyze-only', '--table', 'vactable(b)', 'postgres' ],
qr/statement: ANALYZE public.vactable\(b\);/,
'vacuumdb --analyze-only with partial column list');
+$node->command_checks_all(
+ [ 'vacuumdb', '--analyze', '--table', 'vacview', 'postgres' ],
+ 0,
+ [qr/^.*vacuuming database "postgres"/],
+ [qr/^WARNING.*cannot vacuum non-tables or special system tables/s],
+ 'vacuumdb with view');
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 05321edb8d4..40ba8283a28 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -484,9 +484,16 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
appendPQExpBuffer(&catalog_query, " JOIN listed_tables"
" ON listed_tables.table_oid OPERATOR(pg_catalog.=) c.oid\n");
- appendPQExpBuffer(&catalog_query, " WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array["
- CppAsString2(RELKIND_RELATION) ", "
- CppAsString2(RELKIND_MATVIEW) "])\n");
+ /*
+ * If no tables were listed, filter for the relevant relation types. If
+ * tables were given via --table, don't bother filtering by relation type.
+ * Instead, let the server decide whether a given relation can be
+ * processed in which case the user will know about it.
+ */
+ if (!tables_listed)
+ appendPQExpBuffer(&catalog_query, " WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array["
+ CppAsString2(RELKIND_RELATION) ", "
+ CppAsString2(RELKIND_MATVIEW) "])\n");
/*
* Execute the catalog query. We use the default search_path for this