CREATESCHEMAIFNOTEXISTSmonitor;-- This session only
SETsearch_path=monitor,pg_catalog;-- extension
CREATEEXTENSIONIFNOTEXISTSfile_fdwWITHSCHEMAmonitor;-- log parent table: empty
CREATETABLEmonitor.pg_log(log_timetimestamp(3)withtimezone,user_nametext,database_nametext,process_idinteger,connection_fromtext,session_idtext,session_line_numbigint,command_tagtext,session_start_timetimestampwithtimezone,virtual_transaction_idtext,transaction_idbigint,error_severitytext,sql_state_codetext,messagetext,detailtext,hinttext,internal_querytext,internal_query_posinteger,contexttext,querytext,query_posinteger,locationtext,application_nametext,PRIMARYKEY(session_id,session_line_num));COMMENTONTABLEmonitor.pg_logIS'PostgreSQL csv log schema';-- local file server
CREATESERVERIFNOTEXISTSpg_logFOREIGNDATAWRAPPERfile_fdw;-- Change filename to actual path
CREATEFOREIGNTABLEIFNOTEXISTSmonitor.pg_log_mon()INHERITS(monitor.pg_log)SERVERpg_logOPTIONS(filename'/pg/data/log/postgresql-Mon.csv',format'csv');CREATEFOREIGNTABLEIFNOTEXISTSmonitor.pg_log_tue()INHERITS(monitor.pg_log)SERVERpg_logOPTIONS(filename'/pg/data/log/postgresql-Tue.csv',format'csv');CREATEFOREIGNTABLEIFNOTEXISTSmonitor.pg_log_wed()INHERITS(monitor.pg_log)SERVERpg_logOPTIONS(filename'/pg/data/log/postgresql-Wed.csv',format'csv');CREATEFOREIGNTABLEIFNOTEXISTSmonitor.pg_log_thu()INHERITS(monitor.pg_log)SERVERpg_logOPTIONS(filename'/pg/data/log/postgresql-Thu.csv',format'csv');CREATEFOREIGNTABLEIFNOTEXISTSmonitor.pg_log_fri()INHERITS(monitor.pg_log)SERVERpg_logOPTIONS(filename'/pg/data/log/postgresql-Fri.csv',format'csv');CREATEFOREIGNTABLEIFNOTEXISTSmonitor.pg_log_sat()INHERITS(monitor.pg_log)SERVERpg_logOPTIONS(filename'/pg/data/log/postgresql-Sat.csv',format'csv');CREATEFOREIGNTABLEIFNOTEXISTSmonitor.pg_log_sun()INHERITS(monitor.pg_log)SERVERpg_logOPTIONS(filename'/pg/data/log/postgresql-Sun.csv',format'csv');