[ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ]
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ]) ]
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
+ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
</synopsis>
</refsynopsisdiv>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="PARAMETER">new_owner</replaceable></term>
+ <listitem>
+ <para>
+ The user name of the new owner of the foreign-data wrapper.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="parameter">new_name</replaceable></term>
+ <listitem>
+ <para>
+ The new name for the foreign-data wrapper.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
<para>
<command>ALTER FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
9075-9 (SQL/MED), except that the <literal>HANDLER</literal>,
- <literal>VALIDATOR</> and <literal>OWNER TO</> clauses are extensions.
+ <literal>VALIDATOR</>, <literal>OWNER TO</>, and <literal>RENAME</literal>
+ clauses are extensions.
</para>
</refsect1>
ALTER SERVER <replaceable class="parameter">server_name</replaceable> [ VERSION '<replaceable class="parameter">new_version</replaceable>' ]
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] ) ]
ALTER SERVER <replaceable class="PARAMETER">server_name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
+ALTER SERVER <replaceable class="PARAMETER">server_name</replaceable> RENAME TO <replaceable>new_name</replaceable>
</synopsis>
</refsynopsisdiv>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="PARAMETER">new_owner</replaceable></term>
+ <listitem>
+ <para>
+ The user name of the new owner of the foreign server.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="parameter">new_name</replaceable></term>
+ <listitem>
+ <para>
+ The new name for the foreign server.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
<para>
<command>ALTER SERVER</command> conforms to ISO/IEC 9075-9 (SQL/MED).
+ The <literal>OWNER TO</literal> and <literal>RENAME</literal> forms are
+ PostgreSQL extensions.
</para>
</refsect1>
RenameDatabase(stmt->subname, stmt->newname);
break;
+ case OBJECT_FDW:
+ RenameForeignDataWrapper(stmt->subname, stmt->newname);
+ break;
+
+ case OBJECT_FOREIGN_SERVER:
+ RenameForeignServer(stmt->subname, stmt->newname);
+ break;
+
case OBJECT_FUNCTION:
RenameFunction(stmt->object, stmt->objarg, stmt->newname);
break;
}
+/*
+ * Rename foreign-data wrapper
+ */
+void
+RenameForeignDataWrapper(const char *oldname, const char *newname)
+{
+ HeapTuple tup;
+ Relation rel;
+
+ rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
+
+ tup = SearchSysCacheCopy1(FOREIGNDATAWRAPPERNAME, CStringGetDatum(oldname));
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("foreign-data wrapper \"%s\" does not exist", oldname)));
+
+ /* make sure the new name doesn't exist */
+ if (SearchSysCacheExists1(FOREIGNDATAWRAPPERNAME, CStringGetDatum(newname)))
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("foreign-data wrapper \"%s\" already exists", newname)));
+
+ /* must be owner of FDW */
+ if (!pg_foreign_data_wrapper_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_FDW,
+ oldname);
+
+ /* rename */
+ namestrcpy(&(((Form_pg_foreign_data_wrapper) GETSTRUCT(tup))->fdwname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+}
+
+
+/*
+ * Rename foreign server
+ */
+void
+RenameForeignServer(const char *oldname, const char *newname)
+{
+ HeapTuple tup;
+ Relation rel;
+
+ rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
+
+ tup = SearchSysCacheCopy1(FOREIGNSERVERNAME, CStringGetDatum(oldname));
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("server \"%s\" does not exist", oldname)));
+
+ /* make sure the new name doesn't exist */
+ if (SearchSysCacheExists1(FOREIGNSERVERNAME, CStringGetDatum(newname)))
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("server \"%s\" already exists", newname)));
+
+ /* must be owner of server */
+ if (!pg_foreign_server_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_FOREIGN_SERVER,
+ oldname);
+
+ /* rename */
+ namestrcpy(&(((Form_pg_foreign_server) GETSTRUCT(tup))->srvname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+}
+
+
/*
* Change foreign-data wrapper owner.
*
n->newname = $6;
$$ = (Node *)n;
}
+ | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_FDW;
+ n->subname = $5;
+ n->newname = $8;
+ $$ = (Node *)n;
+ }
| ALTER FUNCTION function_with_argtypes RENAME TO name
{
RenameStmt *n = makeNode(RenameStmt);
n->newname = $6;
$$ = (Node *)n;
}
+ | ALTER SERVER name RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_FOREIGN_SERVER;
+ n->subname = $3;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
| ALTER TABLE relation_expr RENAME TO name
{
RenameStmt *n = makeNode(RenameStmt);
extern List *deserialize_deflist(Datum txt);
/* commands/foreigncmds.c */
+extern void RenameForeignServer(const char *oldname, const char *newname);
+extern void RenameForeignDataWrapper(const char *oldname, const char *newname);
extern void AlterForeignServerOwner(const char *name, Oid newOwnerId);
extern void AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId);
extern void CreateForeignDataWrapper(CreateFdwStmt *stmt);
postgresql | foreign_data_user | - | postgresql_fdw_validator | | |
(3 rows)
+ALTER FOREIGN DATA WRAPPER foo RENAME TO foo1;
+\dew+
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | FDW Options | Description
+------------+-------------------------+---------+--------------------------+-------------------+------------------------------+-------------
+ dummy | foreign_data_user | - | - | | | useless
+ foo1 | regress_test_role_super | - | - | | (b '3', c '4', a '2', d '5') |
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | | |
+(3 rows)
+
+ALTER FOREIGN DATA WRAPPER foo1 RENAME TO foo;
-- DROP FOREIGN DATA WRAPPER
DROP FOREIGN DATA WRAPPER nonexistent; -- ERROR
ERROR: foreign-data wrapper "nonexistent" does not exist
t2 | regress_test_role | foo | | | | |
(10 rows)
+ALTER SERVER s8 RENAME to s8new;
+\des+
+ List of foreign servers
+ Name | Owner | Foreign-data wrapper | Access privileges | Type | Version | FDW Options | Description
+-------+-----------------------+----------------------+-----------------------------------------+--------+---------+--------------------------------------+-------------
+ s1 | regress_test_indirect | foo | foreign_data_user=U/foreign_data_user +| | 1.1 | (servername 's1') |
+ | | | regress_test_role=U/foreign_data_user | | | |
+ s2 | foreign_data_user | foo | | | 1.1 | (host 'a', dbname 'b') |
+ s3 | foreign_data_user | foo | | oracle | | ("tns name" 'orcl', port '1521') |
+ s4 | foreign_data_user | foo | | oracle | | (host 'a', dbname 'b') |
+ s5 | foreign_data_user | foo | | | 15.0 | |
+ s6 | foreign_data_user | foo | foreign_data_user=U/foreign_data_user +| | 16.0 | (host 'a', dbname 'b') |
+ | | | regress_test_role2=U*/foreign_data_user | | | |
+ s7 | foreign_data_user | foo | | oracle | 17.0 | (host 'a', dbname 'b') |
+ s8new | foreign_data_user | postgresql | | | | (dbname 'db1', connect_timeout '30') |
+ t1 | regress_test_role | foo | | | | |
+ t2 | regress_test_role | foo | | | | |
+(10 rows)
+
+ALTER SERVER s8new RENAME to s8;
-- DROP SERVER
DROP SERVER nonexistent; -- ERROR
ERROR: server "nonexistent" does not exist
RESET ROLE;
\dew+
+ALTER FOREIGN DATA WRAPPER foo RENAME TO foo1;
+\dew+
+ALTER FOREIGN DATA WRAPPER foo1 RENAME TO foo;
+
-- DROP FOREIGN DATA WRAPPER
DROP FOREIGN DATA WRAPPER nonexistent; -- ERROR
DROP FOREIGN DATA WRAPPER IF EXISTS nonexistent;
DROP ROLE regress_test_indirect; -- ERROR
\des+
+ALTER SERVER s8 RENAME to s8new;
+\des+
+ALTER SERVER s8new RENAME to s8;
+
-- DROP SERVER
DROP SERVER nonexistent; -- ERROR
DROP SERVER IF EXISTS nonexistent;