Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite93ca16

Browse files
committed
Add some examples to the postgres_fdw documentation.
Michael Paquier
1 parent384fbd1 commite93ca16

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

‎doc/src/sgml/postgres-fdw.sgml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,68 @@
375375
</para>
376376
</sect2>
377377

378+
<sect2>
379+
<title>Examples</title>
380+
381+
<para>
382+
Here is an example of creating a foreign table with
383+
<literal>postgres_fdw</>. First install the extension:
384+
</para>
385+
386+
<programlisting>
387+
CREATE EXTENSION postgres_fdw;
388+
</programlisting>
389+
390+
<para>
391+
Then create a foreign server using <xref linkend="sql-createserver">.
392+
In this example we wish to connect to a <productname>PostgreSQL</> server
393+
on host <literal>192.83.123.89</literal> listening on
394+
port <literal>5432</literal>. The database to which the connection is made
395+
is named <literal>foreign_db</literal> on the remote server:
396+
397+
<programlisting>
398+
CREATE SERVER foreign_server
399+
FOREIGN DATA WRAPPER postgres_fdw
400+
OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');
401+
</programlisting>
402+
</para>
403+
404+
<para>
405+
A user mapping, defined with <xref linkend="sql-createusermapping">, is
406+
needed as well to identify the role that will be used on the remote
407+
server:
408+
409+
<programlisting>
410+
CREATE USER MAPPING FOR local_user
411+
SERVER foreign_server
412+
OPTIONS (user 'foreign_user', password 'password');
413+
</programlisting>
414+
</para>
415+
416+
<para>
417+
Now it is possible to create a foreign table with
418+
<xref linkend="sql-createforeigntable">. In this example we
419+
wish to access the table named <structname>some_schema.some_table</>
420+
on the remote server. The local name for it will
421+
be <structname>foreign_table</>:
422+
423+
<programlisting>
424+
CREATE FOREIGN TABLE foreign_table (
425+
id serial NOT NULL,
426+
data text
427+
)
428+
SERVER foreign_server
429+
OPTIONS (schema_name 'some_schema', table_name 'some_table');
430+
</programlisting>
431+
432+
It's essential that the data types and other properties of the columns
433+
declared in <command>CREATE FOREIGN TABLE</> match the actual remote table.
434+
Column names must match as well, unless you attach <literal>column_name</>
435+
options to the individual columns to show how they are named in the remote
436+
table.
437+
</para>
438+
</sect2>
439+
378440
<sect2>
379441
<title>Author</title>
380442
<para>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp