mirror of https://github.com/postgres/postgres
This doesn't do any remote or external things yet, but it gives modules like plproxy and dblink a standardized and future-proof system for managing their connection information. Martin Pihlak and Peter EisentrautREL8_5_ALPHA1_BRANCH
parent
1eec10a2de
commit
cae565e503
@ -0,0 +1,132 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_foreign_data_wrapper.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-ALTERFOREIGNDATAWRAPPER"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-alterforeigndatawrapper-title">ALTER FOREIGN DATA WRAPPER</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>ALTER FOREIGN DATA WRAPPER</refname> |
||||
<refpurpose>change the definition of a foreign-data wrapper</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-alterforeigndatawrapper"> |
||||
<primary>ALTER FOREIGN DATA WRAPPER</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> |
||||
[ LIBRARY '<replaceable class="parameter">libraryname</replaceable>' ] |
||||
[ 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> |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>ALTER FOREIGN DATA WRAPPER</command> changes the |
||||
definition of a foreign-data wrapper. The first form of the |
||||
command changes the library or the generic options of the |
||||
foreign-data wrapper (at least one clause is required). The second |
||||
form changes the owner of the foreign-data wrapper. |
||||
</para> |
||||
|
||||
<para> |
||||
Only superusers can alter foreign-data wrappers. Additionally, |
||||
only superusers can own foreign-data wrappers. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of an existing foreign-data wrapper. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">libraryname</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
New name of the foreign-data wrapper library. |
||||
</para> |
||||
|
||||
<para> |
||||
Note that it is possible that after changing the library, the |
||||
options to the foreign-data wrapper, servers, and user mappings |
||||
have become invalid. It is up to the user to make sure that |
||||
these options are correct before using the foreign-data |
||||
wrapper. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Change options for the foreign-data |
||||
wrapper. <literal>ADD</>, <literal>SET</>, and <literal>DROP</> |
||||
specify the action to be performed. <literal>ADD</> is assumed |
||||
if no operation is explicitly specified. Option names must be |
||||
unique; names and values are also validated using the foreign |
||||
data wrapper library. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Change a foreign-data wrapper <literal>dbi</>, add |
||||
option <literal>foo</>, drop <literal>bar</>: |
||||
<programlisting> |
||||
ALTER FOREIGN DATA WRAPPER dbi OPTIONS (ADD foo '1', DROP 'bar'); |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
Change the foreign-data wrapper <literal>dbi</> library |
||||
to <literal>/home/bob/mylibrary.so</>: |
||||
<programlisting> |
||||
ALTER FOREIGN DATA WRAPPER dbi LIBRARY '/home/bob/mylibrary.so'; |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>ALTER FOREIGN DATA WRAPPER</command> conforms to ISO/IEC |
||||
9075-9 (SQL/MED). The standard does not specify the <literal>OWNER |
||||
TO</> variant of the command. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createforeigndatawrapper" endterm="sql-createforeigndatawrapper-title"></member> |
||||
<member><xref linkend="sql-dropforeigndatawrapper" endterm="sql-dropforeigndatawrapper-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
@ -0,0 +1,123 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_server.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-ALTERSERVER"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-alterserver-title">ALTER SERVER</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>ALTER SERVER</refname> |
||||
<refpurpose>change the definition of a foreign server</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-alterserver"> |
||||
<primary>ALTER SERVER</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
ALTER SERVER <replaceable class="parameter">servername</replaceable> [ VERSION 'newversion' ] |
||||
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] ) ] |
||||
ALTER SERVER <replaceable class="PARAMETER">servername</replaceable> OWNER TO <replaceable>new_owner</replaceable> |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>ALTER SERVER</command> changes the definition of a foreign |
||||
server. The first form changes the server version string or the |
||||
generic options of the server (at least one clause is required). |
||||
The second form changes the owner of the server. |
||||
</para> |
||||
|
||||
<para> |
||||
To alter the server you must be the owner of the server. |
||||
Additionally to alter the owner, you must own the server and also |
||||
be a direct or indirect member of the new owning role, and you must |
||||
have <literal>USAGE</> privilege on the server's foreign-data |
||||
wrapper. (Note that superusers satisfy all these criteria |
||||
automatically.) |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">servername</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of an existing server. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">serverversion</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
New server version. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Change options for the |
||||
server. <literal>ADD</>, <literal>SET</>, and <literal>DROP</> |
||||
specify the action to be performed. <literal>ADD</> is assumed |
||||
if no operation is explicitly specified. Option names must be |
||||
unique; names and values are also validated using the server's |
||||
foreign-data wrapper library. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Alter server <literal>foo</>, add connection options: |
||||
<programlisting> |
||||
ALTER SERVER foo OPTIONS (host 'foo', dbname 'foodb'); |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
Alter server <literal>foo</>, change version, |
||||
change <literal>host</> option: |
||||
<programlisting> |
||||
ALTER SERVER foo VERSION '8.4' OPTIONS (SET host 'baz'); |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>ALTER SERVER</command> conforms to ISO/IEC 9075-9 (SQL/MED). |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createserver" endterm="sql-createserver-title"></member> |
||||
<member><xref linkend="sql-dropserver" endterm="sql-dropserver-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
@ -0,0 +1,119 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_user_mapping.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-ALTERUSERMAPPING"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-alterusermapping-title">ALTER USER MAPPING</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>ALTER USER MAPPING</refname> |
||||
<refpurpose>change the definition of a user mapping</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-alterusermapping"> |
||||
<primary>ALTER USER MAPPING</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
ALTER USER MAPPING FOR { <replaceable class="parameter">username</replaceable> | USER | CURRENT_USER | PUBLIC } |
||||
SERVER <replaceable class="parameter">servername</replaceable> |
||||
OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] ) |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>ALTER USER MAPPING</command> changes the definition of a |
||||
user mapping. Only the owner of the server can change the user |
||||
mappings of that server. |
||||
</para> |
||||
|
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">username</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
User name of the mapping. <literal>CURRENT_USER</> |
||||
and <literal>USER</> match the name of the current |
||||
user. <literal>PUBLIC</> is used to match all present and future |
||||
user names in the system. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">servername</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
Server name of the user mapping. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Change options for the user mapping. The new options override |
||||
any previously specified |
||||
options. <literal>ADD</>, <literal>SET</>, and <literal>DROP</> |
||||
specify the action to be performed. <literal>ADD</> is assumed |
||||
if no operation is explicitly specified. Option names must be |
||||
unique; options are also validated by the server's foreign-data |
||||
wrapper. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Change the password for user mapping <literal>bob</>, server<literal> foo</>: |
||||
<programlisting> |
||||
ALTER USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'public'); |
||||
</programlisting> |
||||
</para> |
||||
|
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>ALTER USER MAPPING</command> conforms to ISO/IEC 9075-9 |
||||
(SQL/MED). There is a subtle syntax issue: The standard omits |
||||
the <literal>FOR</literal> key word. Since both <literal>CREATE |
||||
USER MAPPING</literal> and <literal>DROP USER MAPPING</literal> use |
||||
<literal>FOR</literal> in analogous positions, and IBM DB2 (being |
||||
the other major SQL/MED implementation) also requires it |
||||
for <literal>ALTER USER MAPPING</literal>, PostgreSQL diverges from |
||||
the standard here in the interest of consistency and |
||||
interoperability. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createusermapping" endterm="sql-createusermapping-title"></member> |
||||
<member><xref linkend="sql-dropusermapping" endterm="sql-dropusermapping-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
@ -0,0 +1,185 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/create_foreign_data_wrapper.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-CREATEFOREIGNDATAWRAPPER"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-createforeigndatawrapper-title">CREATE FOREIGN DATA WRAPPER</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>CREATE FOREIGN DATA WRAPPER</refname> |
||||
<refpurpose>define a new foreign-data wrapper</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-createforeigndatawrapper"> |
||||
<primary>CREATE FOREIGN DATA WRAPPER</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> |
||||
LIBRARY '<replaceable class="parameter">libraryname</replaceable>' |
||||
LANGUAGE C |
||||
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>CREATE FOREIGN DATA WRAPPER</command> creates a new |
||||
foreign-data wrapper. The user who defines a foreign-data wrapper |
||||
becomes its owner. |
||||
</para> |
||||
|
||||
<para> |
||||
The foreign-data wrapper name must be unique within the database. |
||||
</para> |
||||
|
||||
<para> |
||||
Only superusers can create foreign-data wrappers. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of the foreign-data wrapper to be created. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">libraryname</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of the shared library implementing the foreign-data |
||||
wrapper. The file name is specified in the same way as for |
||||
shared library names in <xref linkend="sql-createfunction" |
||||
endterm="sql-createfunction-title">; in particular, one can rely |
||||
on a search path and automatic addition of the system's standard |
||||
shared library file name extension. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>LANGUAGE C</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Currently, only the C programming language is supported for |
||||
implementing foreign-data wrappers. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term> |
||||
<listitem> |
||||
<para> |
||||
This clause specifies options for the new foreign-data wrapper. |
||||
The allowed option names and values are specific to each foreign |
||||
data wrapper and are validated using the foreign-data wrapper |
||||
library. Option names must be unique. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Notes</title> |
||||
|
||||
<para> |
||||
At the moment, the foreign-data wrapper functionality is very |
||||
rudimentary. The purpose of foreign-data wrappers, foreign |
||||
servers, and user mappings is to store this information in a |
||||
standard way so that it can be queried by interested applications. |
||||
The functionality to actually query external data does not exist |
||||
yet. |
||||
</para> |
||||
|
||||
<para> |
||||
The C language API for foreign-data wrappers is currently not |
||||
documented, stable, or complete. Would-be authors of functionality |
||||
interfacing with the SQL/MED functionality are advised to contact |
||||
the PostgreSQL developers. |
||||
</para> |
||||
|
||||
<para> |
||||
There are currently two foreign-data wrapper libraries |
||||
provided: <filename>dummy_fdw</filename>, which does nothing and |
||||
could be useful for testing, |
||||
and <filename>postgresql_fdw</filename>, which accepts options |
||||
corresponding to <application>libpq</> connection parameters. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Create a foreign-data wrapper <literal>dummy</> with |
||||
library <literal>dummy_fdw</>: |
||||
<programlisting> |
||||
CREATE FOREIGN DATA WRAPPER dummy LIBRARY 'dummy_fdw' LANGUAGE C; |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
Create a foreign-data wrapper <literal>postgresql</> with |
||||
library <literal>postgresql_fdw</>: |
||||
<programlisting> |
||||
CREATE FOREIGN DATA WRAPPER postgresql LIBRARY 'postgresql_fdw' LANGUAGE C; |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
Create a foreign-data wrapper <literal>mywrapper</> with library |
||||
<literal>/home/bob/mywrapper.so</> and some options: |
||||
<programlisting> |
||||
CREATE FOREIGN DATA WRAPPER mywrapper |
||||
LIBRARY '/home/bob/mywrapper.so' |
||||
LANGUAGE C |
||||
OPTIONS (debug 'true'); |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>CREATE FOREIGN DATA WRAPPER</command> conforms to ISO/IEC |
||||
9075-9 (SQL/MED), with the exception that |
||||
the <literal>LIBRARY</literal> clause is not optional in |
||||
PostgreSQL. |
||||
</para> |
||||
|
||||
<para> |
||||
Note, however, that the SQL/MED functionality as a whole is not yet |
||||
conforming. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-alterforeigndatawrapper" endterm="sql-alterforeigndatawrapper-title"></member> |
||||
<member><xref linkend="sql-dropforeigndatawrapper" endterm="sql-dropforeigndatawrapper-title"></member> |
||||
<member><xref linkend="sql-createserver" endterm="sql-createserver-title"></member> |
||||
<member><xref linkend="sql-createusermapping" endterm="sql-createusermapping-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
@ -0,0 +1,140 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/create_server.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-CREATESERVER"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-createserver-title">CREATE SERVER</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>CREATE SERVER</refname> |
||||
<refpurpose>define a new foreign server</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-createserver"> |
||||
<primary>CREATE SERVER</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
CREATE SERVER <replaceable class="parameter">servername</replaceable> [ TYPE 'servertype' ] [ VERSION 'serverversion' ] |
||||
FOREIGN DATA WRAPPER <replaceable class="parameter">fdwname</replaceable> |
||||
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>CREATE SERVER</command> defines a new foreign server. The |
||||
user who defines the server becomes its owner. |
||||
</para> |
||||
|
||||
<para> |
||||
The server name must be unique within database. |
||||
</para> |
||||
|
||||
<para> |
||||
Creating a server requires <literal>USAGE</> privilege on the |
||||
foreign-data wrapper being used. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">servername</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of the foreign server to be created. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">servertype</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
Optional server type. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">serverversion</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
Optional server version. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">fdwname</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of the foreign-data wrapper that manages the server. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term> |
||||
<listitem> |
||||
<para> |
||||
This clause specifies the options for the server. The options |
||||
typically define the connection details of the server, but the |
||||
actual names and values are dependent on the server's |
||||
foreign-data wrapper. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Create a server <literal>foo</> that uses the built-in foreign-data |
||||
wrapper <literal>default</>: |
||||
<programlisting> |
||||
CREATE SERVER foo FOREIGN DATA WRAPPER "default"; |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
Create a server <literal>myserver</> that uses the |
||||
foreign-data wrapper <literal>pgsql</>: |
||||
<programlisting> |
||||
CREATE SERVER myserver FOREIGN DATA WRAPPER pgsql OPTIONS (host 'foo', dbname 'foodb', port '5432'); |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>CREATE SERVER</command> conforms to ISO/IEC 9075-9 (SQL/MED). |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-alterserver" endterm="sql-alterserver-title"></member> |
||||
<member><xref linkend="sql-dropserver" endterm="sql-dropserver-title"></member> |
||||
<member><xref linkend="sql-createforeigndatawrapper" endterm="sql-createforeigndatawrapper-title"></member> |
||||
<member><xref linkend="sql-createusermapping" endterm="sql-createusermapping-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
@ -0,0 +1,111 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/create_user_mapping.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-CREATEUSERMAPPING"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-createusermapping-title">CREATE USER MAPPING</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>CREATE USER MAPPING</refname> |
||||
<refpurpose>define a new mapping of a user to a foreign server</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-createusermapping"> |
||||
<primary>CREATE USER MAPPING</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
CREATE USER MAPPING FOR { <replaceable class="parameter">username</replaceable> | USER | CURRENT_USER | PUBLIC } |
||||
SERVER <replaceable class="parameter">servername</replaceable> |
||||
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [ , ... ] ) ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>CREATE USER MAPPING</command> defines a mapping of a user |
||||
to a foreign server. You must be the owner of the server to define |
||||
user mappings for it. |
||||
</para> |
||||
|
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">username</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of an existing user that is mapped to foreign server. |
||||
<literal>CURRENT_USER</> and <literal>USER</> match the name of |
||||
the current user. <literal>PUBLIC</> is used to match all |
||||
present and future user names in the system. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">servername</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of an existing server for which the user mapping is |
||||
to be created. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term> |
||||
<listitem> |
||||
<para> |
||||
This clause specifies the options of the user mapping. The |
||||
options typically define the actual user name and password of |
||||
the mapping. Option names must be unque. The allowed option |
||||
names and values are specific to the server's foreign-data wrapper. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Create a user mapping for user <literal>bob</>, server <literal>foo</>: |
||||
<programlisting> |
||||
CREATE USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'secret'); |
||||
</programlisting> |
||||
</para> |
||||
|
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>CREATE USER MAPPING</command> conforms to ISO/IEC 9075-9 (SQL/MED). |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-alterusermapping" endterm="sql-alterusermapping-title"></member> |
||||
<member><xref linkend="sql-dropusermapping" endterm="sql-dropusermapping-title"></member> |
||||
<member><xref linkend="sql-createforeigndatawrapper" endterm="sql-createforeigndatawrapper-title"></member> |
||||
<member><xref linkend="sql-createserver" endterm="sql-createserver-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
@ -0,0 +1,112 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_foreign_data_wrapper.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-DROPFOREIGNDATAWRAPPER"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-dropforeigndatawrapper-title">DROP FOREIGN DATA WRAPPER</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>DROP FOREIGN DATA WRAPPER</refname> |
||||
<refpurpose>remove a foreign-data wrapper</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-dropforeigndatawrapper"> |
||||
<primary>DROP FOREIGN DATA WRAPPER</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
DROP FOREIGN DATA WRAPPER [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ CASCADE | RESTRICT ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>DROP FOREIGN DATA WRAPPER</command> removes an existing |
||||
foreign-data wrapper. To execute this command, the current user |
||||
must be the owner of the foreign-data wrapper. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><literal>IF EXISTS</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Do not throw an error if the foreign-data wrapper does not |
||||
exist. A notice is issued in this case. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of an existing foreign-data wrapper. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>CASCADE</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Automatically drop objects that depend on the foreign-data |
||||
wrapper (such as servers). |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>RESTRICT</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Refuse to drop the foreign-data wrappers if any objects depend |
||||
on it. This is the default. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Drop the foreign-data wrapper <literal>dbi</>: |
||||
<programlisting> |
||||
DROP FOREIGN DATA WRAPPER dbi; |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>DROP FOREIGN DATA WRAPPER</command> conforms to ISO/IEC |
||||
9075-9 (SQL/MED). The <literal>IF EXISTS</> clause is |
||||
a <productname>PostgreSQL</> extension. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createforeigndatawrapper" endterm="sql-createforeigndatawrapper-title"></member> |
||||
<member><xref linkend="sql-alterforeigndatawrapper" endterm="sql-alterforeigndatawrapper-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
@ -0,0 +1,112 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_server.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-DROPSERVER"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-dropserver-title">DROP SERVER</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>DROP SERVER</refname> |
||||
<refpurpose>remove a foreign server descriptor</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-dropserver"> |
||||
<primary>DROP SERVER</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
DROP SERVER [ IF EXISTS ] <replaceable class="parameter">servername</replaceable> [ CASCADE | RESTRICT ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>DROP SERVER</command> removes an existing foreign server |
||||
descriptor. To execute this command, the current user must be the |
||||
owner of the server. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><literal>IF EXISTS</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Do not throw an error if the server does not exist. A notice is |
||||
issued in this case. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">servername</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of an existing server. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>CASCADE</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Automatically drop objects that depend on the server (such as |
||||
user mappings). |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>RESTRICT</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Refuse to drop the server if any objects depend on it. This is |
||||
the default. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Drop a server <literal>foo</> if it exists: |
||||
<programlisting> |
||||
DROP SERVER IF EXISTS foo; |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>DROP SERVER</command> conforms to ISO/IEC 9075-9 |
||||
(SQL/MED). The <literal>IF EXISTS</> clause is |
||||
a <productname>PostgreSQL</> extension. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createserver" endterm="sql-createserver-title"></member> |
||||
<member><xref linkend="sql-alterserver" endterm="sql-alterserver-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
@ -0,0 +1,104 @@ |
||||
<!-- |
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_user_mapping.sgml,v 1.1 2008/12/19 16:25:16 petere Exp $ |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="SQL-DROPUSERMAPPING"> |
||||
<refmeta> |
||||
<refentrytitle id="sql-dropusermapping-title">DROP USER MAPPING</refentrytitle> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>DROP USER MAPPING</refname> |
||||
<refpurpose>remove a user mapping for a foreign server</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<indexterm zone="sql-dropusermapping"> |
||||
<primary>DROP USER MAPPING</primary> |
||||
</indexterm> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
DROP USER MAPPING [ IF EXISTS ] FOR { <replaceable class="parameter">username</replaceable> | USER | CURRENT_USER | PUBLIC } SERVER <replaceable class="parameter">servername</replaceable> |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>DROP USER MAPPING</command> removes an existing user |
||||
mapping from foreign server. To execute this command, the current |
||||
user must be the owner of the server containing the mapping. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><literal>IF EXISTS</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Do not throw an error if the user mapping does not exist. A |
||||
notice is issued in this case. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">username</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
User name of the mapping. <literal>CURRENT_USER</> |
||||
and <literal>USER</> match the name of the current |
||||
user. <literal>PUBLIC</> is used to match all present and |
||||
future user names in the system. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">servername</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
Server name of the user mapping. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
Drop a user mapping <literal>bob</>, server <literal>foo</> if it exists: |
||||
<programlisting> |
||||
DROP USER MAPPING IF EXISTS FOR bob SERVER foo; |
||||
</programlisting> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>DROP USER MAPPING</command> conforms to ISO/IEC 9075-9 |
||||
(SQL/MED). The <literal>IF EXISTS</> clause is |
||||
a <productname>PostgreSQL</> extension. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createusermapping" endterm="sql-createusermapping-title"></member> |
||||
<member><xref linkend="sql-alterusermapping" endterm="sql-alterusermapping-title"></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,25 @@ |
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile--
|
||||
# Makefile for foreign
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $PostgreSQL: pgsql/src/backend/foreign/Makefile,v 1.1 2008/12/19 16:25:17 petere Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
subdir = src/backend/foreign
|
||||
top_builddir = ../../..
|
||||
include $(top_builddir)/src/Makefile.global |
||||
|
||||
OBJS= foreign.o
|
||||
|
||||
include $(top_srcdir)/src/backend/common.mk |
||||
|
||||
FDW = dummy postgresql
|
||||
|
||||
$(addsuffix -fdw,all install installdirs uninstall distprep): |
||||
for dir in $(FDW); do $(MAKE) -C $$dir `echo $@ | sed 's/-fdw$$//'` || exit; done
|
||||
|
||||
clean distclean maintainer-clean: |
||||
for dir in $(FDW); do $(MAKE) -C $$dir $@ || exit; done
|
||||
@ -0,0 +1,27 @@ |
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile--
|
||||
# Makefile for dummy foreign-data wrapper
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $PostgreSQL: pgsql/src/backend/foreign/dummy/Makefile,v 1.1 2008/12/19 16:25:17 petere Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
subdir = src/backend/foreign/dummy
|
||||
top_builddir = ../../../..
|
||||
include $(top_builddir)/src/Makefile.global |
||||
|
||||
NAME = dummy_fdw
|
||||
OBJS = dummy_fdw.o
|
||||
|
||||
include $(top_srcdir)/src/Makefile.shlib |
||||
|
||||
all: all-shared-lib |
||||
|
||||
install: all install-lib |
||||
|
||||
installdirs: installdirs-lib |
||||
|
||||
clean distclean maintainer-clean: clean-lib |
||||
rm -f $(OBJS)
|
||||
@ -0,0 +1,24 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* dummy_fdw.c |
||||
* "dummy" foreign-data wrapper |
||||
* |
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group |
||||
* |
||||
* IDENTIFICATION |
||||
* $PostgreSQL: pgsql/src/backend/foreign/dummy/dummy_fdw.c,v 1.1 2008/12/19 16:25:17 petere Exp $ |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#include "postgres.h" |
||||
|
||||
#include "fmgr.h" |
||||
#include "foreign/foreign.h" |
||||
|
||||
PG_MODULE_MAGIC; |
||||
|
||||
/*
|
||||
* This looks like a complete waste right now, but it is useful for |
||||
* testing, and will become more interesting as more parts of the |
||||
* interface are implemented. |
||||
*/ |
||||
@ -0,0 +1,389 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* foreign.c |
||||
* support for foreign-data wrappers, servers and user mappings. |
||||
* |
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group |
||||
* |
||||
* IDENTIFICATION |
||||
* $PostgreSQL: pgsql/src/backend/foreign/foreign.c,v 1.1 2008/12/19 16:25:17 petere Exp $ |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#include "postgres.h" |
||||
|
||||
#include "access/reloptions.h" |
||||
#include "catalog/namespace.h" |
||||
#include "catalog/pg_foreign_data_wrapper.h" |
||||
#include "catalog/pg_foreign_server.h" |
||||
#include "catalog/pg_type.h" |
||||
#include "catalog/pg_user_mapping.h" |
||||
#include "foreign/foreign.h" |
||||
#include "funcapi.h" |
||||
#include "miscadmin.h" |
||||
#include "nodes/parsenodes.h" |
||||
#include "utils/acl.h" |
||||
#include "utils/array.h" |
||||
#include "utils/builtins.h" |
||||
#include "utils/lsyscache.h" |
||||
#include "utils/memutils.h" |
||||
#include "utils/syscache.h" |
||||
|
||||
|
||||
extern Datum pg_options_to_table(PG_FUNCTION_ARGS); |
||||
|
||||
|
||||
/* list of currently loaded foreign-data wrapper interfaces */ |
||||
static List *loaded_fdw_interfaces = NIL; |
||||
|
||||
|
||||
/*
|
||||
* GetForeignDataWrapperLibrary - return the named FDW library. If it |
||||
* is already loaded, use that. Otherwise allocate, initialize, and |
||||
* store in cache. |
||||
*/ |
||||
ForeignDataWrapperLibrary * |
||||
GetForeignDataWrapperLibrary(const char *libname) |
||||
{ |
||||
MemoryContext oldcontext; |
||||
void *libhandle = NULL; |
||||
ForeignDataWrapperLibrary *fdwl = NULL; |
||||
ListCell *cell; |
||||
|
||||
/* See if we have the FDW library is already loaded */ |
||||
foreach (cell, loaded_fdw_interfaces) |
||||
{ |
||||
fdwl = lfirst(cell); |
||||
if (strcmp(fdwl->libname, libname) == 0) |
||||
return fdwl; |
||||
} |
||||
|
||||
/*
|
||||
* We don't have it yet, so load and add. Attempt a load_file() |
||||
* first to filter out any missing or unloadable libraries. |
||||
*/ |
||||
load_file(libname, false); |
||||
|
||||
oldcontext = MemoryContextSwitchTo(TopMemoryContext); |
||||
|
||||
fdwl = palloc(sizeof(*fdwl)); |
||||
fdwl->libname = pstrdup(libname); |
||||
loaded_fdw_interfaces = lappend(loaded_fdw_interfaces, fdwl); |
||||
|
||||
MemoryContextSwitchTo(oldcontext); |
||||
|
||||
/*
|
||||
* Now look up the foreign data wrapper functions. |
||||
*/ |
||||
#define LOOKUP_FUNCTION(name) \ |
||||
(void *)(libhandle ? \
|
||||
lookup_external_function(libhandle, name) \
|
||||
: load_external_function(fdwl->libname, name, false, &libhandle)) |
||||
|
||||
fdwl->validateOptionList = LOOKUP_FUNCTION("_pg_validateOptionList"); |
||||
|
||||
return fdwl; |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* GetForeignDataWrapper - look up the foreign-data wrapper by OID. |
||||
* |
||||
* Here we also deal with loading the FDW library and looking up the |
||||
* actual functions. |
||||
*/ |
||||
ForeignDataWrapper * |
||||
GetForeignDataWrapper(Oid fdwid) |
||||
{ |
||||
Form_pg_foreign_data_wrapper fdwform; |
||||
ForeignDataWrapper *fdw; |
||||
Datum datum; |
||||
HeapTuple tp; |
||||
bool isnull; |
||||
|
||||
tp = SearchSysCache(FOREIGNDATAWRAPPEROID, |
||||
ObjectIdGetDatum(fdwid), |
||||
0, 0, 0); |
||||
|
||||
if (!HeapTupleIsValid(tp)) |
||||
elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid); |
||||
|
||||
fdwform = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp); |
||||
|
||||
fdw = palloc(sizeof(ForeignDataWrapper)); |
||||
fdw->fdwid = fdwid; |
||||
fdw->owner = fdwform->fdwowner; |
||||
fdw->fdwname = pstrdup(NameStr(fdwform->fdwname)); |
||||
|
||||
/* Extract library name */ |
||||
datum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID, |
||||
tp, |
||||
Anum_pg_foreign_data_wrapper_fdwlibrary, |
||||
&isnull); |
||||
fdw->fdwlibrary = pstrdup(TextDatumGetCString(datum)); |
||||
|
||||
fdw->lib = GetForeignDataWrapperLibrary(fdw->fdwlibrary); |
||||
|
||||
/* Extract the options */ |
||||
datum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID, |
||||
tp, |
||||
Anum_pg_foreign_data_wrapper_fdwoptions, |
||||
&isnull); |
||||
fdw->options = untransformRelOptions(datum); |
||||
|
||||
ReleaseSysCache(tp); |
||||
|
||||
return fdw; |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* GetForeignDataWrapperOidByName - look up the foreign-data wrapper |
||||
* OID by name. |
||||
*/ |
||||
Oid |
||||
GetForeignDataWrapperOidByName(const char *fdwname, bool missing_ok) |
||||
{ |
||||
Oid fdwId; |
||||
|
||||
fdwId = GetSysCacheOid(FOREIGNDATAWRAPPERNAME, |
||||
CStringGetDatum(fdwname), |
||||
0, 0, 0); |
||||
|
||||
if (!OidIsValid(fdwId) && !missing_ok) |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_UNDEFINED_OBJECT), |
||||
errmsg("foreign-data wrapper \"%s\" does not exist", fdwname))); |
||||
|
||||
return fdwId; |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* GetForeignDataWrapperByName - look up the foreign-data wrapper |
||||
* definition by name. |
||||
*/ |
||||
ForeignDataWrapper * |
||||
GetForeignDataWrapperByName(const char *fdwname, bool missing_ok) |
||||
{ |
||||
Oid fdwId = GetForeignDataWrapperOidByName(fdwname, missing_ok); |
||||
|
||||
if (!OidIsValid(fdwId) && missing_ok) |
||||
return NULL; |
||||
|
||||
return GetForeignDataWrapper(fdwId); |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* GetForeignServer - look up the foreign server definition. |
||||
*/ |
||||
ForeignServer * |
||||
GetForeignServer(Oid serverid) |
||||
{ |
||||
Form_pg_foreign_server serverform; |
||||
ForeignServer *server; |
||||
HeapTuple tp; |
||||
Datum datum; |
||||
bool isnull; |
||||
|
||||
tp = SearchSysCache(FOREIGNSERVEROID, |
||||
ObjectIdGetDatum(serverid), |
||||
0, 0, 0); |
||||
|
||||
if (!HeapTupleIsValid(tp)) |
||||
elog(ERROR, "cache lookup failed for foreign server %u", serverid); |
||||
|
||||
serverform = (Form_pg_foreign_server) GETSTRUCT(tp); |
||||
|
||||
server = palloc(sizeof(ForeignServer)); |
||||
server->serverid = serverid; |
||||
server->servername = pstrdup(NameStr(serverform->srvname)); |
||||
server->owner = serverform->srvowner; |
||||
server->fdwid = serverform->srvfdw; |
||||
|
||||
/* Extract server type */ |
||||
datum = SysCacheGetAttr(FOREIGNSERVEROID, |
||||
tp, |
||||
Anum_pg_foreign_server_srvtype, |
||||
&isnull); |
||||
server->servertype = isnull ? NULL : pstrdup(TextDatumGetCString(datum)); |
||||
|
||||
/* Extract server version */ |
||||
datum = SysCacheGetAttr(FOREIGNSERVEROID, |
||||
tp, |
||||
Anum_pg_foreign_server_srvversion, |
||||
&isnull); |
||||
server->serverversion = isnull ? NULL : pstrdup(TextDatumGetCString(datum)); |
||||
|
||||
/* Extract the srvoptions */ |
||||
datum = SysCacheGetAttr(FOREIGNSERVEROID, |
||||
tp, |
||||
Anum_pg_foreign_server_srvoptions, |
||||
&isnull); |
||||
|
||||
/* untransformRelOptions does exactly what we want - avoid duplication */ |
||||
server->options = untransformRelOptions(datum); |
||||
|
||||
ReleaseSysCache(tp); |
||||
|
||||
return server; |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* GetForeignServerByName - look up the foreign server oid by name. |
||||
*/ |
||||
Oid |
||||
GetForeignServerOidByName(const char *srvname, bool missing_ok) |
||||
{ |
||||
Oid serverid; |
||||
|
||||
serverid = GetSysCacheOid(FOREIGNSERVERNAME, |
||||
CStringGetDatum(srvname), |
||||
0, 0, 0); |
||||
|
||||
if (!OidIsValid(serverid) && !missing_ok) |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_UNDEFINED_OBJECT), |
||||
errmsg("server \"%s\" does not exist", srvname))); |
||||
|
||||
return serverid; |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* GetForeignServerByName - look up the foreign server definition by name. |
||||
*/ |
||||
ForeignServer * |
||||
GetForeignServerByName(const char *srvname, bool missing_ok) |
||||
{ |
||||
Oid serverid = GetForeignServerOidByName(srvname, missing_ok); |
||||
|
||||
if (!OidIsValid(serverid) && missing_ok) |
||||
return NULL; |
||||
|
||||
return GetForeignServer(serverid); |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* GetUserMapping - look up the user mapping. |
||||
* |
||||
* If no mapping is found for the supplied user, we also look for |
||||
* PUBLIC mappings (userid == InvalidOid). |
||||
*/ |
||||
UserMapping * |
||||
GetUserMapping(Oid userid, Oid serverid) |
||||
{ |
||||
Form_pg_user_mapping umform; |
||||
Datum datum; |
||||
HeapTuple tp; |
||||
bool isnull; |
||||
UserMapping *um; |
||||
|
||||
tp = SearchSysCache(USERMAPPINGUSERSERVER, |
||||
ObjectIdGetDatum(userid), |
||||
ObjectIdGetDatum(serverid), |
||||
0, 0); |
||||
|
||||
if (!HeapTupleIsValid(tp)) |
||||
{ |
||||
/* Not found for the specific user -- try PUBLIC */ |
||||
tp = SearchSysCache(USERMAPPINGUSERSERVER, |
||||
ObjectIdGetDatum(InvalidOid), |
||||
ObjectIdGetDatum(serverid), |
||||
0, 0); |
||||
} |
||||
|
||||
if (!HeapTupleIsValid(tp)) |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_UNDEFINED_OBJECT), |
||||
errmsg("user mapping not found for \"%s\"", |
||||
MappingUserName(userid)))); |
||||
|
||||
umform = (Form_pg_user_mapping) GETSTRUCT(tp); |
||||
|
||||
/* Extract the umoptions */ |
||||
datum = SysCacheGetAttr(USERMAPPINGUSERSERVER, |
||||
tp, |
||||
Anum_pg_user_mapping_umoptions, |
||||
&isnull); |
||||
|
||||
um = palloc(sizeof(UserMapping)); |
||||
um->userid = userid; |
||||
um->serverid = serverid; |
||||
um->options = untransformRelOptions(datum); |
||||
|
||||
ReleaseSysCache(tp); |
||||
|
||||
return um; |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* deflist_to_tuplestore - Helper function to convert DefElem list to |
||||
* tuplestore usable in SRF. |
||||
*/ |
||||
static void |
||||
deflist_to_tuplestore(ReturnSetInfo *rsinfo, List *options) |
||||
{ |
||||
ListCell *cell; |
||||
TupleDesc tupdesc; |
||||
Tuplestorestate *tupstore; |
||||
Datum values[2]; |
||||
bool nulls[2] = { 0 }; |
||||
MemoryContext per_query_ctx; |
||||
MemoryContext oldcontext; |
||||
|
||||
/* check to see if caller supports us returning a tuplestore */ |
||||
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
||||
errmsg("set-valued function called in context that cannot accept a set"))); |
||||
if (!(rsinfo->allowedModes & SFRM_Materialize)) |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
||||
errmsg("materialize mode required, but it is not allowed in this context"))); |
||||
|
||||
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory; |
||||
oldcontext = MemoryContextSwitchTo(per_query_ctx); |
||||
|
||||
/*
|
||||
* Now prepare the result set. |
||||
*/ |
||||
tupdesc = CreateTupleDescCopy(rsinfo->expectedDesc); |
||||
tupstore = tuplestore_begin_heap(true, false, work_mem); |
||||
rsinfo->returnMode = SFRM_Materialize; |
||||
rsinfo->setResult = tupstore; |
||||
rsinfo->setDesc = tupdesc; |
||||
|
||||
foreach (cell, options) |
||||
{ |
||||
DefElem *def = lfirst(cell); |
||||
|
||||
values[0] = CStringGetTextDatum(def->defname); |
||||
values[1] = CStringGetTextDatum(((Value *)def->arg)->val.str); |
||||
tuplestore_putvalues(tupstore, tupdesc, values, nulls); |
||||
} |
||||
|
||||
/* clean up and return the tuplestore */ |
||||
tuplestore_donestoring(tupstore); |
||||
|
||||
MemoryContextSwitchTo(oldcontext); |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* Convert options array to name/value table. Useful for information |
||||
* schema and pg_dump. |
||||
*/ |
||||
Datum |
||||
pg_options_to_table(PG_FUNCTION_ARGS) |
||||
{ |
||||
Datum array = PG_GETARG_DATUM(0); |
||||
|
||||
deflist_to_tuplestore((ReturnSetInfo *) fcinfo->resultinfo, untransformRelOptions(array)); |
||||
|
||||
return (Datum) 0; |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile--
|
||||
# Makefile for postgresql foreign-data wrapper
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $PostgreSQL: pgsql/src/backend/foreign/postgresql/Makefile,v 1.1 2008/12/19 16:25:17 petere Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
subdir = src/backend/foreign/postgresql
|
||||
top_builddir = ../../../..
|
||||
include $(top_builddir)/src/Makefile.global |
||||
|
||||
NAME = postgresql_fdw
|
||||
OBJS = postgresql_fdw.o
|
||||
|
||||
include $(top_srcdir)/src/Makefile.shlib |
||||
|
||||
all: all-shared-lib |
||||
|
||||
install: all install-lib |
||||
|
||||
installdirs: installdirs-lib |
||||
|
||||
clean distclean maintainer-clean: clean-lib |
||||
rm -f $(OBJS)
|
||||
@ -0,0 +1,123 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* postgresql_fdw.c |
||||
* foreign-data wrapper for postgresql (libpq) connections. |
||||
* |
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group |
||||
* |
||||
* IDENTIFICATION |
||||
* $PostgreSQL: pgsql/src/backend/foreign/postgresql/postgresql_fdw.c,v 1.1 2008/12/19 16:25:17 petere Exp $ |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#include "postgres.h" |
||||
|
||||
#include "fmgr.h" |
||||
#include "lib/stringinfo.h" |
||||
#include "nodes/value.h" |
||||
#include "nodes/parsenodes.h" |
||||
#include "nodes/makefuncs.h" |
||||
#include "foreign/foreign.h" |
||||
|
||||
PG_MODULE_MAGIC; |
||||
|
||||
|
||||
/*
|
||||
* Describes the valid options for postgresql FDW, server and user mapping. |
||||
*/ |
||||
typedef struct ConnectionOptions { |
||||
const char *optname; /* Option name */ |
||||
GenericOptionFlags optflags; /* Option usage bitmap */ |
||||
} ConnectionOptions; |
||||
|
||||
/*
|
||||
* Copied from fe-connect.c PQconninfoOptions. |
||||
* |
||||
* The list is small - don't bother with bsearch if it stays so. |
||||
*/ |
||||
static ConnectionOptions libpq_conninfo_options[] = { |
||||
{ "authtype", ServerOpt }, |
||||
{ "service", ServerOpt }, |
||||
{ "user", UserMappingOpt }, |
||||
{ "password", UserMappingOpt }, |
||||
{ "connect_timeout", ServerOpt }, |
||||
{ "dbname", ServerOpt }, |
||||
{ "host", ServerOpt }, |
||||
{ "hostaddr", ServerOpt }, |
||||
{ "port", ServerOpt }, |
||||
{ "tty", ServerOpt }, |
||||
{ "options", ServerOpt }, |
||||
{ "requiressl", ServerOpt }, |
||||
{ "sslmode", ServerOpt }, |
||||
{ "gsslib", ServerOpt }, |
||||
{ NULL, InvalidOpt } |
||||
}; |
||||
|
||||
void _PG_fini(void); |
||||
|
||||
|
||||
/*
|
||||
* Check if the provided option is one of libpq conninfo options. |
||||
* We look at only options with matching flags. |
||||
*/ |
||||
static bool |
||||
is_conninfo_option(const char *option, GenericOptionFlags flags) |
||||
{ |
||||
ConnectionOptions *opt; |
||||
|
||||
for (opt = libpq_conninfo_options; opt->optname != NULL; opt++) |
||||
if (flags & opt->optflags && strcmp(opt->optname, option) == 0) |
||||
return true; |
||||
return false; |
||||
} |
||||
|
||||
/*
|
||||
* Validate the generic option given to SERVER or USER MAPPING. |
||||
* Raise an ERROR if the option or its value is considered |
||||
* invalid. |
||||
* |
||||
* Valid server options are all libpq conninfo options except |
||||
* user and password -- these may only appear in USER MAPPING options. |
||||
*/ |
||||
void |
||||
_pg_validateOptionList(ForeignDataWrapper *fdw, GenericOptionFlags flags, |
||||
List *options) |
||||
{ |
||||
ListCell *cell; |
||||
|
||||
foreach (cell, options) |
||||
{ |
||||
DefElem *def = lfirst(cell); |
||||
|
||||
if (!is_conninfo_option(def->defname, flags)) |
||||
{ |
||||
ConnectionOptions *opt; |
||||
StringInfoData buf; |
||||
const char *objtype; |
||||
|
||||
/*
|
||||
* Unknown option specified, complain about it. Provide a hint |
||||
* with list of valid options for the object. |
||||
*/ |
||||
initStringInfo(&buf); |
||||
for (opt = libpq_conninfo_options; opt->optname != NULL; opt++) |
||||
if (flags & opt->optflags) |
||||
appendStringInfo(&buf, "%s%s", (buf.len > 0) ? ", " : "", |
||||
opt->optname); |
||||
|
||||
if (flags & ServerOpt) |
||||
objtype = "server"; |
||||
else if (flags & UserMappingOpt) |
||||
objtype = "user mapping"; |
||||
else if (flags & FdwOpt) |
||||
objtype = "foreign-data wrapper"; |
||||
else |
||||
objtype = "???"; |
||||
|
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_SYNTAX_ERROR), |
||||
errmsg("invalid option \"%s\" to %s", def->defname, objtype), |
||||
errhint("valid %s options are: %s", objtype, buf.data))); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,62 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pg_foreign_data_wrapper.h |
||||
* definition of the system "foreign-data wrapper" relation (pg_foreign_data_wrapper) |
||||
* along with the relation's initial contents. |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* $PostgreSQL: pgsql/src/include/catalog/pg_foreign_data_wrapper.h,v 1.1 2008/12/19 16:25:18 petere Exp $ |
||||
* |
||||
* NOTES |
||||
* the genbki.sh script reads this file and generates .bki |
||||
* information from the DATA() statements. |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PG_FOREIGN_DATA_WRAPPER_H |
||||
#define PG_FOREIGN_DATA_WRAPPER_H |
||||
|
||||
#include "catalog/genbki.h" |
||||
|
||||
/* ----------------
|
||||
* pg_foreign_data_wrapper definition. cpp turns this into |
||||
* typedef struct FormData_pg_foreign_data_wrapper |
||||
* ---------------- |
||||
*/ |
||||
#define ForeignDataWrapperRelationId 2328 |
||||
|
||||
CATALOG(pg_foreign_data_wrapper,2328) |
||||
{ |
||||
NameData fdwname; /* foreign-data wrapper name */ |
||||
Oid fdwowner; /* FDW owner */ |
||||
|
||||
/* VARIABLE LENGTH FIELDS start here. */ |
||||
|
||||
text fdwlibrary; /* FDW shared library location */ |
||||
aclitem fdwacl[1]; /* access permissions */ |
||||
text fdwoptions[1]; /* FDW options */ |
||||
} FormData_pg_foreign_data_wrapper; |
||||
|
||||
/* ----------------
|
||||
* Form_pg_fdw corresponds to a pointer to a tuple with |
||||
* the format of pg_fdw relation. |
||||
* ---------------- |
||||
*/ |
||||
typedef FormData_pg_foreign_data_wrapper *Form_pg_foreign_data_wrapper; |
||||
|
||||
/* ----------------
|
||||
* compiler constants for pg_fdw |
||||
* ---------------- |
||||
*/ |
||||
|
||||
#define Natts_pg_foreign_data_wrapper 5 |
||||
#define Anum_pg_foreign_data_wrapper_fdwname 1 |
||||
#define Anum_pg_foreign_data_wrapper_fdwowner 2 |
||||
#define Anum_pg_foreign_data_wrapper_fdwlibrary 3 |
||||
#define Anum_pg_foreign_data_wrapper_fdwacl 4 |
||||
#define Anum_pg_foreign_data_wrapper_fdwoptions 5 |
||||
|
||||
#endif /* PG_FOREIGN_DATA_WRAPPER_H */ |
||||
@ -0,0 +1,65 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pg_foreign_server.h |
||||
* definition of the system "foreign server" relation (pg_foreign_server) |
||||
* |
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* $PostgreSQL: pgsql/src/include/catalog/pg_foreign_server.h,v 1.1 2008/12/19 16:25:18 petere Exp $ |
||||
* |
||||
* NOTES |
||||
* the genbki.sh script reads this file and generates .bki |
||||
* information from the DATA() statements. |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PG_FOREIGN_SERVER_H |
||||
#define PG_FOREIGN_SERVER_H |
||||
|
||||
#include "catalog/genbki.h" |
||||
|
||||
/* ----------------
|
||||
* pg_foreign_server definition. cpp turns this into |
||||
* typedef struct FormData_pg_foreign_server |
||||
* ---------------- |
||||
*/ |
||||
#define ForeignServerRelationId 1417 |
||||
|
||||
CATALOG(pg_foreign_server,1417) |
||||
{ |
||||
NameData srvname; /* foreign server name */ |
||||
Oid srvowner; /* server owner */ |
||||
Oid srvfdw; /* server FDW */ |
||||
|
||||
/*
|
||||
* VARIABLE LENGTH FIELDS start here. These fields may be NULL, too. |
||||
*/ |
||||
text srvtype; |
||||
text srvversion; |
||||
aclitem srvacl[1]; /* access permissions */ |
||||
text srvoptions[1]; /* FDW-specific options */ |
||||
} FormData_pg_foreign_server; |
||||
|
||||
/* ----------------
|
||||
* Form_pg_foreign_server corresponds to a pointer to a tuple with |
||||
* the format of pg_foreign_server relation. |
||||
* ---------------- |
||||
*/ |
||||
typedef FormData_pg_foreign_server *Form_pg_foreign_server; |
||||
|
||||
/* ----------------
|
||||
* compiler constants for pg_foreign_server |
||||
* ---------------- |
||||
*/ |
||||
|
||||
#define Natts_pg_foreign_server 7 |
||||
#define Anum_pg_foreign_server_srvname 1 |
||||
#define Anum_pg_foreign_server_srvowner 2 |
||||
#define Anum_pg_foreign_server_srvfdw 3 |
||||
#define Anum_pg_foreign_server_srvtype 4 |
||||
#define Anum_pg_foreign_server_srvversion 5 |
||||
#define Anum_pg_foreign_server_srvacl 6 |
||||
#define Anum_pg_foreign_server_srvoptions 7 |
||||
|
||||
#endif /* PG_FOREIGN_SERVER_H */ |
||||
@ -0,0 +1,58 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pg_user_mapping.h |
||||
* definition of the system "user mapping" relation (pg_user_mapping) |
||||
* |
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* $PostgreSQL: pgsql/src/include/catalog/pg_user_mapping.h,v 1.1 2008/12/19 16:25:19 petere Exp $ |
||||
* |
||||
* NOTES |
||||
* the genbki.sh script reads this file and generates .bki |
||||
* information from the DATA() statements. |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PG_USER_MAPPING_H |
||||
#define PG_USER_MAPPING_H |
||||
|
||||
#include "catalog/genbki.h" |
||||
|
||||
/* ----------------
|
||||
* pg_user_mapping definition. cpp turns this into |
||||
* typedef struct FormData_pg_user_mapping |
||||
* ---------------- |
||||
*/ |
||||
#define UserMappingRelationId 1418 |
||||
|
||||
CATALOG(pg_user_mapping,1418) |
||||
{ |
||||
Oid umuser; /* Id of the user, InvalidOid if PUBLIC is wanted */ |
||||
Oid umserver; /* server of this mapping */ |
||||
|
||||
/*
|
||||
* VARIABLE LENGTH FIELDS start here. These fields may be NULL, too. |
||||
*/ |
||||
|
||||
text umoptions[1]; /* user mapping options */ |
||||
} FormData_pg_user_mapping; |
||||
|
||||
/* ----------------
|
||||
* Form_pg_user_mapping corresponds to a pointer to a tuple with |
||||
* the format of pg_user_mapping relation. |
||||
* ---------------- |
||||
*/ |
||||
typedef FormData_pg_user_mapping *Form_pg_user_mapping; |
||||
|
||||
/* ----------------
|
||||
* compiler constants for pg_user_mapping |
||||
* ---------------- |
||||
*/ |
||||
|
||||
#define Natts_pg_user_mapping 3 |
||||
#define Anum_pg_user_mapping_umuser 1 |
||||
#define Anum_pg_user_mapping_umserver 2 |
||||
#define Anum_pg_user_mapping_umoptions 3 |
||||
|
||||
#endif /* PG_USER_MAPPING_H */ |
||||
@ -0,0 +1,101 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* foreign.h |
||||
* support for foreign-data wrappers, servers and user mappings. |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group |
||||
* |
||||
* $PostgreSQL: pgsql/src/include/foreign/foreign.h,v 1.1 2008/12/19 16:25:19 petere Exp $ |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef FOREIGN_H |
||||
#define FOREIGN_H |
||||
|
||||
#include "nodes/parsenodes.h" |
||||
#include "nodes/pg_list.h" |
||||
|
||||
|
||||
/* Helper for obtaining username for user mapping */ |
||||
#define MappingUserName(userid) \ |
||||
(OidIsValid(userid) ? GetUserNameFromId(userid) : "public") |
||||
|
||||
|
||||
/*
|
||||
* Generic option types for validation. |
||||
* NB! Thes are treated as flags, so use only powers of two here. |
||||
*/ |
||||
typedef enum { |
||||
InvalidOpt = 0, |
||||
ServerOpt = 1, /* options applicable to SERVER */ |
||||
UserMappingOpt = 2, /* options for USER MAPPING */ |
||||
FdwOpt = 4, /* options for FOREIGN DATA WRAPPER */ |
||||
} GenericOptionFlags; |
||||
|
||||
typedef struct ForeignDataWrapperLibrary ForeignDataWrapperLibrary; |
||||
|
||||
typedef struct ForeignDataWrapper |
||||
{ |
||||
Oid fdwid; /* FDW Oid */ |
||||
Oid owner; /* FDW owner user Oid */ |
||||
char *fdwname; /* Name of the FDW */ |
||||
char *fdwlibrary; /* Library name */ |
||||
List *options; /* fdwoptions as DefElem list */ |
||||
|
||||
ForeignDataWrapperLibrary *lib; /* interface to the FDW functions */ |
||||
} ForeignDataWrapper; |
||||
|
||||
typedef struct ForeignServer |
||||
{ |
||||
Oid serverid; /* server Oid */ |
||||
Oid fdwid; /* foreign-data wrapper */ |
||||
Oid owner; /* server owner user Oid */ |
||||
char *servername; /* name of the server */ |
||||
char *servertype; /* server type, optional */ |
||||
char *serverversion; /* server version, optional */ |
||||
List *options; /* srvoptions as DefElem list */ |
||||
} ForeignServer; |
||||
|
||||
typedef struct UserMapping |
||||
{ |
||||
Oid userid; /* local user Oid */ |
||||
Oid serverid; /* server Oid */ |
||||
List *options; /* useoptions as DefElem list */ |
||||
} UserMapping; |
||||
|
||||
|
||||
/*
|
||||
* Foreign-data wrapper library function types. |
||||
*/ |
||||
typedef void (*OptionListValidatorFunc)(ForeignDataWrapper *, |
||||
GenericOptionFlags, |
||||
List *); |
||||
|
||||
/*
|
||||
* Interface functions to the foreign-data wrapper. This is decoupled |
||||
* from the FDW as there maybe several FDW-s accessing the same library. |
||||
*/ |
||||
struct ForeignDataWrapperLibrary |
||||
{ |
||||
char *libname; /* name of the library file */ |
||||
|
||||
OptionListValidatorFunc validateOptionList; |
||||
}; |
||||
|
||||
|
||||
extern ForeignServer *GetForeignServer(Oid serverid); |
||||
extern ForeignServer *GetForeignServerByName(const char *name, bool missing_ok); |
||||
extern Oid GetForeignServerOidByName(const char *name, bool missing_ok); |
||||
extern UserMapping *GetUserMapping(Oid userid, Oid serverid); |
||||
extern ForeignDataWrapper *GetForeignDataWrapper(Oid fdwid); |
||||
extern ForeignDataWrapper *GetForeignDataWrapperByName(const char *name, |
||||
bool missing_ok); |
||||
extern Oid GetForeignDataWrapperOidByName(const char *name, bool missing_ok); |
||||
extern ForeignDataWrapperLibrary *GetForeignDataWrapperLibrary(const char *libname); |
||||
|
||||
/* Foreign data wrapper interface functions */ |
||||
extern void _pg_validateOptionList(ForeignDataWrapper *fdw, |
||||
GenericOptionFlags flags, List *options); |
||||
|
||||
#endif /* FOREIGN_H */ |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,396 @@ |
||||
-- |
||||
-- Test foreign-data wrapper and server management. |
||||
-- |
||||
|
||||
-- Clean up in case a prior regression run failed |
||||
|
||||
-- Suppress NOTICE messages when roles don't exist |
||||
SET client_min_messages TO 'error'; |
||||
|
||||
DROP ROLE IF EXISTS foreign_data_user, regress_test_role, regress_test_role2, regress_test_role_super, regress_test_indirect, unpriviled_role; |
||||
|
||||
RESET client_min_messages; |
||||
|
||||
CREATE ROLE foreign_data_user LOGIN SUPERUSER; |
||||
SET SESSION AUTHORIZATION 'foreign_data_user'; |
||||
|
||||
CREATE ROLE regress_test_role; |
||||
CREATE ROLE regress_test_role2; |
||||
CREATE ROLE regress_test_role_super SUPERUSER; |
||||
CREATE ROLE regress_test_indirect; |
||||
CREATE ROLE unprivileged_role; |
||||
|
||||
CREATE FOREIGN DATA WRAPPER dummy LIBRARY 'dummy_fdw' LANGUAGE C; |
||||
CREATE FOREIGN DATA WRAPPER postgresql LIBRARY 'postgresql_fdw' LANGUAGE C; |
||||
|
||||
-- At this point we should have 2 built-in wrappers and no servers. |
||||
SELECT fdwname, fdwlibrary, fdwoptions FROM pg_foreign_data_wrapper ORDER BY 1, 2, 3; |
||||
SELECT srvname, srvoptions FROM pg_foreign_server; |
||||
SELECT * FROM pg_user_mapping; |
||||
|
||||
-- CREATE FOREIGN DATA WRAPPER |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY '' LANGUAGE C; -- ERROR |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'plpgsql' LANGUAGE C; |
||||
DROP FOREIGN DATA WRAPPER foo; |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw' LANGUAGE C; |
||||
\dew |
||||
|
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw' LANGUAGE C; -- duplicate |
||||
CREATE FOREIGN DATA WRAPPER "Foo" LIBRARY 'dummy_fdw' LANGUAGE C; |
||||
DROP FOREIGN DATA WRAPPER "Foo"; |
||||
DROP FOREIGN DATA WRAPPER foo; |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw' LANGUAGE C OPTIONS (testing '1'); |
||||
\dew+ |
||||
|
||||
DROP FOREIGN DATA WRAPPER foo; |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw' LANGUAGE C OPTIONS (testing '1', testing '2'); -- ERROR |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw' LANGUAGE C OPTIONS (testing '1', another '2'); |
||||
\dew+ |
||||
|
||||
DROP FOREIGN DATA WRAPPER foo; |
||||
SET ROLE regress_test_role; |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw' LANGUAGE C; -- ERROR |
||||
RESET ROLE; |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'postgresql_fdw' LANGUAGE C; |
||||
\dew+ |
||||
|
||||
-- ALTER FOREIGN DATA WRAPPER |
||||
ALTER FOREIGN DATA WRAPPER foo LIBRARY ''; -- ERROR |
||||
ALTER FOREIGN DATA WRAPPER foo LIBRARY 'plpgsql'; |
||||
ALTER FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw'; |
||||
\dew+ |
||||
|
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (a '1', b '2'); |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (SET c '4'); -- ERROR |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (DROP c); -- ERROR |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD x '1', DROP x); |
||||
\dew+ |
||||
|
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (DROP a, SET b '3', ADD c '4'); |
||||
\dew+ |
||||
|
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (a '2'); |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (b '4'); -- ERROR |
||||
\dew+ |
||||
|
||||
SET ROLE regress_test_role; |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD d '5'); -- ERROR |
||||
SET ROLE regress_test_role_super; |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD d '5'); |
||||
\dew+ |
||||
|
||||
ALTER FOREIGN DATA WRAPPER foo OWNER TO regress_test_role; -- ERROR |
||||
ALTER FOREIGN DATA WRAPPER foo OWNER TO regress_test_role_super; |
||||
ALTER ROLE regress_test_role_super NOSUPERUSER; |
||||
SET ROLE regress_test_role_super; |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD e '6'); -- ERROR |
||||
RESET ROLE; |
||||
\dew+ |
||||
|
||||
-- DROP FOREIGN DATA WRAPPER |
||||
DROP FOREIGN DATA WRAPPER nonexistent; -- ERROR |
||||
DROP FOREIGN DATA WRAPPER IF EXISTS nonexistent; |
||||
\dew+ |
||||
|
||||
DROP ROLE regress_test_role_super; -- ERROR |
||||
SET ROLE regress_test_role_super; |
||||
DROP FOREIGN DATA WRAPPER foo; -- ERROR |
||||
RESET ROLE; |
||||
ALTER ROLE regress_test_role_super SUPERUSER; |
||||
DROP FOREIGN DATA WRAPPER foo; |
||||
DROP ROLE regress_test_role_super; |
||||
\dew+ |
||||
|
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw' LANGUAGE C; |
||||
CREATE SERVER s1 FOREIGN DATA WRAPPER foo; |
||||
CREATE USER MAPPING FOR current_user SERVER s1; |
||||
\dew+ |
||||
\des+ |
||||
\deu+ |
||||
DROP FOREIGN DATA WRAPPER foo; -- ERROR |
||||
SET ROLE regress_test_role; |
||||
DROP FOREIGN DATA WRAPPER foo CASCADE; -- ERROR |
||||
RESET ROLE; |
||||
DROP FOREIGN DATA WRAPPER foo CASCADE; |
||||
\dew+ |
||||
\des+ |
||||
\deu+ |
||||
|
||||
-- exercise CREATE SERVER |
||||
CREATE SERVER s1 FOREIGN DATA WRAPPER foo; -- ERROR |
||||
CREATE FOREIGN DATA WRAPPER foo LIBRARY 'dummy_fdw' LANGUAGE C OPTIONS (test_wrapper 'true'); |
||||
CREATE SERVER s1 FOREIGN DATA WRAPPER foo; |
||||
CREATE SERVER s1 FOREIGN DATA WRAPPER foo; -- ERROR |
||||
CREATE SERVER s2 FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbname 'b'); |
||||
CREATE SERVER s3 TYPE 'oracle' FOREIGN DATA WRAPPER foo; |
||||
CREATE SERVER s4 TYPE 'oracle' FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbname 'b'); |
||||
CREATE SERVER s5 VERSION '15.0' FOREIGN DATA WRAPPER foo; |
||||
CREATE SERVER s6 VERSION '16.0' FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbname 'b'); |
||||
CREATE SERVER "S6" FOREIGN DATA WRAPPER foo OPTIONS (mixed_case_names 'true'); |
||||
CREATE SERVER s7 TYPE 'oracle' VERSION '17.0' FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbname 'b'); |
||||
CREATE SERVER s8 FOREIGN DATA WRAPPER postgresql OPTIONS (foo '1'); -- ERROR |
||||
CREATE SERVER s8 FOREIGN DATA WRAPPER postgresql OPTIONS (host 'localhost', dbname 's8db'); |
||||
\des+ |
||||
SET ROLE regress_test_role; |
||||
CREATE SERVER st1 FOREIGN DATA WRAPPER foo; -- ERROR: no usage on FDW |
||||
RESET ROLE; |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER foo TO regress_test_role; |
||||
SET ROLE regress_test_role; |
||||
CREATE SERVER st1 FOREIGN DATA WRAPPER foo; |
||||
RESET ROLE; |
||||
\des+ |
||||
|
||||
REVOKE USAGE ON FOREIGN DATA WRAPPER foo FROM regress_test_role; |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER foo TO regress_test_indirect; |
||||
SET ROLE regress_test_role; |
||||
CREATE SERVER st2 FOREIGN DATA WRAPPER foo; -- ERROR |
||||
RESET ROLE; |
||||
GRANT regress_test_indirect TO regress_test_role; |
||||
SET ROLE regress_test_role; |
||||
CREATE SERVER st2 FOREIGN DATA WRAPPER foo; |
||||
\des+ |
||||
RESET ROLE; |
||||
REVOKE regress_test_indirect FROM regress_test_role; |
||||
|
||||
-- ALTER SERVER |
||||
ALTER SERVER s0; -- ERROR |
||||
ALTER SERVER s0 OPTIONS (a '1'); -- ERROR |
||||
ALTER SERVER s1 VERSION '1.0' OPTIONS (servername 's1'); |
||||
ALTER SERVER s2 VERSION '1.1'; |
||||
ALTER SERVER s3 OPTIONS (tnsname 'orcl', port '1521'); |
||||
GRANT USAGE ON FOREIGN SERVER s1 TO regress_test_role; |
||||
GRANT USAGE ON FOREIGN SERVER s6 TO regress_test_role2 WITH GRANT OPTION; |
||||
\des+ |
||||
SET ROLE regress_test_role; |
||||
ALTER SERVER s1 VERSION '1.1'; -- ERROR |
||||
ALTER SERVER s1 OWNER TO regress_test_role; -- ERROR |
||||
RESET ROLE; |
||||
ALTER SERVER s1 OWNER TO regress_test_role; |
||||
GRANT regress_test_role2 TO regress_test_role; |
||||
SET ROLE regress_test_role; |
||||
ALTER SERVER s1 VERSION '1.1'; |
||||
ALTER SERVER s1 OWNER TO regress_test_role2; -- ERROR |
||||
RESET ROLE; |
||||
ALTER SERVER s8 OPTIONS (foo '1'); -- ERROR option validation |
||||
ALTER SERVER s8 OPTIONS (connect_timeout '30', SET dbname 'db1', DROP host); |
||||
SET ROLE regress_test_role; |
||||
ALTER SERVER s1 OWNER TO regress_test_indirect; -- ERROR |
||||
RESET ROLE; |
||||
GRANT regress_test_indirect TO regress_test_role; |
||||
SET ROLE regress_test_role; |
||||
ALTER SERVER s1 OWNER TO regress_test_indirect; |
||||
RESET ROLE; |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER foo TO regress_test_indirect; |
||||
SET ROLE regress_test_role; |
||||
ALTER SERVER s1 OWNER TO regress_test_indirect; |
||||
RESET ROLE; |
||||
DROP ROLE regress_test_indirect; -- ERROR |
||||
\des+ |
||||
|
||||
-- DROP SERVER |
||||
DROP SERVER nonexistent; -- ERROR |
||||
DROP SERVER IF EXISTS nonexistent; |
||||
\des |
||||
SET ROLE regress_test_role; |
||||
DROP SERVER s2; -- ERROR |
||||
DROP SERVER s1; |
||||
RESET ROLE; |
||||
\des |
||||
ALTER SERVER s2 OWNER TO regress_test_role; |
||||
SET ROLE regress_test_role; |
||||
DROP SERVER s2; |
||||
RESET ROLE; |
||||
\des |
||||
CREATE USER MAPPING FOR current_user SERVER s3; |
||||
\deu |
||||
DROP SERVER s3; -- ERROR |
||||
DROP SERVER s3 CASCADE; |
||||
\des |
||||
\deu |
||||
|
||||
-- CREATE USER MAPPING |
||||
CREATE USER MAPPING FOR baz SERVER s1; -- ERROR |
||||
CREATE USER MAPPING FOR current_user SERVER s1; -- ERROR |
||||
CREATE USER MAPPING FOR current_user SERVER s4; |
||||
CREATE USER MAPPING FOR user SERVER s4; -- ERROR duplicate |
||||
CREATE USER MAPPING FOR public SERVER s4 OPTIONS (mapping 'is public'); |
||||
CREATE USER MAPPING FOR user SERVER s8 OPTIONS (username 'test', password 'secret'); -- ERROR |
||||
CREATE USER MAPPING FOR user SERVER s8 OPTIONS (user 'test', password 'secret'); |
||||
ALTER SERVER s5 OWNER TO regress_test_role; |
||||
ALTER SERVER s6 OWNER TO regress_test_indirect; |
||||
SET ROLE regress_test_role; |
||||
CREATE USER MAPPING FOR current_user SERVER s5; |
||||
CREATE USER MAPPING FOR current_user SERVER s6 OPTIONS (username 'test'); |
||||
CREATE USER MAPPING FOR current_user SERVER s7; -- ERROR |
||||
CREATE USER MAPPING FOR public SERVER s8; -- ERROR |
||||
RESET ROLE; |
||||
CREATE USER MAPPING FOR current_user SERVER "S6" OPTIONS (username 'test_mixed_case'); |
||||
|
||||
ALTER SERVER st1 OWNER TO regress_test_indirect; |
||||
SET ROLE regress_test_role; |
||||
CREATE USER MAPPING FOR current_user SERVER st1 OPTIONS (username 'bob', password 'boo'); |
||||
CREATE USER MAPPING FOR public SERVER st1; |
||||
RESET ROLE; |
||||
\deu |
||||
|
||||
-- ALTER USER MAPPING |
||||
ALTER USER MAPPING FOR bob SERVER s4 OPTIONS (gotcha 'true'); -- ERROR |
||||
ALTER USER MAPPING FOR user SERVER ss4 OPTIONS (gotcha 'true'); -- ERROR |
||||
ALTER USER MAPPING FOR public SERVER s5 OPTIONS (gotcha 'true'); -- ERROR |
||||
ALTER USER MAPPING FOR current_user SERVER s8 OPTIONS (username 'test'); -- ERROR |
||||
ALTER USER MAPPING FOR current_user SERVER s8 OPTIONS (DROP user, SET password 'public'); |
||||
SET ROLE regress_test_role; |
||||
ALTER USER MAPPING FOR current_user SERVER s5 OPTIONS (ADD modified '1'); |
||||
ALTER USER MAPPING FOR public SERVER s4 OPTIONS (ADD modified '1'); -- ERROR |
||||
ALTER USER MAPPING FOR public SERVER st1 OPTIONS (ADD modified '1'); |
||||
RESET ROLE; |
||||
\deu+ |
||||
|
||||
-- DROP USER MAPPING |
||||
DROP USER MAPPING FOR bob SERVER s4; -- ERROR |
||||
DROP USER MAPPING FOR user SERVER ss4; |
||||
DROP USER MAPPING FOR public SERVER s7; -- ERROR |
||||
DROP USER MAPPING IF EXISTS FOR bob SERVER s4; |
||||
DROP USER MAPPING IF EXISTS FOR user SERVER ss4; |
||||
DROP USER MAPPING IF EXISTS FOR public SERVER s7; |
||||
CREATE USER MAPPING FOR public SERVER s8; |
||||
SET ROLE regress_test_role; |
||||
DROP USER MAPPING FOR public SERVER s8; -- ERROR |
||||
RESET ROLE; |
||||
DROP SERVER s7; |
||||
\deu |
||||
|
||||
-- Information schema |
||||
|
||||
SELECT * FROM information_schema.foreign_data_wrappers ORDER BY 1, 2; |
||||
SELECT * FROM information_schema.foreign_data_wrapper_options ORDER BY 1, 2, 3; |
||||
SELECT * FROM information_schema.foreign_servers ORDER BY 1, 2; |
||||
SELECT * FROM information_schema.foreign_server_options ORDER BY 1, 2, 3; |
||||
SELECT * FROM information_schema.user_mappings ORDER BY 1, 2, 3; |
||||
SELECT * FROM information_schema.user_mapping_options ORDER BY 1, 2, 3, 4; |
||||
SELECT * FROM information_schema.usage_privileges WHERE object_type LIKE 'FOREIGN%' ORDER BY 1, 2, 3, 4, 5; |
||||
SELECT * FROM information_schema.role_usage_grants WHERE object_type LIKE 'FOREIGN%' ORDER BY 1, 2, 3, 4, 5; |
||||
SET ROLE regress_test_role; |
||||
SELECT * FROM information_schema.user_mapping_options ORDER BY 1, 2, 3, 4; |
||||
SELECT * FROM information_schema.usage_privileges WHERE object_type LIKE 'FOREIGN%' ORDER BY 1, 2, 3, 4, 5; |
||||
SELECT * FROM information_schema.role_usage_grants WHERE object_type LIKE 'FOREIGN%' ORDER BY 1, 2, 3, 4, 5; |
||||
DROP USER MAPPING FOR current_user SERVER st1; |
||||
RESET ROLE; |
||||
|
||||
|
||||
-- has_foreign_data_wrapper_privilege |
||||
SELECT has_foreign_data_wrapper_privilege('regress_test_role', |
||||
(SELECT oid FROM pg_foreign_data_wrapper WHERE fdwname='foo'), 'USAGE'); |
||||
SELECT has_foreign_data_wrapper_privilege('regress_test_role', 'foo', 'USAGE'); |
||||
SELECT has_foreign_data_wrapper_privilege( |
||||
(SELECT oid FROM pg_roles WHERE rolname='regress_test_role'), |
||||
(SELECT oid FROM pg_foreign_data_wrapper WHERE fdwname='foo'), 'USAGE'); |
||||
SELECT has_foreign_data_wrapper_privilege( |
||||
(SELECT oid FROM pg_foreign_data_wrapper WHERE fdwname='foo'), 'USAGE'); |
||||
SELECT has_foreign_data_wrapper_privilege( |
||||
(SELECT oid FROM pg_roles WHERE rolname='regress_test_role'), 'foo', 'USAGE'); |
||||
SELECT has_foreign_data_wrapper_privilege('foo', 'USAGE'); |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER foo TO regress_test_role; |
||||
SELECT has_foreign_data_wrapper_privilege('regress_test_role', 'foo', 'USAGE'); |
||||
|
||||
-- has_server_privilege |
||||
SELECT has_server_privilege('regress_test_role', |
||||
(SELECT oid FROM pg_foreign_server WHERE srvname='s8'), 'USAGE'); |
||||
SELECT has_server_privilege('regress_test_role', 's8', 'USAGE'); |
||||
SELECT has_server_privilege( |
||||
(SELECT oid FROM pg_roles WHERE rolname='regress_test_role'), |
||||
(SELECT oid FROM pg_foreign_server WHERE srvname='s8'), 'USAGE'); |
||||
SELECT has_server_privilege( |
||||
(SELECT oid FROM pg_foreign_server WHERE srvname='s8'), 'USAGE'); |
||||
SELECT has_server_privilege( |
||||
(SELECT oid FROM pg_roles WHERE rolname='regress_test_role'), 's8', 'USAGE'); |
||||
SELECT has_server_privilege('s8', 'USAGE'); |
||||
GRANT USAGE ON FOREIGN SERVER s8 TO regress_test_role; |
||||
SELECT has_server_privilege('regress_test_role', 's8', 'USAGE'); |
||||
REVOKE USAGE ON FOREIGN SERVER s8 FROM regress_test_role; |
||||
|
||||
GRANT USAGE ON FOREIGN SERVER s4 TO regress_test_role; |
||||
DROP USER MAPPING FOR public SERVER s4; |
||||
ALTER SERVER s6 OPTIONS (DROP host, DROP dbname); |
||||
ALTER USER MAPPING FOR regress_test_role SERVER s6 OPTIONS (DROP username); |
||||
ALTER FOREIGN DATA WRAPPER foo LIBRARY 'plpgsql'; |
||||
ALTER FOREIGN DATA WRAPPER foo LIBRARY 'default_fdw'; |
||||
|
||||
-- Privileges |
||||
SET ROLE unprivileged_role; |
||||
CREATE FOREIGN DATA WRAPPER foobar LIBRARY 'dummy_fdw' LANGUAGE C; -- ERROR |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (gotcha 'true'); -- ERROR |
||||
ALTER FOREIGN DATA WRAPPER foo OWNER TO unprivileged_role; -- ERROR |
||||
DROP FOREIGN DATA WRAPPER foo; -- ERROR |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER foo TO regress_test_role; -- ERROR |
||||
CREATE SERVER s9 FOREIGN DATA WRAPPER foo; -- ERROR |
||||
ALTER SERVER s4 VERSION '0.5'; -- ERROR |
||||
ALTER SERVER s4 OWNER TO unprivileged_role; -- ERROR |
||||
DROP SERVER s4; -- ERROR |
||||
GRANT USAGE ON FOREIGN SERVER s4 TO regress_test_role; -- ERROR |
||||
CREATE USER MAPPING FOR public SERVER s4; -- ERROR |
||||
ALTER USER MAPPING FOR regress_test_role SERVER s6 OPTIONS (gotcha 'true'); -- ERROR |
||||
DROP USER MAPPING FOR regress_test_role SERVER s6; -- ERROR |
||||
RESET ROLE; |
||||
|
||||
GRANT USAGE ON FOREIGN DATA WRAPPER postgresql TO unprivileged_role; |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER foo TO unprivileged_role WITH GRANT OPTION; |
||||
SET ROLE unprivileged_role; |
||||
CREATE FOREIGN DATA WRAPPER foobar LIBRARY 'dummy_fdw' LANGUAGE C; -- ERROR |
||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (gotcha 'true'); -- ERROR |
||||
DROP FOREIGN DATA WRAPPER foo; -- ERROR |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER postgresql TO regress_test_role; -- WARNING |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER foo TO regress_test_role; |
||||
CREATE SERVER s9 FOREIGN DATA WRAPPER postgresql; |
||||
ALTER SERVER s6 VERSION '0.5'; -- ERROR |
||||
DROP SERVER s6; -- ERROR |
||||
GRANT USAGE ON FOREIGN SERVER s6 TO regress_test_role; -- ERROR |
||||
GRANT USAGE ON FOREIGN SERVER s9 TO regress_test_role; |
||||
CREATE USER MAPPING FOR public SERVER s6; -- ERROR |
||||
CREATE USER MAPPING FOR public SERVER s9; |
||||
ALTER USER MAPPING FOR regress_test_role SERVER s6 OPTIONS (gotcha 'true'); -- ERROR |
||||
DROP USER MAPPING FOR regress_test_role SERVER s6; -- ERROR |
||||
RESET ROLE; |
||||
|
||||
REVOKE USAGE ON FOREIGN DATA WRAPPER foo FROM unprivileged_role; -- ERROR |
||||
REVOKE USAGE ON FOREIGN DATA WRAPPER foo FROM unprivileged_role CASCADE; |
||||
SET ROLE unprivileged_role; |
||||
GRANT USAGE ON FOREIGN DATA WRAPPER foo TO regress_test_role; -- ERROR |
||||
CREATE SERVER s10 FOREIGN DATA WRAPPER foo; -- ERROR |
||||
ALTER SERVER s9 VERSION '1.1'; |
||||
GRANT USAGE ON FOREIGN SERVER s9 TO regress_test_role; |
||||
CREATE USER MAPPING FOR current_user SERVER s9; |
||||
DROP SERVER s9 CASCADE; |
||||
RESET ROLE; |
||||
CREATE SERVER s9 FOREIGN DATA WRAPPER foo; |
||||
GRANT USAGE ON FOREIGN SERVER s9 TO unprivileged_role; |
||||
SET ROLE unprivileged_role; |
||||
ALTER SERVER s9 VERSION '1.2'; -- ERROR |
||||
GRANT USAGE ON FOREIGN SERVER s9 TO regress_test_role; -- WARNING |
||||
CREATE USER MAPPING FOR current_user SERVER s9; -- ERROR |
||||
DROP SERVER s9 CASCADE; -- ERROR |
||||
RESET ROLE; |
||||
|
||||
-- Cleanup |
||||
DROP ROLE regress_test_role; -- ERROR |
||||
DROP SERVER s5 CASCADE; |
||||
DROP SERVER st1 CASCADE; |
||||
DROP SERVER st2; |
||||
DROP USER MAPPING FOR regress_test_role SERVER s6; |
||||
DROP FOREIGN DATA WRAPPER foo CASCADE; |
||||
DROP SERVER s8 CASCADE; |
||||
DROP ROLE regress_test_indirect; |
||||
DROP ROLE regress_test_role; |
||||
DROP ROLE unprivileged_role; -- ERROR |
||||
REVOKE ALL ON FOREIGN DATA WRAPPER postgresql FROM unprivileged_role; |
||||
DROP ROLE unprivileged_role; |
||||
DROP ROLE regress_test_role2; |
||||
DROP FOREIGN DATA WRAPPER postgresql CASCADE; |
||||
DROP FOREIGN DATA WRAPPER dummy CASCADE; |
||||
\c |
||||
DROP ROLE foreign_data_user; |
||||
|
||||
-- At this point we should have no wrappers, no servers, and no mappings. |
||||
SELECT fdwname, fdwlibrary, fdwoptions FROM pg_foreign_data_wrapper; |
||||
SELECT srvname, srvoptions FROM pg_foreign_server; |
||||
SELECT * FROM pg_user_mapping; |
||||
Loading…
Reference in new issue