summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2014-01-31 22:27:50 +0000
committerTom Lane2014-01-31 22:28:02 +0000
commite93ca1618b92ff4ca3e1ed3bff89179d3e2abd9e (patch)
tree338ae1e639e7dd14b3d95407e03855b0e6d2a964
parent384fbd1a5d49c3acaecf15d7a7eefae49049f6eb (diff)
Add some examples to the postgres_fdw documentation.
Michael Paquier
-rw-r--r--doc/src/sgml/postgres-fdw.sgml62
1 files changed, 62 insertions, 0 deletions
diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml
index 35924f19f2..e6f6e20581 100644
--- a/doc/src/sgml/postgres-fdw.sgml
+++ b/doc/src/sgml/postgres-fdw.sgml
@@ -376,6 +376,68 @@
</sect2>
<sect2>
+ <title>Examples</title>
+
+ <para>
+ Here is an example of creating a foreign table with
+ <literal>postgres_fdw</>. First install the extension:
+ </para>
+
+<programlisting>
+CREATE EXTENSION postgres_fdw;
+</programlisting>
+
+ <para>
+ Then create a foreign server using <xref linkend="sql-createserver">.
+ In this example we wish to connect to a <productname>PostgreSQL</> server
+ on host <literal>192.83.123.89</literal> listening on
+ port <literal>5432</literal>. The database to which the connection is made
+ is named <literal>foreign_db</literal> on the remote server:
+
+<programlisting>
+CREATE SERVER foreign_server
+ FOREIGN DATA WRAPPER postgres_fdw
+ OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');
+</programlisting>
+ </para>
+
+ <para>
+ A user mapping, defined with <xref linkend="sql-createusermapping">, is
+ needed as well to identify the role that will be used on the remote
+ server:
+
+<programlisting>
+CREATE USER MAPPING FOR local_user
+ SERVER foreign_server
+ OPTIONS (user 'foreign_user', password 'password');
+</programlisting>
+ </para>
+
+ <para>
+ Now it is possible to create a foreign table with
+ <xref linkend="sql-createforeigntable">. In this example we
+ wish to access the table named <structname>some_schema.some_table</>
+ on the remote server. The local name for it will
+ be <structname>foreign_table</>:
+
+<programlisting>
+CREATE FOREIGN TABLE foreign_table (
+ id serial NOT NULL,
+ data text
+)
+ SERVER foreign_server
+ OPTIONS (schema_name 'some_schema', table_name 'some_table');
+</programlisting>
+
+ It's essential that the data types and other properties of the columns
+ declared in <command>CREATE FOREIGN TABLE</> match the actual remote table.
+ Column names must match as well, unless you attach <literal>column_name</>
+ options to the individual columns to show how they are named in the remote
+ table.
+ </para>
+ </sect2>
+
+ <sect2>
<title>Author</title>
<para>
Shigeru Hanada <email>[email protected]</email>