バージョンごとのドキュメント一覧

20.8. エラー報告とログ取得 #

<title>Error Reporting and Logging</title>

20.8.1. ログの出力先 #

<title>Where to Log</title>
log_destination (string) #

<productname>PostgreSQL</productname> supports several methods for logging server messages, including <systemitem>stderr</systemitem>, <systemitem>csvlog</systemitem>, <systemitem>jsonlog</systemitem>, and <systemitem>syslog</systemitem>. On Windows, <systemitem>eventlog</systemitem> is also supported. Set this parameter to a list of desired log destinations separated by commas. The default is to log to <systemitem>stderr</systemitem> only. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. PostgreSQLは、stderrjsonlogcsvlogjsonlogおよびsyslogを含めて、サーバメッセージのログ取得に対し数種類の方法を提供します。 Windowsでは、eventlogも同時に提供します。 このパラメータを設定するには、コンマ区切りでお好みのログ出力先を記載します。 デフォルトでは、ログはstderrのみに出力されます。 このパラメータは、postgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。

If <systemitem>csvlog</systemitem> is included in <varname>log_destination</varname>, log entries are output in <quote>comma separated value</quote> (<acronym>CSV</acronym>) format, which is convenient for loading logs into programs. See <xref linkend="runtime-config-logging-csvlog"/> for details. <xref linkend="guc-logging-collector"/> must be enabled to generate CSV-format log output. csvloglog_destinationに含まれる場合、ログ項目はプログラムへの読み込みが簡便なカンマ区切り値書式(CSV)で出力されます。 詳細は20.8.4を参照してください。 CSV書式のログ出力を生成するためにはlogging_collectorを有効にする必要があります。

If <systemitem>jsonlog</systemitem> is included in <varname>log_destination</varname>, log entries are output in <acronym>JSON</acronym> format, which is convenient for loading logs into programs. See <xref linkend="runtime-config-logging-jsonlog"/> for details. <xref linkend="guc-logging-collector"/> must be enabled to generate JSON-format log output. jsonloglog_destinationに含まれる場合、ログ項目はプログラムへの読み込みが簡便なJSON書式で出力されます。 詳細は20.8.5を参照してください。 JSON書式のログ出力を生成するためにはlogging_collectorを有効にする必要があります。

When either <systemitem>stderr</systemitem>, <systemitem>csvlog</systemitem> or <systemitem>jsonlog</systemitem> are included, the file <filename>current_logfiles</filename> is created to record the location of the log file(s) currently in use by the logging collector and the associated logging destination. This provides a convenient way to find the logs currently in use by the instance. Here is an example of this file's content: stderrcsvlog、またはjsonlogのいずれかが含まれている場合、ファイルcurrent_logfilesが作成され、ロギングコレクタによって現在使用されているログファイルの場所と関連付けられたロギング先が記録されます。 これにより、インスタンスによって現在使用されているログを簡単に見つけることができます。 このファイルの内容の例を次に示します:

stderr log/postgresql.log
csvlog log/postgresql.csv
jsonlog log/postgresql.json

<filename>current_logfiles</filename> is recreated when a new log file is created as an effect of rotation, and when <varname>log_destination</varname> is reloaded. It is removed when none of <systemitem>stderr</systemitem>, <systemitem>csvlog</systemitem> or <systemitem>jsonlog</systemitem> are included in <varname>log_destination</varname>, and when the logging collector is disabled. current_logfilesは、ローテーションの効果として新しいログファイルが作成されたとき、およびlog_destinationがリロードされたときに再作成されます。 stderrcsvlogjsonlogのいずれもlog_destinationに含まれていないとき、およびロギングコレクタが無効になっているときに削除されます。

注記

On most Unix systems, you will need to alter the configuration of your system's <application>syslog</application> daemon in order to make use of the <systemitem>syslog</systemitem> option for <varname>log_destination</varname>. <productname>PostgreSQL</productname> can log to <application>syslog</application> facilities <literal>LOCAL0</literal> through <literal>LOCAL7</literal> (see <xref linkend="guc-syslog-facility"/>), but the default <application>syslog</application> configuration on most platforms will discard all such messages. You will need to add something like: log_destinationsyslogオプションを使用できるようにするために、ほとんどのUnixシステムではシステムのsyslogデーモンの設定を変更しなければならないでしょう。 PostgreSQLではログをLOCAL0からLOCAL7までのsyslogファシリティで記録することができます(syslog_facilityを参照してください)。 しかし、ほとんどのプラットフォームのデフォルトのsyslog設定ではこれらのメッセージはすべて破棄されます。 うまく動作させるために

local0.*    /var/log/postgresql

to the <application>syslog</application> daemon's configuration file to make it work. syslogデーモンの設定に追加しなければならないでしょう。

On Windows, when you use the <literal>eventlog</literal> option for <varname>log_destination</varname>, you should register an event source and its library with the operating system so that the Windows Event Viewer can display event log messages cleanly. See <xref linkend="event-log-registration"/> for details. Windowsでlog_destinationに対しeventlogオプションを使用する場合、Windows Event Viewer がイベントログメッセージを手際良く表示できるよう、オペレーティングシステムでイベントソースとそのライブラリを登録しなければなりません。 詳細は19.12を参照ください。

logging_collector (boolean) #

This parameter enables the <firstterm>logging collector</firstterm>, which is a background process that captures log messages sent to <systemitem>stderr</systemitem> and redirects them into log files. This approach is often more useful than logging to <application>syslog</application>, since some types of messages might not appear in <application>syslog</application> output. (One common example is dynamic-linker failure messages; another is error messages produced by scripts such as <varname>archive_command</varname>.) This parameter can only be set at server start. このパラメータはログ収集機構を有効にします。 それはstderrに送られたログメッセージを捕捉し、ログファイルにリダイレクトするバックグラウンドプロセスです。 この手法はsyslogへのログよりもしばしば有用です。 メッセージの一部の種類がsyslogでは出力されない可能性があるためです。 (一般的な例として、ダイナミックリンカのエラーメッセージがあり、その他の例としてarchive_commandのようなスクリプトにより生成されたエラーメッセージが挙げられます)。 このパラメータはサーバ起動時のみ設定可能です。

注記

It is possible to log to <systemitem>stderr</systemitem> without using the logging collector; the log messages will just go to wherever the server's <systemitem>stderr</systemitem> is directed. However, that method is only suitable for low log volumes, since it provides no convenient way to rotate log files. Also, on some platforms not using the logging collector can result in lost or garbled log output, because multiple processes writing concurrently to the same log file can overwrite each other's output. ログ収集機構を使用せずにstderrのログを取ることは可能です。 ログメッセージはサーバのstderrが指し示すいかなる場所にも向かうだけです。 しかし、その方法はログファイルを巡回させる都合のよい方法を提供しないので、ログ容量が小さい場合のみに適しています。 同時に、ログ収集機構を使用しないいくつかのプラットフォームにおいては、ログ出力が失われたり、文字化けします。なぜなら、同一のログファイルに同時に書き込みを行うマルチプロセッサはそれぞれの出力を上書きできるからです。

注記

The logging collector is designed to never lose messages. This means that in case of extremely high load, server processes could be blocked while trying to send additional log messages when the collector has fallen behind. In contrast, <application>syslog</application> prefers to drop messages if it cannot write them, which means it may fail to log some messages in such cases but it will not block the rest of the system. ログ収集機構はメッセージを決して失わないために設計されています。 これは、極端に高い負荷の場合、サーバプロセスはコレクタが遅れをとった場合、追加のログメッセージを送信しようと試みる時に阻止される可能性があります。 それとは対象的にsyslogは、もし書き込みができなかったときメッセージの廃棄を選びます。 これらの場合にはいくつかのログメッセージを失うことになりますが、残ったシステムを阻止しません。

log_directory (string) #

When <varname>logging_collector</varname> is enabled, this parameter determines the directory in which log files will be created. It can be specified as an absolute path, or relative to the cluster data directory. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. The default is <literal>log</literal>. logging_collectorを有効と設定した場合、このパラメータはログファイルが作成されるディレクトリを確定します。 ディレクトリは、絶対パス、もしくはデータベースクラスタのディレクトリに対する相対パスで指定することができます。 このパラメータはpostgresql.confファイル、またはサーバコマンドラインからのみ設定可能です。 デフォルトはlogです。

log_filename (string) #

When <varname>logging_collector</varname> is enabled, this parameter sets the file names of the created log files. The value is treated as a <function>strftime</function> pattern, so <literal>%</literal>-escapes can be used to specify time-varying file names. (Note that if there are any time-zone-dependent <literal>%</literal>-escapes, the computation is done in the zone specified by <xref linkend="guc-log-timezone"/>.) The supported <literal>%</literal>-escapes are similar to those listed in the Open Group's <ulink url="https://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html">strftime </ulink> specification. Note that the system's <function>strftime</function> is not used directly, so platform-specific (nonstandard) extensions do not work. The default is <literal>postgresql-%Y-%m-%d_%H%M%S.log</literal>. logging_collectorが有効な場合、このパラメータは作成されたログファイルのファイル名を設定します。 値はstrftimeパターンとして扱われるため、%エスケープを使用して、時刻によって変動するファイル名を指定することができます。 (時間帯に依存した%エスケープが存在する場合、log_timezoneで指定された時間帯で計算が行われます。) サポートされている%-エスケープはstrftime 仕様によく似ています。 システムのstrftimeは直接使用されないので、プラットフォーム固有の(非標準)の拡張は動作しません。 デフォルトはpostgresql-%Y-%m-%d_%H%M%S.logです。

If you specify a file name without escapes, you should plan to use a log rotation utility to avoid eventually filling the entire disk. In releases prior to 8.4, if no <literal>%</literal> escapes were present, <productname>PostgreSQL</productname> would append the epoch of the new log file's creation time, but this is no longer the case. エスケープすることなくファイル名を指定する場合、ディスク全体を使い切ってしまうことを防止するためにログローテーションを行うユーティリティを使用することを計画しなければなりません。 8.4より前のリリースのPostgreSQLでは、%エスケープがなければ、新しいログファイルの生成時のエポック時刻を付与しますが、これはもはや当てはまりません。

If CSV-format output is enabled in <varname>log_destination</varname>, <literal>.csv</literal> will be appended to the timestamped log file name to create the file name for CSV-format output. (If <varname>log_filename</varname> ends in <literal>.log</literal>, the suffix is replaced instead.) CSV書式の出力がlog_destinationで有効な場合、タイムスタンプ付きのログファイル名に.csvを付与し、最終的なCSV書式出力用のファイル名が作成されます。 (log_filename.logで終わる場合は後置詞が置き換えられます。)

If JSON-format output is enabled in <varname>log_destination</varname>, <literal>.json</literal> will be appended to the timestamped log file name to create the file name for JSON-format output. (If <varname>log_filename</varname> ends in <literal>.log</literal>, the suffix is replaced instead.) JSON書式の出力がlog_destinationで有効な場合、タイムスタンプ付きのログファイル名に.jsonを付与し、最終的なJSON書式出力用のファイル名が作成されます。 (log_filename.logで終わる場合は後置詞が置き換えられます。)

This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. このパラメータは、postgresql.confファイルか、サーバのコマンドラインでのみ設定可能です。

log_file_mode (integer) #

