*** a/doc/src/sgml/ref/reindex.sgml
--- b/doc/src/sgml/ref/reindex.sgml
***************
*** 22,27 **** PostgreSQL documentation
--- 22,28 ----
   <refsynopsisdiv>
  <synopsis>
  REINDEX { INDEX | TABLE | DATABASE | SYSTEM | USER TABLES } <replaceable class="PARAMETER">name</replaceable> [ FORCE ]
+ REINDEX { DATABASE | SYSTEM | USER TABLES }
  </synopsis>
   </refsynopsisdiv>
  
***************
*** 145,151 **** REINDEX { INDEX | TABLE | DATABASE | SYSTEM | USER TABLES } <replaceable class="
        reindexed.  Index and table names can be schema-qualified.
        Presently, <command>REINDEX DATABASE</>, <command>REINDEX SYSTEM</>,
        and <command>REINDEX USER TABLES</> can only reindex the current
!       database, so their parameter must match the current database's name.
       </para>
      </listitem>
     </varlistentry>
--- 146,153 ----
        reindexed.  Index and table names can be schema-qualified.
        Presently, <command>REINDEX DATABASE</>, <command>REINDEX SYSTEM</>,
        and <command>REINDEX USER TABLES</> can only reindex the current
!       database, so their parameter must match the current database's name
!       if provided.
       </para>
      </listitem>
     </varlistentry>
*** a/src/backend/commands/indexcmds.c
--- b/src/backend/commands/indexcmds.c
***************
*** 1784,1799 **** ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
  	List	   *relids = NIL;
  	ListCell   *l;
  
! 	AssertArg(databaseName);
! 
! 	if (strcmp(databaseName, get_database_name(MyDatabaseId)) != 0)
  		ereport(ERROR,
  				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
  				 errmsg("can only reindex the currently open database")));
  
  	if (!pg_database_ownercheck(MyDatabaseId, GetUserId()))
  		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
! 					   databaseName);
  
  	/*
  	 * Create a memory context that will survive forced transaction commits we
--- 1784,1797 ----
  	List	   *relids = NIL;
  	ListCell   *l;
  
! 	if (databaseName != NULL && strcmp(databaseName, get_database_name(MyDatabaseId)) != 0)
  		ereport(ERROR,
  				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
  				 errmsg("can only reindex the currently open database")));
  
  	if (!pg_database_ownercheck(MyDatabaseId, GetUserId()))
  		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
! 					   get_database_name(MyDatabaseId));
  
  	/*
  	 * Create a memory context that will survive forced transaction commits we
*** a/src/backend/parser/gram.y
--- b/src/backend/parser/gram.y
***************
*** 6974,6979 **** ReindexStmt:
--- 6974,6989 ----
  					n->do_user = false;
  					$$ = (Node *)n;
  				}
+ 			| REINDEX SYSTEM_P
+ 				{
+ 					ReindexStmt *n = makeNode(ReindexStmt);
+ 					n->kind = OBJECT_DATABASE;
+ 					n->name = NULL;
+ 					n->relation = NULL;
+ 					n->do_system = true;
+ 					n->do_user = false;
+ 					$$ = (Node *)n;
+ 				}
  			| REINDEX DATABASE name opt_force
  				{
  					ReindexStmt *n = makeNode(ReindexStmt);
***************
*** 6984,6989 **** ReindexStmt:
--- 6994,7009 ----
  					n->do_user = true;
  					$$ = (Node *)n;
  				}
+ 			| REINDEX DATABASE
+ 				{
+ 					ReindexStmt *n = makeNode(ReindexStmt);
+ 					n->kind = OBJECT_DATABASE;
+ 					n->name = NULL;
+ 					n->relation = NULL;
+ 					n->do_system = true;
+ 					n->do_user = true;
+ 					$$ = (Node *)n;
+ 				}
  			| REINDEX USER TABLES name opt_force
  				{
  					ReindexStmt *n = makeNode(ReindexStmt);
***************
*** 6994,6999 **** ReindexStmt:
--- 7014,7029 ----
  					n->do_user = true;
  					$$ = (Node *)n;
  				}
+ 			| REINDEX USER TABLES
+ 				{
+ 					ReindexStmt *n = makeNode(ReindexStmt);
+ 					n->kind = OBJECT_DATABASE;
+ 					n->name = NULL;
+ 					n->relation = NULL;
+ 					n->do_system = false;
+ 					n->do_user = true;
+ 					$$ = (Node *)n;
+ 				}
  		;
  
  reindex_type:
