Software: Apache. PHP/5.6.40 uname -a: Linux cpanel06wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.80.el6.x86_64 #1 SMP Thu Sep 24 uid=851(cp949260) gid=853(cp949260) groups=853(cp949260) Safe-mode: OFF (not secure) /opt/alt/postgresql11/usr/share/doc/alt-postgresql11-9.2.24/html/ drwxr-xr-x |
Viewing file: Select action/file-type:
F.14. file_fdw The file_fdw module provides the foreign-data wrapper
A foreign table created using this wrapper can have the following options:
A column of a foreign table created using this wrapper can have the following options:
COPY's OIDS and FORCE_QUOTE options are currently not supported by file_fdw. These options can only be specified for a foreign table or its columns, not in the options of the file_fdw foreign-data wrapper, nor in the options of a server or user mapping using the wrapper. Changing table-level options requires superuser privileges, for security reasons: only a superuser should be able to determine which file is read. In principle non-superusers could be allowed to change the other options, but that's not supported at present. For a foreign table using file_fdw, EXPLAIN shows the name of the file to be read. Unless COSTS OFF is specified, the file size (in bytes) is shown as well. Example F-1. 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; Then create a foreign 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 file name, 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. |
:: Command execute :: | |
--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0093 ]-- |