Postgresql of csv log settings
Original link:
https://my.oschina.net/Kenyon/blog/62504
PG logging system more complete, the system starts to remove the specified log, log Wal substandard, the following describes a further detailed output log: csv log related to the parameter file:. $ PGDATA / postgresql.conf
main parameters involved:
To turn csv log, you need to set logging_collector = on, or else lose out. DB need to restart after setting finished.
The default parameters are log_destination stderr, without modification, then only the output stderr
log_directory is the path of the output log
log_filename is the name of the output log, the default.
There are other parameters specific reference to where to log the postgresql.conf portion.
2. View:
is to import the text file into the database, using the copy mode is relatively simple. To build the table
main parameters involved:
-
log_destination = 'csvlog' logging_collector = on log_directory = '/home/postgres/pg_log' log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
-
To turn csv log, you need to set logging_collector = on, or else lose out. DB need to restart after setting finished.
The default parameters are log_destination stderr, without modification, then only the output stderr
log_directory is the path of the output log
log_filename is the name of the output log, the default.
There are other parameters specific reference to where to log the postgresql.conf portion.
2. View:
-
[postgres@localhost pg_log]$ ll /home/postgres/pg_log/ total 4 -rw-------. 1 postgres postgres 2476 Jun 15 15:40 postgresql-2012-06-15_152431.csv -rw-------. 1 postgres postgres 0 Jun 15 15:24 postgresql-2012-06-15_152431.log [postgres@localhost pg_log]$ more postgresql-2012-06-15_152431.csv 2012-06-15 15:24:31.258 CST,,,1882,,4fdae32f.75a,1,,2012-06-15 15:24:31 CST,,0,LOG,00000,"database system was shut down at 2012-06-1 5 15:24:19 CST",,,,,,,,,"" 2012-06-15 15:24:31.259 CST,,,1882,,4fdae32f.75a,2,,2012-06-15 15:24:31 CST,,0,LOG,00000,"could not remove cache file ""base/16384/p g_internal.init"": Not a directory",,,,,,,,,"" 2012-06-15 15:24:31.282 CST,,,1885,,4fdae32f.75d,1,,2012-06-15 15:24:31 CST,,0,LOG,00000,"autovacuum launcher started",,,,,,,,,"" 2012-06-15 15:24:31.306 CST,,,1880,,4fdae32e.758,1,,2012-06-15 15:24:30 CST,,0,LOG,00000,"database system is ready to accept connect ions",,,,,,,,,""
-
is to import the text file into the database, using the copy mode is relatively simple. To build the table
CREATE TABLE pg_log ( 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, PRIMARY KEY (session_id, session_line_num) ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pg_log_pkey" for table "pg_log"
copy pg_log from '/home/postgres/pg_log/postgresql-2012-06-15_152431.csv' with csv; COPY 4
4. Close the log
to log open during operation do the reverse, set off to the correlation value
5. Other
This log information may be combined with a log output start time to see a history of operation of the system, is a very easy to troubleshoot the system err Tool of
Reproduced in: https: //my.oschina.net/Kenyon/blog/62504