1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.137 2007/08/13 19:27:11 tgl Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.138 2007/08/19 01:41:23 adunstan Exp $ -->
2
2
3
3
<chapter Id="runtime-config">
4
4
<title>Server Configuration</title>
@@ -2261,7 +2261,7 @@ SELECT * FROM parent WHERE key = 2400;
2261
2261
<para>
2262
2262
<productname>PostgreSQL</productname> supports several methods
2263
2263
for logging server messages, including
2264
- <systemitem>stderr</systemitem> and
2264
+ <systemitem>stderr</systemitem>, <systemitem>csvlog</systemitem> and
2265
2265
<systemitem>syslog</systemitem>. On Windows,
2266
2266
<systemitem>eventlog</systemitem> is also supported. Set this
2267
2267
parameter to a list of desired log destinations separated by
@@ -2270,24 +2270,33 @@ SELECT * FROM parent WHERE key = 2400;
2270
2270
This parameter can only be set in the <filename>postgresql.conf</>
2271
2271
file or on the server command line.
2272
2272
</para>
2273
+ <para> If <varname>log_destination</> is set to <systemitem>csvlog</systemitem>,
2274
+ the log is output as comma seperated values. The format is:
2275
+ timestamp with milliseconds, username, database name, session id, host:port number,
2276
+ process id, per process line number, command tag, session start time, transaction id,
2277
+ error severity, SQL state code, statement/error message.
2278
+ </para>
2273
2279
</listitem>
2274
2280
</varlistentry>
2275
2281
2276
- <varlistentry id="guc-redirect-stderr " xreflabel="redirect_stderr ">
2277
- <term><varname>redirect_stderr </varname> (<type>boolean</type>)</term>
2282
+ <varlistentry id="guc-logging-collector " xreflabel="logging_collector ">
2283
+ <term><varname>logging_collector </varname> (<type>boolean</type>)</term>
2278
2284
<indexterm>
2279
- <primary><varname>redirect_stderr </> configuration parameter</primary>
2285
+ <primary><varname>logging_collector </> configuration parameter</primary>
2280
2286
</indexterm>
2281
2287
<listitem>
2282
2288
<para>
2283
- This parameter allows messages sent to <application>stderr</> to be
2289
+ This parameter allows messages sent to <application>stderr</>,
2290
+ and CSV logs, to be
2284
2291
captured and redirected into log files.
2285
2292
This method, in combination with logging to <application>stderr</>,
2286
2293
is often more useful than
2287
2294
logging to <application>syslog</>, since some types of messages
2288
2295
might not appear in <application>syslog</> output (a common example
2289
2296
is dynamic-linker failure messages).
2290
2297
This parameter can only be set at server start.
2298
+ <varname>start_log_collector</varname> must be enabled to generate
2299
+ CSV logs.
2291
2300
</para>
2292
2301
</listitem>
2293
2302
</varlistentry>
@@ -2299,8 +2308,8 @@ SELECT * FROM parent WHERE key = 2400;
2299
2308
</indexterm>
2300
2309
<listitem>
2301
2310
<para>
2302
- When <varname>redirect_stderr </> is enabled, this parameter
2303
- determines the directory in which log files will be created.
2311
+ When <varname>logging_collector </> is enabled,
2312
+ this parameter determines the directory in which log files will be created.
2304
2313
It can be specified as an absolute path, or relative to the
2305
2314
cluster data directory.
2306
2315
This parameter can only be set in the <filename>postgresql.conf</>
@@ -2316,8 +2325,8 @@ SELECT * FROM parent WHERE key = 2400;
2316
2325
</indexterm>
2317
2326
<listitem>
2318
2327
<para>
2319
- When <varname>redirect_stderr </varname> is enabled, this parameter
2320
- sets the file names of the created log files. The value
2328
+ When <varname>logging_collector </varname> is enabled,
2329
+ this parameter sets the file names of the created log files. The value
2321
2330
is treated as a <systemitem>strftime</systemitem> pattern,
2322
2331
so <literal>%</literal>-escapes can be used to specify time-varying
2323
2332
file names. (Note that if there are
@@ -2332,6 +2341,14 @@ SELECT * FROM parent WHERE key = 2400;
2332
2341
This parameter can only be set in the <filename>postgresql.conf</>
2333
2342
file or on the server command line.
2334
2343
</para>
2344
+ <para>
2345
+ If <varname>log_destination</> is set to <systemitem>csvlog</>,
2346
+ <literal>.csv</> will be appended to the timestamped
2347
+ <varname>log_filename</> to create the final log file name.
2348
+ (If log_filename ends in <literal>.log</>, the suffix is overwritten.)
2349
+ In the case of the example above, the
2350
+ file name will be <literal>server_log.1093827753.csv</literal>
2351
+ </para>
2335
2352
</listitem>
2336
2353
</varlistentry>
2337
2354
@@ -2342,8 +2359,8 @@ SELECT * FROM parent WHERE key = 2400;
2342
2359
</indexterm>
2343
2360
<listitem>
2344
2361
<para>
2345
- When <varname>redirect_stderr </varname> is enabled, this parameter
2346
- determines the maximum lifetime of an individual log file.
2362
+ When <varname>logging_collector </varname> is enabled,
2363
+ this parameter determines the maximum lifetime of an individual log file.
2347
2364
After this many minutes have elapsed, a new log file will
2348
2365
be created. Set to zero to disable time-based creation of
2349
2366
new log files.
@@ -2360,8 +2377,8 @@ SELECT * FROM parent WHERE key = 2400;
2360
2377
</indexterm>
2361
2378
<listitem>
2362
2379
<para>
2363
- When <varname>redirect_stderr </varname> is enabled, this parameter
2364
- determines the maximum size of an individual log file.
2380
+ When <varname>logging_collector </varname> is enabled,
2381
+ this parameter determines the maximum size of an individual log file.
2365
2382
After this many kilobytes have been emitted into a log file,
2366
2383
a new log file will be created. Set to zero to disable size-based
2367
2384
creation of new log files.
@@ -2378,8 +2395,8 @@ SELECT * FROM parent WHERE key = 2400;
2378
2395
</indexterm>
2379
2396
<listitem>
2380
2397
<para>
2381
- When <varname>redirect_stderr </varname> is enabled, this parameter will cause
2382
- <productname>PostgreSQL</productname> to truncate (overwrite),
2398
+ When <varname>logging_collector </varname> is enabled,
2399
+ this parameter will cause <productname>PostgreSQL</productname> to truncate (overwrite),
2383
2400
rather than append to, any existing log file of the same name.
2384
2401
However, truncation will occur only when a new file is being opened
2385
2402
due to time-based rotation, not during server startup or size-based
@@ -2599,7 +2616,7 @@ SELECT * FROM parent WHERE key = 2400;
2599
2616
The server's standard output and standard error are redirected
2600
2617
to <literal>/dev/null</>, so any messages sent to them will be lost.
2601
2618
Unless <application>syslog</> logging is selected or
2602
- <varname>redirect_stderr </> is enabled, using this parameter
2619
+ <varname>start_log_collector </> is enabled, using this parameter
2603
2620
is discouraged because it makes it impossible to see error messages.
2604
2621
This parameter can only be set at server start.
2605
2622
</para>
@@ -3066,6 +3083,94 @@ SELECT * FROM parent WHERE key = 2400;
3066
3083
</varlistentry>
3067
3084
3068
3085
</variablelist>
3086
+ </sect2>
3087
+ <sect2 id="runtime-config-logging-csvlog">
3088
+ <title>Using the csvlog</title>
3089
+
3090
+ <para>
3091
+ Including <literal>csvlog</> in the <varname>log_destination</> list
3092
+ provides a convenient way to import log files into a database table.
3093
+ Here is a sample table definition for storing csvlog output:
3094
+ </para>
3095
+
3096
+ <programlisting>
3097
+ CREATE TABLE postgres_log
3098
+ (
3099
+ log_time timestamp,
3100
+ username text,
3101
+ database_name text,
3102
+ sessionid text not null,
3103
+ connection_from text,
3104
+ process_id text,
3105
+ process_line_num int not null,
3106
+ command_tag text,
3107
+ session_start_time timestamp,
3108
+ transaction_id int,
3109
+ error_severity text,
3110
+ sql_state_code text,
3111
+ statement text,
3112
+ PRIMARY KEY (sessionid, process_line_num)
3113
+ );
3114
+ </programlisting>
3115
+
3116
+
3117
+ <para>
3118
+ In order to import into this table, use the COPY FROM command:
3119
+ </para>
3120
+
3121
+ <programlisting>
3122
+ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
3123
+ </programlisting>
3124
+
3125
+ <para>
3126
+ There are a few things you need to import csvlog files easily and
3127
+ automatically:
3128
+
3129
+ <orderedlist>
3130
+ <listitem>
3131
+ <para>
3132
+ Use a consistant, predictable naming scheme for your log files
3133
+ with <varname>log_filename</varname>. This lets you predict what
3134
+ the file name will be when it is ready to be imported.
3135
+ guess what
3136
+ the file name will be and know when an individual log file is
3137
+ complete and therefore ready to be imported.
3138
+ </para>
3139
+ </listitem>
3140
+
3141
+ <listitem>
3142
+ <para>
3143
+ Set <varname>log_rotation_size</varname> to 0 to disable
3144
+ size-based log rotation, as it makes the log filename difficult
3145
+ to predict.
3146
+ </para>
3147
+ </listitem>
3148
+
3149
+ <listitem>
3150
+ <para>
3151
+ Set <varname>log_truncate_on_rotate</varname> = on so that old
3152
+ log data isn't mixed with the new in the same file.
3153
+ </para>
3154
+ </listitem>
3155
+
3156
+ <listitem>
3157
+ <para>
3158
+ The example above includes a useful primary key on the log
3159
+ file data, which will protect against accidentally importing
3160
+ the same information twice. The COPY command commits all of
3161
+ the data it imports at one time, and any single error will
3162
+ cause the entire import to fail.
3163
+ If you import a partial log file and later import the file again
3164
+ when it is complete, the primary key violation will cause the
3165
+ import to fail. Wait until the log is complete and closed before
3166
+ import. This will also protect against accidently importing a
3167
+ partial line that hasn't been completely written, which would
3168
+ also cause the COPY to fail.
3169
+ </para>
3170
+ </listitem>
3171
+ </orderedlist>
3172
+ </para>
3173
+
3069
3174
</sect2>
3070
3175
</sect1>
3071
3176
0 commit comments