On Unix systems this parameter sets the permissions for log files when <varname>logging_collector</varname> is enabled. (On Microsoft Windows this parameter is ignored.) The parameter value is expected to be a numeric mode specified in the format accepted by the <function>chmod</function> and <function>umask</function> system calls. (To use the customary octal format the number must start with a <literal>0</literal> (zero).) Unixシステムにおいては、logging_collectorが有効になっている場合、このパラメータはログファイルのパーミッションを設定します。 (Microsoft Windowsではこのパラメータは無視されます。) パラメータの値はchmod および umaskシステムコールで許容されるフォーマットで指定される数値モードであると期待されます。 (慣例的な8進数フォーマットを使用する場合、番号は0(ゼロ)で始まらなければなりません。

The default permissions are <literal>0600</literal>, meaning only the server owner can read or write the log files. The other commonly useful setting is <literal>0640</literal>, allowing members of the owner's group to read the files. Note however that to make use of such a setting, you'll need to alter <xref linkend="guc-log-directory"/> to store the files somewhere outside the cluster data directory. In any case, it's unwise to make the log files world-readable, since they might contain sensitive data. デフォルトのパーミッションは0600で、意味するところはサーバの所有者のみログファイルの読み書きが可能です。 そのほか一般的に実用的な設定は0640で、所有者のグループはファイルを読み込めます。 しかし、これらの設定を活用するにはlog_directoryがクラスタデータディレクトリの外部のどこかにあるファイルを格納できるように変更する必要があります。

This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. このパラメータは、postgresql.confファイルか、サーバのコマンドラインでのみ設定可能です。

log_rotation_age (integer) #

When <varname>logging_collector</varname> is enabled, this parameter determines the maximum amount of time to use an individual log file, after which a new log file will be created. If this value is specified without units, it is taken as minutes. The default is 24 hours. Set to zero to disable time-based creation of new log files. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. logging_collectorが有効な場合、このパラメータは個々のログファイルの最大寿命を決定します。 ここで指定した時間経過すると、新しいログファイルが生成されます。 この値が単位なしで指定された場合は、分単位であるとみなします。 デフォルトは24時間です。 ゼロに設定することで、時間に基づいた新しいログファイルの生成は無効になります。 このパラメータは、postgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。

log_rotation_size (integer) #

When <varname>logging_collector</varname> is enabled, this parameter determines the maximum size of an individual log file. After this amount of data has been emitted into a log file, a new log file will be created. If this value is specified without units, it is taken as kilobytes. The default is 10 megabytes. Set to zero to disable size-based creation of new log files. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. logging_collectorが有効な場合、このパラメータは個々のログファイルの最大容量を決定します。 ここで指定したデータ量がログファイルに出力された後、新しいログファイルが生成されます。 この値が単位なしで指定された場合は、キロバイト単位であるとみなします。 デフォルトは10メガバイトです。 ゼロに設定することで、サイズに基づいた新しいログファイルの生成は無効になります。 このパラメータはpostgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。

log_truncate_on_rotation (boolean) #

When <varname>logging_collector</varname> is enabled, this parameter will cause <productname>PostgreSQL</productname> to truncate (overwrite), rather than append to, any existing log file of the same name. However, truncation will occur only when a new file is being opened due to time-based rotation, not during server startup or size-based rotation. When off, pre-existing files will be appended to in all cases. For example, using this setting in combination with a <varname>log_filename</varname> like <literal>postgresql-%H.log</literal> would result in generating twenty-four hourly log files and then cyclically overwriting them. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. logging_collectorが有効な場合、このパラメータにより、PostgreSQLは既存の同名のファイルに追加するのではなく、そのファイルを切り詰める(上書きする)ようになります。 しかし、切り詰めは時間を基にしたローテーションのために新規にファイルが開かれた時にのみ発生し、サーバ起動時やサイズを基にしたローテーションでは発生しません。 偽の場合、全ての場合において既存のファイルは追記されます。 例えば、この設定をpostgresql-%H.logのようなlog_filenameと組み合わせて使用すると、24個の時別のログファイルが生成され、それらは周期的に上書きされることになります。 このパラメータはpostgresql.confファイル、または、サーバのコマンドラインで設定されます。

Example: To keep 7 days of logs, one log file per day named <literal>server_log.Mon</literal>, <literal>server_log.Tue</literal>, etc., and automatically overwrite last week's log with this week's log, set <varname>log_filename</varname> to <literal>server_log.%a</literal>, <varname>log_truncate_on_rotation</varname> to <literal>on</literal>, and <varname>log_rotation_age</varname> to <literal>1440</literal>. 例:7日間のログを保存し、毎日のログを server_log.Monserver_log.Tue、等とし、そして自動的に前週のログを今週のログで上書きするには以下のように設定します。 log_filenameserver_log.%aとし、log_truncate_on_rotationonにし、そしてlog_rotation_age1440に設定します。

Example: To keep 24 hours of logs, one log file per hour, but also rotate sooner if the log file size exceeds 1GB, set <varname>log_filename</varname> to <literal>server_log.%H%M</literal>, <varname>log_truncate_on_rotation</varname> to <literal>on</literal>, <varname>log_rotation_age</varname> to <literal>60</literal>, and <varname>log_rotation_size</varname> to <literal>1000000</literal>. Including <literal>%M</literal> in <varname>log_filename</varname> allows any size-driven rotations that might occur to select a file name different from the hour's initial file name. 例:24時間のログを保持、1時間おきに1つのログファイルを作成、ただし、ログファイルのサイズが1ギガバイトを超えた場合それより早く切り替えさせるには、log_filenameserver_log.%H%Mにし、log_truncate_on_rotationonにし、log_rotation_age60にし、そしてlog_rotation_size1000000に設定します。 log_filename%Mを含めると、サイズを元にしたローテーションが時間毎の始めのファイル名とは異なる名前のファイルを選択するようにできます。

syslog_facility (enum) #

When logging to <application>syslog</application> is enabled, this parameter determines the <application>syslog</application> <quote>facility</quote> to be used. You can choose from <literal>LOCAL0</literal>, <literal>LOCAL1</literal>, <literal>LOCAL2</literal>, <literal>LOCAL3</literal>, <literal>LOCAL4</literal>, <literal>LOCAL5</literal>, <literal>LOCAL6</literal>, <literal>LOCAL7</literal>; the default is <literal>LOCAL0</literal>. See also the documentation of your system's <application>syslog</application> daemon. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. syslogへのログ取得が有効な場合、このパラメータはsyslogfacilityが使われるように確定します。 LOCAL0LOCAL1LOCAL2LOCAL3LOCAL4LOCAL5LOCAL6LOCAL7の中から選んでください。 デフォルトはLOCAL0です。 使用しているシステムのsyslogデーモンの文書を同時に参照してください。 このパラメータはpostgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。

syslog_ident (string) #

When logging to <application>syslog</application> is enabled, this parameter determines the program name used to identify <productname>PostgreSQL</productname> messages in <application>syslog</application> logs. The default is <literal>postgres</literal>. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. syslogにログ取得が有効な場合、このパラメータはsyslogログ内のPostgreSQLメッセージを特定するのに使用するプログラム名を確定します。デフォルトはpostgresです。 このパラメータは、postgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。

syslog_sequence_numbers (boolean) #

When logging to <application>syslog</application> and this is on (the default), then each message will be prefixed by an increasing sequence number (such as <literal>[2]</literal>). This circumvents the <quote>&#45;&#45;- last message repeated N times &#45;&#45;-</quote> suppression that many syslog implementations perform by default. In more modern syslog implementations, repeated message suppression can be configured (for example, <literal>$RepeatedMsgReduction</literal> in <productname>rsyslog</productname>), so this might not be necessary. Also, you could turn this off if you actually want to suppress repeated messages. syslogにログを出力している場合で、これがオン(デフォルト)であると、各メッセージには([2]のような)増加する順序数が頭に追加されます。 これにより、多くのsyslogの実装がデフォルトで行う--- last message repeated N times ---による出力の抑止が回避されます。 より近代的なsyslogの実装では、繰り返されるメッセージの抑止は設定変更できるので(たとえば、rsyslog)における$RepeatedMsgReduction)、この機能は必要ないかもしれません。 繰り返されるメッセージを抑止したい場合には、これをオフにできます。

This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. このパラメータは、postgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。

syslog_split_messages (boolean) #

When logging to <application>syslog</application> is enabled, this parameter determines how messages are delivered to syslog. When on (the default), messages are split by lines, and long lines are split so that they will fit into 1024 bytes, which is a typical size limit for traditional syslog implementations. When off, PostgreSQL server log messages are delivered to the syslog service as is, and it is up to the syslog service to cope with the potentially bulky messages. syslogへのログ出力が有効な場合、このパラメータはメッセージがどのようにsyslogに送られるかを規定します。 オンなら(デフォルト)、メッセージは行に分割され、長い行は、伝統的なsyslog実装のサイズ上限である1024バイト以内に分割されます。 オフならば、PostgreSQLサーバログメッセージは、そのままsyslogサービスに送られます。 大きなサイズになるかもしれないメッセージにどう対応するかは、syslogサービス次第となります。

If syslog is ultimately logging to a text file, then the effect will be the same either way, and it is best to leave the setting on, since most syslog implementations either cannot handle large messages or would need to be specially configured to handle them. But if syslog is ultimately writing into some other medium, it might be necessary or more useful to keep messages logically together. もしsyslogが最終的にテキストファイルにログを出力するのであれば、どちらに設定しても効果は同じです。 設定値をオンにしておくのが最善です。 多くのsyslogの実装では、長いメッセージを扱えないか、長いメッセージを扱うための特別な設定が必要だからです。 しかし、syslogが最終的に他のメディアに書き込むのであれば、メッセージを論理的に一緒にしておくことが必要か、もしくは有用です。

This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. このパラメータはpostgresql.confファイル内、またはサーバのコマンドラインのみで設定可能です。

event_source (string) #

When logging to <application>event log</application> is enabled, this parameter determines the program name used to identify <productname>PostgreSQL</productname> messages in the log. The default is <literal>PostgreSQL</literal>. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. event logへのログ取得が有効になっていると、このパラメータはログ中のPostgreSQLメッセージを特定するのに使用されるプログラム名を決定します。デフォルトはPostgreSQLです。このパラメータは、postgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。

20.8.2. いつログを取得するか #

<title>When to Log</title>
log_min_messages (enum) #

Controls which <link linkend="runtime-config-severity-levels">message levels</link> are written to the server log. Valid values are <literal>DEBUG5</literal>, <literal>DEBUG4</literal>, <literal>DEBUG3</literal>, <literal>DEBUG2</literal>, <literal>DEBUG1</literal>, <literal>INFO</literal>, <literal>NOTICE</literal>, <literal>WARNING</literal>, <literal>ERROR</literal>, <literal>LOG</literal>, <literal>FATAL</literal>, and <literal>PANIC</literal>. Each level includes all the levels that follow it. The later the level, the fewer messages are sent to the log. The default is <literal>WARNING</literal>. Note that <literal>LOG</literal> has a different rank here than in <xref linkend="guc-client-min-messages"/>. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. どのメッセージレベルをサーバログに書き込むかを管理します。 有効な値はDEBUG5DEBUG4DEBUG3DEBUG2DEBUG1INFONOTICEWARNINGERRORLOGFATAL、およびPANICです。 それぞれの階層はその下の全ての階層を含みます。階層を低くする程、より少ないメッセージがログに送られます。 デフォルトはWARNINGです。 ここでのLOGの優先順位がclient_min_messagesの場合と異なることに注意してください。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

log_min_error_statement (enum) #

Controls which SQL statements that cause an error condition are recorded in the server log. The current SQL statement is included in the log entry for any message of the specified <link linkend="runtime-config-severity-levels">severity</link> or higher. Valid values are <literal>DEBUG5</literal>, <literal>DEBUG4</literal>, <literal>DEBUG3</literal>, <literal>DEBUG2</literal>, <literal>DEBUG1</literal>, <literal>INFO</literal>, <literal>NOTICE</literal>, <literal>WARNING</literal>, <literal>ERROR</literal>, <literal>LOG</literal>, <literal>FATAL</literal>, and <literal>PANIC</literal>. The default is <literal>ERROR</literal>, which means statements causing errors, log messages, fatal errors, or panics will be logged. To effectively turn off logging of failing statements, set this parameter to <literal>PANIC</literal>. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. エラー条件の原因となったどのSQL文をサーバログに記録するかを制御します。 設定したレベル以上のメッセージについては現在のSQL文がログに記録されます。 有効な値は、DEBUG5DEBUG4DEBUG3DEBUG2DEBUG1INFONOTICEWARNINGERRORLOGFATALPANICです。 デフォルトはERRORです。 エラー、ログメッセージ、致命的エラー、パニックを引き起こした文がログに記録されることを意味します。 失敗した文の記録を実質的に無効にするには、このパラメータをPANICに設定してください。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

log_min_duration_statement (integer) #

Causes the duration of each completed statement to be logged if the statement ran for at least the specified amount of time. For example, if you set it to <literal>250ms</literal> then all SQL statements that run 250ms or longer will be logged. Enabling this parameter can be helpful in tracking down unoptimized queries in your applications. If this value is specified without units, it is taken as milliseconds. Setting this to zero prints all statement durations. <literal>-1</literal> (the default) disables logging statement durations. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. 文の実行に少なくとも指定した時間かかった場合、それぞれの文の実行に要した時間をログに記録します。 例えば、250msと設定した場合、250msもしくはそれ以上長くかかった全てのSQL文がログとして残ります。 このパラメータを有効にすることにより、アプリケーションで最適化されていない問い合わせを追跡するのが便利になります。 この値が単位なしで指定された場合は、ミリ秒単位であるとみなします。 0に設定すれば、すべての文の実行時間が出力されます。 -1(デフォルト)は、文実行時間の記録を無効にします。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

This overrides <xref linkend="guc-log-min-duration-sample"/>, meaning that queries with duration exceeding this setting are not subject to sampling and are always logged. これはlog_min_duration_sampleを上書きします。つまり、問い合わせがこの設定を越えると、実行時間のサンプリングの対象にならず、常に記録されます。

For clients using extended query protocol, durations of the Parse, Bind, and Execute steps are logged independently. 拡張問い合わせプロトコルを使用するクライアントでは、Parse、Bind、Executeそれぞれの段階で要した時間が独立して記録されます。

注記

When using this option together with <xref linkend="guc-log-statement"/>, the text of statements that are logged because of <varname>log_statement</varname> will not be repeated in the duration log message. If you are not using <application>syslog</application>, it is recommended that you log the PID or session ID using <xref linkend="guc-log-line-prefix"/> so that you can link the statement message to the later duration message using the process ID or session ID. このオプションとlog_statementを一緒に使用する時、log_statementによって記録されるテキスト文は、実行時間のログには重複されません。 syslogを使用していなければ、プロセスIDとセッションIDを使用して、文メッセージと後の実行時間メッセージを関連付けできるように、log_line_prefixを使用してPIDまたはセッションIDをログに記録することを勧めます。

log_min_duration_sample (integer) #

Allows sampling the duration of completed statements that ran for at least the specified amount of time. This produces the same kind of log entries as <xref linkend="guc-log-min-duration-statement"/>, but only for a subset of the executed statements, with sample rate controlled by <xref linkend="guc-log-statement-sample-rate"/>. For example, if you set it to <literal>100ms</literal> then all SQL statements that run 100ms or longer will be considered for sampling. Enabling this parameter can be helpful when the traffic is too high to log all queries. If this value is specified without units, it is taken as milliseconds. Setting this to zero samples all statement durations. <literal>-1</literal> (the default) disables sampling statement durations. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. 指定した時間以上で実行完了した文の実行時間のサンプルを許可します。 これによりlog_min_duration_statementと同様ですが、log_statement_sample_rateで制御するレートでサンプルされた実行時間のサブセットのログエントリを生成します。 たとえば、100msに設定すると、100ミリ秒以上かかったSQL文がサンプルの対象となります。 このパラメータを有効にすることで、トラフィックが多すぎてすべての問い合わせをログできない状況で助けになることもあります。 この値を単位無しで指定すると、ミリ秒と見なされます。 これをゼロに設定すると、すべての文の実行時間がサンプルされます。 -1(デフォルトです)とすると、文の実行時間のサンプリングが無効になります。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

This setting has lower priority than <varname>log_min_duration_statement</varname>, meaning that statements with durations exceeding <varname>log_min_duration_statement</varname> are not subject to sampling and are always logged. この設定はlog_min_duration_statementよりも優先度が低いです。つまり、log_min_duration_statementを超えた実行時間の文はサンプリングの対象となり、常に記録されます。

Other notes for <varname>log_min_duration_statement</varname> apply also to this setting. log_min_duration_statementのその他の注意事項もこの設定に適用されます。

log_statement_sample_rate (floating point) #

Determines the fraction of statements with duration exceeding <xref linkend="guc-log-min-duration-sample"/> that will be logged. Sampling is stochastic, for example <literal>0.5</literal> means there is statistically one chance in two that any given statement will be logged. The default is <literal>1.0</literal>, meaning to log all sampled statements. Setting this to zero disables sampled statement-duration logging, the same as setting <varname>log_min_duration_sample</varname> to <literal>-1</literal>. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. log_min_duration_sampleを越え、記録対象となる文の割合を決定します。 サンプリングは確率論的で、たとえば0.5は2つの文のうちひとつが統計的に記録対象になることを意味します。 デフォルトは1.0で、サンプルされた文はすべて記録対象となります。 ゼロに設定すると、log_min_duration_sample-1にしたのと同じで、文の実行時間のサンプルを記録しません。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

log_transaction_sample_rate (floating point) #

Sets the fraction of transactions whose statements are all logged, in addition to statements logged for other reasons. It applies to each new transaction regardless of its statements' durations. Sampling is stochastic, for example <literal>0.1</literal> means there is statistically one chance in ten that any given transaction will be logged. <varname>log_transaction_sample_rate</varname> can be helpful to construct a sample of transactions. The default is <literal>0</literal>, meaning not to log statements from any additional transactions. Setting this to <literal>1</literal> logs all statements of all transactions. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. 他の理由に加え、トランザクションの文のうち、ログの対象となる割合を設定します。 文の実行時間にかかわらず、新しいトランザクションに適用されます。 サンプリングは確率論的で、たとえば0.1は10のトランザクションのうちひとつが統計的に記録対象になることを意味します。 デフォルトは0で、これは追加のトランザクションのログを取らないことを意味します。 1に設定すると、すべてのトランザクションのすべての文のログを取ります。 log_transaction_sample_rateは、トランザクションのサンプルを調査するのに役立ちます。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

注記

Like all statement-logging options, this option can add significant overhead. 他の文のログを取るオプション同様、このオプションも大きなオーバーヘッドを与える可能性があります。

log_startup_progress_interval (integer) #

Sets the amount of time after which the startup process will log a message about a long-running operation that is still in progress, as well as the interval between further progress messages for that operation. The default is 10 seconds. A setting of <literal>0</literal> disables the feature. If this value is specified without units, it is taken as milliseconds. This setting is applied separately to each operation. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. 起動プロセスが実行中の長時間実行操作に関するメッセージをログに記録するまでの時間と、その操作に関する次の進行状況メッセージの間隔を設定します。 デフォルトは10秒です。 0に設定すると、この機能は無効になります。この値を単位なしで指定すると、ミリ秒とみなされます。 この設定は、各操作に個別に適用されます。 このパラメータは、postgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。

For example, if syncing the data directory takes 25 seconds and thereafter resetting unlogged relations takes 8 seconds, and if this setting has the default value of 10 seconds, then a messages will be logged for syncing the data directory after it has been in progress for 10 seconds and again after it has been in progress for 20 seconds, but nothing will be logged for resetting unlogged relations. たとえば、データディレクトリの同期に25秒かかり、その後、unloggedリレーションのリセットに8秒かかったとします。 この設定がデフォルト値の10秒である場合、データディレクトリを同期するためのメッセージは、10秒間処理された後と20秒間処理された後に記録されますが、unloggedリレーションのリセットに関しては何も記録されません。

<xref linkend="runtime-config-severity-levels"/> explains the message severity levels used by <productname>PostgreSQL</productname>. If logging output is sent to <systemitem>syslog</systemitem> or Windows' <systemitem>eventlog</systemitem>, the severity levels are translated as shown in the table. 表 20.2で、PostgreSQLで使用されるメッセージ深刻度レベルを説明します。 ログ出力がsyslogまたはWindowsのeventlogに送られる場合、この深刻度レベルは表で示すように変換されます。

表20.2 メッセージ深刻度レベル

<title>Message Severity Levels</title>
深刻度使用方法syslogeventlog
DEBUG1 .. DEBUG5開発者が使用する連続的かつより詳細な情報を提供します。DEBUGINFORMATION
INFOVACUUM VERBOSEの出力などの、ユーザによって暗黙的に要求された情報を提供します。INFOINFORMATION
NOTICE長い識別子の切り詰めに関する注意など、ユーザの補助になる情報を提供します。NOTICEINFORMATION
WARNINGトランザクションブロック外でのCOMMITの様な、ユーザへの警告を提供します。NOTICEWARNING
ERROR現在のコマンドを中断させる原因となったエラーを報告します。WARNINGERROR
LOGチェックポイントの活動の様な、管理者に関心のある情報を報告します。INFOINFORMATION
FATAL現在のセッションを中断させる原因となったエラーを報告します。ERRERROR
PANIC全てのデータベースセッションを中断させる原因となったエラーを報告します。CRITERROR

20.8.3. 何をログに #

<title>What to Log</title>

注記

What you choose to log can have security implications; see <xref linkend="logfile-maintenance"/>. ログに記録する内容は、セキュリティに影響を与える可能性があります。 25.3を参照してください。

application_name (string) #

The <varname>application_name</varname> can be any string of less than <symbol>NAMEDATALEN</symbol> characters (64 characters in a standard build). It is typically set by an application upon connection to the server. The name will be displayed in the <structname>pg_stat_activity</structname> view and included in CSV log entries. It can also be included in regular log entries via the <xref linkend="guc-log-line-prefix"/> parameter. Only printable ASCII characters may be used in the <varname>application_name</varname> value. Other characters will be replaced with question marks (<literal>?</literal>). application_nameNAMEDATALEN(標準構築では64)文字以下の任意の文字列を指定できます。 通常はサーバへの接続時にアプリケーションによって設定されます。 この名前は pg_stat_activityビューに表示され、CSVログに含まれます。 またlog_line_prefixパラメータにより通常のログ項目に含めることができます。 application_nameには表示可能なASCII文字のみ使用することができ、それ以外の文字は疑問符(?)に置換されます。

debug_print_parse (boolean)
debug_print_rewritten (boolean)
debug_print_plan (boolean) #

These parameters enable various debugging output to be emitted. When set, they print the resulting parse tree, the query rewriter output, or the execution plan for each executed query. These messages are emitted at <literal>LOG</literal> message level, so by default they will appear in the server log but will not be sent to the client. You can change that by adjusting <xref linkend="guc-client-min-messages"/> and/or <xref linkend="guc-log-min-messages"/>. These parameters are off by default. これらのパラメータは生成される各種デバッグ出力を有効にします。 設定すると実行された問い合わせそれぞれに対し、最終的な解析ツリー、問い合わせリライタの出力、実行計画を出力します。 これらのメッセージはLOGメッセージレベルで出力されますので、デフォルトではサーバログに出力され、クライアントには渡されません。 client_min_messageslog_min_messagesまたはその両方を調整することで変更することができます。 デフォルトではこれらのパラメータは無効です。

debug_pretty_print (boolean) #

When set, <varname>debug_pretty_print</varname> indents the messages produced by <varname>debug_print_parse</varname>, <varname>debug_print_rewritten</varname>, or <varname>debug_print_plan</varname>. This results in more readable but much longer output than the <quote>compact</quote> format used when it is off. It is on by default. 設定された場合、debug_pretty_printdebug_print_parsedebug_print_rewritten、またはdebug_print_planで生成されたメッセージを字下げします。 設定されない場合のコンパクト形式よりもより見やすく、しかしより長いものとなります。デフォルトは有効です。

log_autovacuum_min_duration (integer) #

Causes each action executed by autovacuum to be logged if it ran for at least the specified amount of time. Setting this to zero logs all autovacuum actions. <literal>-1</literal> disables logging autovacuum actions. If this value is specified without units, it is taken as milliseconds. For example, if you set this to <literal>250ms</literal> then all automatic vacuums and analyzes that run 250ms or longer will be logged. In addition, when this parameter is set to any value other than <literal>-1</literal>, a message will be logged if an autovacuum action is skipped due to a conflicting lock or a concurrently dropped relation. The default is <literal>10min</literal>. Enabling this parameter can be helpful in tracking autovacuum activity. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line; but the setting can be overridden for individual tables by changing table storage parameters. 少なくとも指定時間実行した場合、autovacuumで実行される各活動がログに残るようになります。 これをゼロに設定すると、すべてのautovacuumの活動がログに残ります。 -1はautovacuum活動のログを無効にします。 この値が単位なしで指定された場合は、ミリ秒単位であるとみなします。 例えば、これを250msに設定すると、250ms以上かかって実行されたautovacuumやanalyzeはすべてログに残ります。 さらに、-1以外の値にこのパラメータが設定された場合、競合するロックや並行して削除されたリレーションによりautovacuum動作がスキップされるとメッセージはログに記録されます。 デフォルトは10minです。 このパラメータを有効にすることは、autovacuum活動の追跡に役に立ちます。 このパラメータはpostgresql.confファイル、または、サーバのコマンドラインでのみで設定されます。 ただし、この設定はテーブルストレージパラメータの変更により、それぞれのテーブルに対して上書きすることができます。

log_checkpoints (boolean) #

Causes checkpoints and restartpoints to be logged in the server log. Some statistics are included in the log messages, including the number of buffers written and the time spent writing them. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. The default is on. チェックポイントおよびリスタートポイントをサーバログに記録するようにします。 書き出されたバッファ数や書き出しに要した時間など、いくつかの統計情報がこのログメッセージに含まれます。 このパラメータはpostgresql.confファイルまたはサーバのコマンドラインでのみ設定可能です。 デフォルトはonです。

log_connections (boolean) #

Causes each attempted connection to the server to be logged, as well as successful completion of both client authentication (if necessary) and authorization. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this parameter at session start, and it cannot be changed at all within a session. The default is <literal>off</literal>. サーバへの接続試行とともに、クライアント認証の成功終了と(必要ならば)承認をログに残します。 スーパーユーザと、適切なSET権限を持つユーザだけがセッション開始時にこのパラメータを変更でき、セッションが開始された後は変更できません。 デフォルトはoffです。

注記

Some client programs, like <application>psql</application>, attempt to connect twice while determining if a password is required, so duplicate <quote>connection received</quote> messages do not necessarily indicate a problem. psqlなどクライアントプログラムは、パスワードが要求されているかどうか確認するまで2回接続を試みるので、二重のconnection receivedメッセージは必ずしも問題を示すものではありません。

log_disconnections (boolean) #

Causes session terminations to be logged. The log output provides information similar to <varname>log_connections</varname>, plus the duration of the session. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this parameter at session start, and it cannot be changed at all within a session. The default is <literal>off</literal>. セッションの終了をログします。 ログ出力の情報はlog_connectionsと同様で、更にセッションの経過時間が追加されます。 スーパーユーザと、適切なSET権限を持つユーザだけがセッション開始時にこのパラメータを変更でき、セッションが開始された後は変更できません。 デフォルトはoffです。

log_duration (boolean) #

Causes the duration of every completed statement to be logged. The default is <literal>off</literal>. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. すべての完了した文について、その経過時間をログするようにします。 デフォルトはoffです。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

For clients using extended query protocol, durations of the Parse, Bind, and Execute steps are logged independently. 拡張問い合わせプロトコルを使用するクライアントでは、Parse、Bind、Executeそれぞれの段階で要した時間が独立して記録されます。

注記

The difference between enabling <varname>log_duration</varname> and setting <xref linkend="guc-log-min-duration-statement"/> to zero is that exceeding <varname>log_min_duration_statement</varname> forces the text of the query to be logged, but this option doesn't. Thus, if <varname>log_duration</varname> is <literal>on</literal> and <varname>log_min_duration_statement</varname> has a positive value, all durations are logged but the query text is included only for statements exceeding the threshold. This behavior can be useful for gathering statistics in high-load installations. log_durationを有効にするのとlog_min_duration_statementを0に設定する方法との違いは、log_min_duration_statementを超えた場合、テキスト版の問い合わせが強制的に出力されるのに対して、このオプションでは出力されないという点です。 したがって、log_durationon、かつ、log_min_duration_statementが正の値を持つ場合、すべての経過時間がログに記録されますが、閾値を超えた文のみがテキスト版の問い合わせが含められるようになります。 この動作は、高負荷なインストレーションで統計情報を収集する際に有用です。

log_error_verbosity (enum) #

Controls the amount of detail written in the server log for each message that is logged. Valid values are <literal>TERSE</literal>, <literal>DEFAULT</literal>, and <literal>VERBOSE</literal>, each adding more fields to displayed messages. <literal>TERSE</literal> excludes the logging of <literal>DETAIL</literal>, <literal>HINT</literal>, <literal>QUERY</literal>, and <literal>CONTEXT</literal> error information. <literal>VERBOSE</literal> output includes the <symbol>SQLSTATE</symbol> error code (see also <xref linkend="errcodes-appendix"/>) and the source code file name, function name, and line number that generated the error. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. ログ取得されるそれぞれのメッセージに対し、サーバログに書き込まれる詳細の量を制御します。 有効な値は、TERSEDEFAULT、およびVERBOSEで、それぞれは表示されるメッセージにより多くのフィールドを追加します。 TERSEDETAILHINTQUERY、およびCONTEXTエラー情報を除外します。 VERBOSE出力は、SQLSTATEエラーコード(付録Aも参照)、および、ソースコードファイル名、関数名、そしてエラーを生成した行番号を含みます。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

log_hostname (boolean) #

By default, connection log messages only show the IP address of the connecting host. Turning this parameter on causes logging of the host name as well. Note that depending on your host name resolution setup this might impose a non-negligible performance penalty. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. デフォルトでは、接続ログメッセージは接続元ホストのIPアドレスのみを表示します。 このパラメータを有効にすると、ホスト名もログに残るようになります。 ホスト名解決方法の設定に依存しますが、これが無視できないほどの性能劣化を起こす可能性があることに注意してください。 このパラメータはpostgresql.confファイル内、またはサーバのコマンドラインのみで設定可能です。

log_line_prefix (string) #

This is a <function>printf</function>-style string that is output at the beginning of each log line. <literal>%</literal> characters begin <quote>escape sequences</quote> that are replaced with status information as outlined below. Unrecognized escapes are ignored. Other characters are copied straight to the log line. Some escapes are only recognized by session processes, and will be treated as empty by background processes such as the main server process. Status information may be aligned either left or right by specifying a numeric literal after the % and before the option. A negative value will cause the status information to be padded on the right with spaces to give it a minimum width, whereas a positive value will pad on the left. Padding can be useful to aid human readability in log files. これは、各ログ行の先頭に出力するprintfの書式文字列です。 %から始まるエスケープシーケンスは、後述の通りのステータス情報で置き換えられます。 この他のエスケープは無視されます。 他の文字はそのままログ行に出力されます。 エスケープの中には、セッションプロセスによってのみ認識可能なものがあり、これらはメインサーバプロセスなどのバックグラウンドプロセスでは空文字として扱われます。 状態情報は%の後かつオプションの前に数字を指定することにより、左寄せまた右寄せにすることができます。 数字が負ならば状態情報を右側に空白を詰めて最小限の幅にし、正の値は左に空白を詰めます。 ログファイルではパディングは人間の視認性を向上させるので有用です。

This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. The default is <literal>'%m [%p] '</literal> which logs a time stamp and the process ID. このパラメータは、postgresql.confファイル、または、サーバのコマンドラインでのみで設定することができます。 デフォルトは、タイムスタンプとプロセスIDをログ出力する'%m [%p] 'です。

エスケープ効果セッションのみ
%aアプリケーション名
%uユーザ名
%dデータベース名
%r遠隔ホスト名、またはIPアドレス、およびポート番号
%h遠隔ホスト名、またはIPアドレス
%bバックエンドタイプ×
%pプロセス識別子×
%Pこのプロセスがパラレルクエリワーカーである場合に、パラレルグループリーダーのプロセス識別子×
%tミリ秒無しのタイムスタンプ×
%mミリ秒付きタイムスタンプ×
%nミリ秒付きタイムスタンプ(Unixエポックとして)×
%iコマンドタグ。セッションの現在のコマンド種類
%eSQLSTATE エラーコード×
%cセッションID。下記参照×
%l各セッションまたは各プロセスのログ行の番号。1から始まります。×
%sプロセスの開始タイムスタンプ×
%v仮想トランザクションID(backendID/localXID)。 74.1参照×
%xトランザクションID(何もアサインされていない場合0)。 74.1参照×
%q何も出力しません。 非セッションプロセスではこのエスケープ以降の出力を停止します。 セッションプロセスでは無視されます。×
%Q現在の問い合わせの問い合わせ識別子。問い合わせ識別子はデフォルトでは計算されません。 ですからcompute_query_idパラメータが有効であるか、あるいは問い合わせ識別子を計算するサードパーティのモジュールが設定されていないければゼロとなります。
%%%文字そのもの×

The backend type corresponds to the column <structfield>backend_type</structfield> in the view <link linkend="monitoring-pg-stat-activity-view"> <structname>pg_stat_activity</structname></link>, but additional types can appear in the log that don't show in that view. バックエンドタイプはpg_stat_activityビューのbackend_typeに関連します。しかし、ビューにない他のタイプがログに現れることがあります。

The <literal>%c</literal> escape prints a quasi-unique session identifier, consisting of two 4-byte hexadecimal numbers (without leading zeros) separated by a dot. The numbers are the process start time and the process ID, so <literal>%c</literal> can also be used as a space saving way of printing those items. For example, to generate the session identifier from <literal>pg_stat_activity</literal>, use this query: %cエスケープは、2つの4バイトの16進数(先頭のゼロは省略)をドットで区切った構成の、準一意なセッション識別子を表示します。 この数値はプロセスの起動時間とそのプロセスIDです。 したがって、%cを使用して、これらの項目を出力するための文字数を省略することができます。例として、pg_stat_activityからセッション識別子を生成するには以下の問い合わせを行ないます。

SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' ||
       to_hex(pid)
FROM pg_stat_activity;

ヒント

If you set a nonempty value for <varname>log_line_prefix</varname>, you should usually make its last character be a space, to provide visual separation from the rest of the log line. A punctuation character can be used too. log_line_prefixに空白文字以外の値を設定する場合、通常、ログ行の残りとの区切りを明確にするために、その最後の文字を空白文字にすべきです。 句読点用の文字も使用できます。

ヒント

<application>Syslog</application> produces its own time stamp and process ID information, so you probably do not want to include those escapes if you are logging to <application>syslog</application>. Syslogは独自にタイムスタンプとプロセスID情報を生成します。 ですのでおそらく、Syslogにログを保管する場合は、こうしたエスケープを含めるとは考えないでしょう。

ヒント

The <literal>%q</literal> escape is useful when including information that is only available in session (backend) context like user or database name. For example: %qエスケープは、ユーザやデータベース名のように、セッション(バックエンド)コンテキストでのみ存在する情報を含める場合に有用です。 %q

log_line_prefix = '%m [%p] %q%u@%d/%a '

注記

The <literal>%Q</literal> escape always reports a zero identifier for lines output by <xref linkend="guc-log-statement"/> because <varname>log_statement</varname> generates output before an identifier can be calculated, including invalid statements for which an identifier cannot be calculated. 識別子が計算できない不正な文も含め、log_statementは識別子が計算可能になる前に出力を生成するため、%Qエスケープは、log_statementが生成する行では常にゼロの識別子を報告します。

log_lock_waits (boolean) #

Controls whether a log message is produced when a session waits longer than <xref linkend="guc-deadlock-timeout"/> to acquire a lock. This is useful in determining if lock waits are causing poor performance. The default is <literal>off</literal>. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. セッションがロックの獲得までの間にdeadlock_timeoutより長く待機する場合にログメッセージを生成するかどうかを制御します。 これは、ロック待ちによって性能がでていないのかどうか確認する時に有用です。 デフォルトはoffです。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

log_recovery_conflict_waits (boolean) #

Controls whether a log message is produced when the startup process waits longer than <varname>deadlock_timeout</varname> for recovery conflicts. This is useful in determining if recovery conflicts prevent the recovery from applying WAL. スタートアッププロセスがdeadlock_timeoutよりも長くリカバリコンフリクトを待つ場合にログメッセージを出力するかどうかを制御します。 リカバリコンフリクトによってリカバリがWALを適用するのを妨げられているかどうかを決定するのに有用です。

The default is <literal>off</literal>. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. デフォルトはoffです。 このパラメータはpostgresql.confファイル、または、サーバのコマンドラインのみで設定可能です。

log_parameter_max_length (integer) #

If greater than zero, each bind parameter value logged with a non-error statement-logging message is trimmed to this many bytes. Zero disables logging of bind parameters for non-error statement logs. <literal>-1</literal> (the default) allows bind parameters to be logged in full. If this value is specified without units, it is taken as bytes. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. ゼロよりも大きければ、エラーではない時にバインドパラメータ値が、文とともにこの指定バイト数に短縮されて記録されます。 ゼロなら、エラーではない時のバインドパラメータ値と文の記録は行われません。 -1(デフォルトです)ならバインドパラメータはすべて記録されます。 この値が単位なしに指定されると、バイト単位と見なされます。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

This setting only affects log messages printed as a result of <xref linkend="guc-log-statement"/>, <xref linkend="guc-log-duration"/>, and related settings. Non-zero values of this setting add some overhead, particularly if parameters are sent in binary form, since then conversion to text is required. この設定は、log_statementlog_durationおよび関連設定の結果を表示するログメッセージにのみ影響します。 ゼロ以外の値の設定は、とりわけパラメータがバイナリ形式で送信される際に多少のオーバーヘッドをもたらします。 テキストへの変換が必要になるからです。

log_parameter_max_length_on_error (integer) #

If greater than zero, each bind parameter value reported in error messages is trimmed to this many bytes. Zero (the default) disables including bind parameters in error messages. <literal>-1</literal> allows bind parameters to be printed in full. If this value is specified without units, it is taken as bytes. ゼロよりも大きければ、エラー時のバインドパラメータ値が、エラーメッセージ中にこの指定バイト数に短縮されて記録されます。 ゼロ(デフォルトです)ならエラーメッセージ中のバインドパラメータは記録されません。 -1ならバインドパラメータはすべて記録されます。 この値が単位なしに指定されると、バイト単位と見なされます。

Non-zero values of this setting add overhead, as <productname>PostgreSQL</productname> will need to store textual representations of parameter values in memory at the start of each statement, whether or not an error eventually occurs. The overhead is greater when bind parameters are sent in binary form than when they are sent as text, since the former case requires data conversion while the latter only requires copying the string. ゼロ以外の値の設定は多少のオーバーヘッドをもたらします。 エラーが起きるかどうかに関わらず、PostgreSQLは文を開始する際にテキスト形式のパラメータ値をメモリに保存する必要があるからです。 パラメータがバイナリ形式で送信される場合にテキスト形式で送信するよりもオーバーヘッドが大きくなります。 前者はデータ変換が必要なのに対し、後者は単に文字列をコピーするだけだからです。

log_statement (enum) #

Controls which SQL statements are logged. Valid values are <literal>none</literal> (off), <literal>ddl</literal>, <literal>mod</literal>, and <literal>all</literal> (all statements). <literal>ddl</literal> logs all data definition statements, such as <command>CREATE</command>, <command>ALTER</command>, and <command>DROP</command> statements. <literal>mod</literal> logs all <literal>ddl</literal> statements, plus data-modifying statements such as <command>INSERT</command>, <command>UPDATE</command>, <command>DELETE</command>, <command>TRUNCATE</command>, and <command>COPY FROM</command>. <command>PREPARE</command>, <command>EXECUTE</command>, and <command>EXPLAIN ANALYZE</command> statements are also logged if their contained command is of an appropriate type. For clients using extended query protocol, logging occurs when an Execute message is received, and values of the Bind parameters are included (with any embedded single-quote marks doubled). どのSQL文をログに記録するかを制御します。 有効な値は、none(off)、ddlmod、およびall(全ての文)です。 ddlは、CREATEALTER、およびDROP文といった、データ定義文を全てログに記録します。 modは、全てのddl文に加え、INSERTUPDATEDELETETRUNCATE、およびCOPY FROMといった、データ変更文をログに記録します。 PREPAREEXECUTEおよびEXPLAIN ANALYZEコマンドも、そこに含まれるコマンドが適切な種類であればログが録られます。 拡張問い合わせプロトコルを使用するクライアントでは、Executeメッセージを受け取った時にBindパラメータの値が(すべての単一引用符が二重にされた状態で)含まれていた場合、ログに記録されます。

The default is <literal>none</literal>. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. デフォルトはnoneです。 スーパーユーザーおよび適切なSET権限を持つユーザーのみがこの設定を変更できます。

注記

Statements that contain simple syntax errors are not logged even by the <varname>log_statement</varname> = <literal>all</literal> setting, because the log message is emitted only after basic parsing has been done to determine the statement type. In the case of extended query protocol, this setting likewise does not log statements that fail before the Execute phase (i.e., during parse analysis or planning). Set <varname>log_min_error_statement</varname> to <literal>ERROR</literal> (or lower) to log such statements. ログメッセージの発行は、基本解析により文の種類が決まった後に行われますので、log_statement = allという設定を行ったとしても、単純な構文エラーを持つ文は記録されません。 拡張問い合わせプロトコルの場合も同様に、この設定ではExecute段階以前(つまり、解析や計画作成期間)に失敗した文は記録されません。 こうした文のログを記録するには、log_min_error_statementERROR(以下)に設定してください。

Logged statements might reveal sensitive data and even contain plaintext passwords. ログに記録された文は、機密データを明らかにし、プレーンテキストのパスワードを含むことさえあります。

log_replication_commands (boolean) #

Causes each replication command to be logged in the server log. See <xref linkend="protocol-replication"/> for more information about replication command. The default value is <literal>off</literal>. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. サーバログにレプリケーションコマンドを記録します。 レプリケーションコマンドの更なる情報は55.4をご覧ください。 デフォルト値はoffです。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。

log_temp_files (integer) #

Controls logging of temporary file names and sizes. Temporary files can be created for sorts, hashes, and temporary query results. If enabled by this setting, a log entry is emitted for each temporary file, with the file size specified in bytes, when it is deleted. A value of zero logs all temporary file information, while positive values log only files whose size is greater than or equal to the specified amount of data. If this value is specified without units, it is taken as kilobytes. The default setting is -1, which disables such logging. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. 一時ファイルのファイル名とサイズのログ出力を制御します。 一時ファイルはソート処理やハッシュ処理、一時的な問い合わせの結果のために作成されます。 この設定が有効になると、指定されたファイルのバイト単位の大きさを伴うログの項目が、すべての一時ファイルそれぞれについて削除されたときに生成されます。 0を指定すると、すべての一時ファイル情報のログが残ります。 正の数を指定すると、指定した以上の容量のファイルのみがログに残ります。 この値が単位なしで指定された場合は、キロバイト単位であるとみなします。 デフォルトの設定は-1で、このログ出力を無効にします。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。 この設定を変更できるのは、スーパーユーザと適切なSET権限を持つユーザだけです。

log_timezone (string) #

Sets the time zone used for timestamps written in the server log. Unlike <xref linkend="guc-timezone"/>, this value is cluster-wide, so that all sessions will report timestamps consistently. The built-in default is <literal>GMT</literal>, but that is typically overridden in <filename>postgresql.conf</filename>; <application>initdb</application> will install a setting there corresponding to its system environment. See <xref linkend="datatype-timezones"/> for more information. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. サーバログに書き出す際に使用される時間帯を設定します。 TimeZoneと異なり、すべてのセッションで一貫性を持ってタイムスタンプが報告されるようにこの値はクラスタ全体に適用されます。 組み込まれているデフォルトはGMTですが、postgresql.confにより通常は上書きされます。initdbによりこれらと関連した設定をシステム環境にインストールされます。 詳細は8.5.3を参照してください。 このパラメータはpostgresql.confファイル内、またはサーバのコマンドラインのみで設定可能です。

20.8.4. CSV書式のログ出力の利用 #

<title>Using CSV-Format Log Output</title>

Including <literal>csvlog</literal> in the <varname>log_destination</varname> list provides a convenient way to import log files into a database table. This option emits log lines in comma-separated-values (<acronym>CSV</acronym>) format, with these columns: time stamp with milliseconds, user name, database name, process ID, client host:port number, session ID, per-session line number, command tag, session start time, virtual transaction ID, regular transaction ID, error severity, SQLSTATE code, error message, error message detail, hint, internal query that led to the error (if any), character count of the error position therein, error context, user query that led to the error (if any and enabled by <varname>log_min_error_statement</varname>), character count of the error position therein, location of the error in the PostgreSQL source code (if <varname>log_error_verbosity</varname> is set to <literal>verbose</literal>), application name, backend type, process ID of parallel group leader, and query id. Here is a sample table definition for storing CSV-format log output: log_destinationリストにcsvlogを含めることは、ログファイルをデータベーステーブルにインポートする簡便な方法を提供します。このオプションはカンマ区切り値書式(CSV)で以下の列を含むログ行を生成します。 ミリ秒単位のtimestamp、 ユーザ名、 データベース名、 プロセスID、 クライアントホスト:ポート番号、 セッションID、 セッション前行番号、 コマンドタグ、 セッション開始時間、 仮想トランザクションID、 通常トランザクションID、 エラーの深刻度、 SQLSTATEコード、 エラーメッセージ、 詳細エラーメッセージ、 ヒント、 エラーとなった内部的な問い合わせ(もしあれば)、 内部問い合わせにおけるエラー位置の文字数、 エラーの文脈、 エラーの原因となったユーザ問い合わせ(存在しlog_min_error_statementで有効になっている場合)、 エラー位置の文字数、 PostgreSQLソースコード上のエラー発生場所(log_error_verbosityverboseに設定されているならば)、 アプリケーション名、バックエンドタイプ、パラレルグループリーダーのプロセスID、問い合わせID。 以下にcsvlog出力を格納するためのテーブル定義のサンプルを示します。

CREATE TABLE postgres_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,
  backend_type text,
  leader_pid integer,
  query_id bigint,
  PRIMARY KEY (session_id, session_line_num)
);

