%type <defelt> generic_option_elem alter_generic_option_elem
%type <list> generic_option_list alter_generic_option_list
-%type <ival> reindex_target_type
+%type <ival> reindex_target_relation reindex_target_all
%type <list> opt_reindex_option_list
%type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
*
* QUERY:
*
- * REINDEX [ (options) ] {TABLE | INDEX | SCHEMA} [CONCURRENTLY] <name>
- * REINDEX [ (options) ] DATABASE [CONCURRENTLY] [<name>]
- * REINDEX [ (options) ] SYSTEM [<name>]
+ * REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
+ * REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
*****************************************************************************/
ReindexStmt:
- REINDEX opt_reindex_option_list reindex_target_type opt_concurrently qualified_name
+ REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
{
ReindexStmt *n = makeNode(ReindexStmt);
ReindexStmt *n = makeNode(ReindexStmt);
n->kind = REINDEX_OBJECT_SCHEMA;
- n->name = $5;
n->relation = NULL;
+ n->name = $5;
n->params = $2;
if ($4)
n->params = lappend(n->params,
makeDefElem("concurrently", NULL, @4));
$$ = (Node *) n;
}
- | REINDEX opt_reindex_option_list DATABASE opt_concurrently opt_single_name
- {
- ReindexStmt *n = makeNode(ReindexStmt);
- n->kind = REINDEX_OBJECT_DATABASE;
- n->name = NULL;
- n->relation = NULL;
- n->params = $2;
- $$ = (Node *) n;
- }
- | REINDEX opt_reindex_option_list SYSTEM_P opt_single_name
+ | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
{
ReindexStmt *n = makeNode(ReindexStmt);
- n->kind = REINDEX_OBJECT_SYSTEM;
- n->name = NULL;
+
+ n->kind = $3;
n->relation = NULL;
+ n->name = $5;
n->params = $2;
+ if ($4)
+ n->params = lappend(n->params,
+ makeDefElem("concurrently", NULL, @4));
$$ = (Node *) n;
}
;
-reindex_target_type:
+reindex_target_relation:
INDEX { $$ = REINDEX_OBJECT_INDEX; }
| TABLE { $$ = REINDEX_OBJECT_TABLE; }
;
+reindex_target_all:
+ SYSTEM_P { $$ = REINDEX_OBJECT_SYSTEM; }
+ | DATABASE { $$ = REINDEX_OBJECT_DATABASE; }
+ ;
opt_reindex_option_list:
'(' utility_option_list ')' { $$ = $2; }
| /* EMPTY */ { $$ = NULL; }
# REINDEX operations. A set of relfilenodes is saved from the catalogs
# and then compared with pg_class.
$node->safe_psql('postgres',
- 'CREATE TABLE index_relfilenodes (parent regclass, indname regclass, relfilenode oid);'
+ 'CREATE TABLE index_relfilenodes (parent regclass, indname text, indoid oid, relfilenode oid);'
);
# Save the relfilenode of a set of toast indexes, one from the catalog
# pg_constraint and one from the test table.
my $fetch_toast_relfilenodes =
- qq{SELECT b.oid::regclass, c.oid::regclass, c.relfilenode
+ qq{SELECT b.oid::regclass, c.oid::regclass::text, c.oid, c.relfilenode
FROM pg_class a
JOIN pg_class b ON (a.oid = b.reltoastrelid)
JOIN pg_index i on (a.oid = i.indrelid)
WHERE b.oid IN ('pg_constraint'::regclass, 'test1'::regclass)};
# Same for relfilenodes of normal indexes. This saves the relfilenode
# from an index of pg_constraint, and from the index of the test table.
-my $fetch_index_relfilenodes = qq{SELECT i.indrelid, a.oid, a.relfilenode
+my $fetch_index_relfilenodes = qq{SELECT i.indrelid, a.oid::regclass::text, a.oid, a.relfilenode
FROM pg_class a
JOIN pg_index i ON (i.indexrelid = a.oid)
WHERE a.relname IN ('pg_constraint_oid_index', 'test1x')};
# parent table is included to provide more context.
my $compare_relfilenodes = qq(SELECT b.parent::regclass,
regexp_replace(b.indname::text, '(pg_toast.pg_toast_)\\d+(_index)', '\\1<oid>\\2'),
+ CASE WHEN a.oid = b.indoid THEN 'OID is unchanged'
+ ELSE 'OID has changed' END,
CASE WHEN a.relfilenode = b.relfilenode THEN 'relfilenode is unchanged'
ELSE 'relfilenode has changed' END
FROM index_relfilenodes b
'SQL REINDEX run');
my $relnode_info = $node->safe_psql('postgres', $compare_relfilenodes);
is( $relnode_info,
- qq(pg_constraint|pg_constraint_oid_index|relfilenode is unchanged
-pg_constraint|pg_toast.pg_toast_<oid>_index|relfilenode is unchanged
-test1|pg_toast.pg_toast_<oid>_index|relfilenode has changed
-test1|test1x|relfilenode has changed),
+ qq(pg_constraint|pg_constraint_oid_index|OID is unchanged|relfilenode is unchanged
+pg_constraint|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode is unchanged
+test1|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode has changed
+test1|test1x|OID is unchanged|relfilenode has changed),
'relfilenode change after REINDEX DATABASE');
# Re-save and run the second one.
'reindex system tables');
$relnode_info = $node->safe_psql('postgres', $compare_relfilenodes);
is( $relnode_info,
- qq(pg_constraint|pg_constraint_oid_index|relfilenode has changed
-pg_constraint|pg_toast.pg_toast_<oid>_index|relfilenode has changed
-test1|pg_toast.pg_toast_<oid>_index|relfilenode is unchanged
-test1|test1x|relfilenode is unchanged),
+ qq(pg_constraint|pg_constraint_oid_index|OID is unchanged|relfilenode has changed
+pg_constraint|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode has changed
+test1|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode is unchanged
+test1|test1x|OID is unchanged|relfilenode is unchanged),
'relfilenode change after REINDEX SYSTEM');
$node->issues_sql_like(
qr/statement: REINDEX \(VERBOSE, TABLESPACE $tbspace_name\) TABLE public\.test1;/,
'reindex with verbose output and tablespace');
-# the same with --concurrently
+# Same with --concurrently.
+# Save the state of the relations and compare them after the DATABASE
+# rebuild.
+$node->safe_psql('postgres',
+ "TRUNCATE index_relfilenodes; $save_relfilenodes");
$node->issues_sql_like(
[ 'reindexdb', '--concurrently', 'postgres' ],
qr/statement: REINDEX DATABASE CONCURRENTLY postgres;/,
'SQL REINDEX CONCURRENTLY run');
+$relnode_info = $node->safe_psql('postgres', $compare_relfilenodes);
+is( $relnode_info,
+ qq(pg_constraint|pg_constraint_oid_index|OID is unchanged|relfilenode is unchanged
+pg_constraint|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode is unchanged
+test1|pg_toast.pg_toast_<oid>_index|OID has changed|relfilenode has changed
+test1|test1x|OID has changed|relfilenode has changed),
+ 'OID change after REINDEX DATABASE CONCURRENTLY');
$node->issues_sql_like(
[ 'reindexdb', '--concurrently', '-t', 'test1', 'postgres' ],
REINDEX INDEX CONCURRENTLY pg_toast.pg_toast_1260_index; -- no catalog toast index
ERROR: cannot reindex system catalogs concurrently
REINDEX SYSTEM CONCURRENTLY postgres; -- not allowed for SYSTEM
-ERROR: syntax error at or near "CONCURRENTLY"
-LINE 1: REINDEX SYSTEM CONCURRENTLY postgres;
- ^
+ERROR: cannot reindex system catalogs concurrently
REINDEX (CONCURRENTLY) SYSTEM postgres; -- ditto
ERROR: cannot reindex system catalogs concurrently
REINDEX (CONCURRENTLY) SYSTEM; -- ditto
-- Warns about catalog relations
REINDEX SCHEMA CONCURRENTLY pg_catalog;
WARNING: cannot reindex system catalogs concurrently, skipping all
+-- Not the current database
+REINDEX DATABASE not_current_database;
+ERROR: can only reindex the currently open database
-- Check the relation status, there should not be invalid indexes
\d concur_reindex_tab
Table "public.concur_reindex_tab"