aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-01-30 09:44:08 +0900
committerMichael Paquier <michael@paquier.xyz>2019-01-30 09:44:08 +0900
commitb8f73df0f845d865823ef72669024dc150282392 (patch)
tree78380701182b0f467cc84eab897b1571ac3c5db4
parentfa2cf164aaf91e074be653c28e035f65d80eb666 (diff)
downloadpostgresql-b8f73df0f845d865823ef72669024dc150282392.tar.gz
postgresql-b8f73df0f845d865823ef72669024dc150282392.zip
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
-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