To import a log file into this table, use the <command>COPY FROM</command> command: このテーブルにインポートするためには、COPY FROMコマンドを使用してください。

COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;

It is also possible to access the file as a foreign table, using the supplied <xref linkend="file-fdw"/> module. 提供されたfile_fdwモジュールを使って外部テーブルとしてファイルをアクセスすることも可能です。

There are a few things you need to do to simplify importing CSV log files: CSVログファイルをインポートする作業を単純にするためにいくつか必要な作業があります。

  1. Set <varname>log_filename</varname> and <varname>log_rotation_age</varname> to provide a consistent, predictable naming scheme for your log files. This lets you predict what the file name will be and know when an individual log file is complete and therefore ready to be imported. 一貫性があり、予測可能なログファイル命名機構を提供するために、log_filenameおよびlog_rotation_ageを設定してください。 これによりどのようなファイル名になると、個々のログファイルが完了しインポートする準備が整ったかが推測できるようになります。

  2. Set <varname>log_rotation_size</varname> to 0 to disable size-based log rotation, as it makes the log file name difficult to predict. ログファイル名の予測が困難になりますので、log_rotation_sizeを0にして容量を基にしたログの回転を無効にしてください。

  3. Set <varname>log_truncate_on_rotation</varname> to <literal>on</literal> so that old log data isn't mixed with the new in the same file. 同じファイルに古いログデータと新しいログデータが混在しないようにするために、log_truncate_on_rotationonに設定してください。

  4. The table definition above includes a primary key specification. This is useful to protect against accidentally importing the same information twice. The <command>COPY</command> command commits all of the data it imports at one time, so any error will cause the entire import to fail. If you import a partial log file and later import the file again when it is complete, the primary key violation will cause the import to fail. Wait until the log is complete and closed before importing. This procedure will also protect against accidentally importing a partial line that hasn't been completely written, which would also cause <command>COPY</command> to fail. 上のテーブル定義には主キーの指定が含まれています。 これにより、同じ情報が2回インポートされる事故を防止するために有用です。 COPYコマンドは、一度にインポートするすべてのデータをコミットしますので、何か1つでもエラーがあればインポート全体が失敗します。 ログファイルの一部をインポートし、そのファイルが完了した後に再度インポートしようとした場合、主キー違反によりインポートが失敗します。 インポートする前に、ログファイルの完了を待ち、閉じるまで待機してください。 この手順は、COPYが失敗する原因となる、完全に書き込まれなかった欠落した行をインポートするという事故も防止します。

