diff options
author | Bruce Momjian <bruce@momjian.us> | 2011-12-01 09:33:59 -0500 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2011-12-01 09:33:59 -0500 |
commit | 1be6f9379287ecbbe6ab47636af7d41c7ae279ea (patch) | |
tree | 2f9eccd6d7696c0b530f80ae055d39d4cdac3e2f /doc/src | |
parent | ebbcba75b46699fe11e347e1250898ce7d01b6f2 (diff) | |
download | postgresql-1be6f9379287ecbbe6ab47636af7d41c7ae279ea.tar.gz postgresql-1be6f9379287ecbbe6ab47636af7d41c7ae279ea.zip |
Add file-fdw documentation example.
Josh Berkus
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/file-fdw.sgml | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/doc/src/sgml/file-fdw.sgml b/doc/src/sgml/file-fdw.sgml index dd712e92636..900b0553f78 100644 --- a/doc/src/sgml/file-fdw.sgml +++ b/doc/src/sgml/file-fdw.sgml @@ -158,4 +158,76 @@ specified, the file size (in bytes) is shown as well. </para> + <example> + <title id="csvlog-fdw">Create a Foreign Table for PostgreSQL CSV Logs</title> + + <para> + One of the obvious uses for the <literal>file_fdw</> is to make + the PostgreSQL activity log available as a table for querying. To + do this, first you must be logging to a CSV file, which here we + will call <literal>pglog.csv</>. First, install <literal>file_fdw</> + as an extension: + </para> + +<programlisting> +CREATE EXTENSION file_fdw; +</programlisting> + + <para> + Next, create the foreign data wrapper: + +<programlisting> +CREATE FOREIGN DATA WRAPPER file_fdw HANDLER file_fdw_handler; +</programlisting> + </para> + + <para> + Then create a foreign data server: + +<programlisting> +CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw; +</programlisting> + </para> + + <para> + Now you are ready to create the foreign data table. Using the + <command>CREATE FOREIGN TABLE</> command, you will need to define + the columns for the table, the CSV filename, and its format: + +<programlisting> +CREATE FOREIGN TABLE pglog ( + log_time timestamp(3) with time zone, + user_name text, + database_name text, + process_id integer, + connection_from text, + session_id text, + session_line_num bigint, + command_tag text, + session_start_time timestamp with time zone, + virtual_transaction_id text, + transaction_id bigint, + error_severity text, + sql_state_code text, + message text, + detail text, + hint text, + internal_query text, + internal_query_pos integer, + context text, + query text, + query_pos integer, + location text, + application_name text +) SERVER pglog +OPTIONS ( filename '/home/josh/9.1/data/pg_log/pglog.csv', format 'csv' ); +</programlisting> + </para> + + <para> + That's it — now you can query your log directly. In production, of course, + you would need to define some way to adjust to log rotation. + </para> + </example> + </sect1> |