Add file-fdw documentation example.
authorBruce Momjian
Thu, 1 Dec 2011 14:33:59 +0000 (09:33 -0500)
committerBruce Momjian
Thu, 1 Dec 2011 14:33:59 +0000 (09:33 -0500)
Josh Berkus

doc/src/sgml/file-fdw.sgml

index dd712e92636f207e989486e0d3fca6e9b9618625..900b0553f7826f425c08fa9decc63c2fafbb4fe9 100644 (file)
   specified, the file size (in bytes) is shown as well.
  
 
Create a Foreign Table for PostgreSQL CSV Logs
+   
+  
+   One of the obvious uses for the 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 pglog.csv.  First, install file_fdw
+   as an extension:
+  
+
+
+CREATE EXTENSION file_fdw;
+
+
+  
+   Next, create the foreign data wrapper:
+
+
+CREATE FOREIGN DATA WRAPPER file_fdw HANDLER file_fdw_handler;
+
+  
+
+  
+   Then create a foreign data server:
+
+
+CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;
+
+  
+
+  
+   Now you are ready to create the foreign data table.  Using the
+   CREATE FOREIGN TABLE command, you will need to define
+   the columns for the table, the CSV filename, and its format:
+
+
+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' );
+
+  
+
+  
+   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.
+  
+