20.8.5. JSON書式のログ出力 #

<title>Using JSON-Format Log Output</title>

Including <literal>jsonlog</literal> in the <varname>log_destination</varname> list provides a convenient way to import log files into many different programs. This option emits log lines in <acronym>JSON</acronym> format. log_destinationリストにjsonlogを含めると、ログファイルをさまざまなプログラムにインポートするのに便利です。 このオプションは、JSON書式のログ行を出力します。

String fields with null values are excluded from output. Additional fields may be added in the future. User applications that process <literal>jsonlog</literal> output should ignore unknown fields. NULL値を持つ文字列フィールドは出力から除外されます。 将来、フィールドが追加される可能性があります。 jsonlog出力を処理するユーザーアプリケーションは不明なフィールドを無視する必要があります。

Each log line is serialized as a JSON object with the set of keys and their associated values shown in <xref linkend="runtime-config-logging-jsonlog-keys-values"/>. 各ログ行はJSONオブジェクトとしてシリアライズされ、一連のキーとそれに関連する値が表 20.3で示されます。

表20.3 JSONログ項目のキーと値

<title>Keys and Values of JSON Log Entries</title>
キー名説明
timestampstringミリ秒単位のタイムスタンプ
userstringユーザ名
dbnamestringデータベース名
pidnumberプロセスID
remote_hoststringクライアントホスト
remote_portnumberクライアントポート
session_idstringセッションID
line_numnumberセッション単位の行番号
psstring現在のps表示
session_startstringセッション開始時刻
vxidstring仮想トランザクションID
txidstring通常トランザクションID
error_severitystringエラー深刻度
state_codestringSQLSTATEコード
messagestringエラーメッセージ
detailstringエラーメッセージ詳細
hintstringエラーメッセージヒント
internal_querystringこのエラーの原因となった内部問い合わせ
internal_positionnumber内部問い合わせへのカーソルインデックス
contextstringエラーコンテキスト
statementstringクライアント提供の問い合わせ文字列
cursor_positionnumber問い合わせ文字列へのカーソルインデックス
func_namestringエラー位置関数名
file_namestringエラー位置のファイル名
file_line_numnumberエラー位置のファイル行番号
application_namestringクライアントアプリケーション名
backend_typestringバックエンドの種類
leader_pidnumber活動中のパラレルワーカーのリーダーのプロセスID
query_idnumber問い合わせ識別子

20.8.6. プロセスの表題 #

<title>Process Title</title>

These settings control how process titles of server processes are modified. Process titles are typically viewed using programs like <application>ps</application> or, on Windows, <application>Process Explorer</application>. See <xref linkend="monitoring-ps"/> for details. これらの設定項目は、サーバプロセスの表題を変更します。 プロセスの表題は、典型的にはps、あるいはWindowsにおいてはProcess Explorerで見ることができます。 詳細については、28.1を参照してください。

cluster_name (string) #

Sets a name that identifies this database cluster (instance) for various purposes. The cluster name appears in the process title for all server processes in this cluster. Moreover, it is the default application name for a standby connection (see <xref linkend="guc-synchronous-standby-names"/>.) 様々な目的のために、このデータベースクラスタ(インスタンス)を識別する名前を設定します。 クラスタ名はこのクラスタのすべてのサーバプロセスのプロセス表題に表れます。 更に、スタンバイ接続のデフォルトのアプリケーション名となります。 (synchronous_standby_names参照。)

The name can be any string of less than <symbol>NAMEDATALEN</symbol> characters (64 characters in a standard build). Only printable ASCII characters may be used in the <varname>cluster_name</varname> value. Other characters will be replaced with question marks (<literal>?</literal>). No name is shown if this parameter is set to the empty string <literal>''</literal> (which is the default). This parameter can only be set at server start. クラスタ名はNAMEDATALEN文字(標準のビルドでは64文字)より少ない文字列です。 表示可能なASCII文字だけがcluster_nameの値として設定できます。 他の文字は、疑問符(?)に置き換えられます。 空文字''(これがデフォルト値です)が設定されると、クラスタ名は表示されません。 このパラメータはサーバ起動時にのみ設定できます。

update_process_title (boolean) #

Enables updating of the process title every time a new SQL command is received by the server. This setting defaults to <literal>on</literal> on most platforms, but it defaults to <literal>off</literal> on Windows due to that platform's larger overhead for updating the process title. Only superusers and users with the appropriate <literal>SET</literal> privilege can change this setting. サーバが新しいSQLコマンドを受け取る時に毎回、プロセスタイトルを更新できるようにします。 この設定値はたいていのプラットフォームでonがデフォルトになっていますが、Windowsではプロセスタイトルを更新するオーバーヘッドが大きいため、offがデフォルトになっています。 スーパーユーザと、適切なSET権限を持つユーザのみがこの設定を変更することができます。