デバッグ出力

The postmaster occasionally prints out messages which are often helpful during troubleshooting. If you wish to view debugging messages from the postmaster, you can start it with the -d option and redirect the output to the log file:

トラブルシューティングの際postmasterは, ときには便利なメッセージをその機会に応じて出力してくれます.もし, postmasterのデバッグ出力を見てみたいと 思ったら,postmasterを-dオプションつきで起動して,その出力をログ ファイルにリダイレクトします:

% postmaster -d >& pm.log &
    
If you do not wish to see these messages, you can type これらのメッセージを見る必要がなければ:
% postmaster -S
    
Notice that there is no ampersand ("&") at the end of the last example so postmaster will be running in the foreground. and the postmaster will be "S"ilent. とすることもできます. 最後の例では末尾にアンパサンド("&")がないので postmasterはフォアグラウンドで動作する ことと,-Sオプションつきで起動すると, postmasterが何もメッセージを出力せず, 黙々と("S"ilent)仕事をするようになるのを見ておいてください.

pg_options

Note: このセクションはMassimo Dal Zottoの手によるもので す.

The optional file data/pg_options contains runtime options used by the backend to control trace messages and other backend tunable parameters. What makes this file interesting is the fact that it is re-read by a backend when it receives a SIGHUP signal, making thus possible to change run-time options on the fly without needing to restart Postgres. The options specified in this file may be debugging flags used by the trace package (backend/utils/misc/trace.c) or numeric parameters which can be used by the backend to control its behaviour. New options and parameters must be defined in backend/utils/misc/trace.c and backend/include/utils/trace.h.

オプションファイル,data/pg_optionsには, トレース情報や,その他諸々のチューニングパラメータを制御する目的で バックエンドに渡す,実行時オプションを記述します.このファイルの いいところは,バックエンドがSIGHUPシグナルを受けた時にこのファイルを 再度読みこむので,Postgresを立ち上げ 直さなくても,その場でさっと実行時のオプションを変更できることです. ファイルで指定できるオプションは,トレーシングパッケージ (backend/utils/misc/trace.c)で使うデバッグ用 フラグ,あるいはバックエンドの動作をコントロールするのに使える数値 パラメータなどです. この新しいオプションとパラメータは, backend/utils/misc/trace.cと, backend/include/utils/trace.hに定義されています.

pg_options can also be specified with the -T switch of Postgres:

またこのオプションはPostgresの-Tオプションで 指定することもできます:

postgres options -T "verbose=2,query,hostlookup-"
    

The functions used for printing errors and debug messages can now make use of the syslog(2) facility. Message printed to stdout or stderr are prefixed by a timestamp containing also the backend pid:

エラーとデバッグメッセージを出力する関数も syslog(2)を利用できるようになりました. 標準出力,あるいは標準エラー出力に表示されるメッセージには, タイムスタンプとバックエンドのプロセスIDが行頭に付加されます:

#timestamp          #pid    #message
980127.17:52:14.173 [29271] StartTransactionCommand
980127.17:52:14.174 [29271] ProcessUtility: drop table t;
980127.17:52:14.186 [29271] SIIncNumEntries: table is 70% full
980127.17:52:14.186 [29286] Async_NotifyHandler
980127.17:52:14.186 [29286] Waking up sleeping backend process
980127.19:52:14.292 [29286] Async_NotifyFrontEnd
980127.19:52:14.413 [29286] Async_NotifyFrontEnd done
980127.19:52:14.466 [29286] Async_NotifyHandler done
    

This format improves readability of the logs and allows people to understand exactly which backend is doing what and at which time. It also makes easier to write simple awk or perl scripts which monitor the log to detect database errors or problem, or to compute transaction time statistics.

このフォーマットはログをずっと読みやすく,そしてバックエンドがいつ, 何をしているのかを正確に理解できるようにしてくれます.さらにawkや perlで,ログを追っかけるちょっとしたスクリプトを書いて,データベースの エラーや障害を検出する,トランザクションタイムの統計を計算する,と いったこともやりやすくなります.

Messages printed to syslog use the log facility LOG_LOCAL0. The use of syslog can be controlled with the syslog pg_option. Unfortunately many functions call directly printf() to print their messages to stdout or stderr and this output can't be redirected to syslog or have timestamps in it. It would be advisable that all calls to printf would be replaced with the PRINTF macro and output to stderr be changed to use EPRINTF instead so that we can control all output in a uniform way.

syslogへのメッセージ出力には,LOG_LOCAL0ファシリティを使います. syslogを使うかどうかは,pg_optionのsyslogオプションで指定すれば コントロールできます. ただ残念なことに,多くの関数は標準出力や標準エラー出力への表示に 直接printf()を呼び出すので,こういう出力は syslogにリダイレクトしたり,タイムスタンプをつけてあげることができま せん.できればprintfの呼び出しを全部PRINTFマクロに置き換え, 標準エラー出力への出力はEPRINTFマクロを代わりに使うよう変更すれば すっきりするのですが.そうすればどの出力も一律にコントロールできる ようになりますからね.

The format of the pg_options file is as follows:

pg_optionsファイルのフォーマットは以下の通りです.

# comment
option=integer_value  # set
value for option
option                # set option = 1
option+               # set option = 1
option-               # set option = 0
     
# コメント
option=整数値
                                        # optionを[整数値]に設定
option       # option = 1 に設定
option+      # option = 1 に設定
option-      # option = 0 に設定
     
Note that keyword can also be an abbreviation of the option name defined in backend/utils/misc/trace.c. キーワードbackend/utils/misc/trace.cで定義されている オプション名の短縮形でもかまいません.

Refer to pg_options の使用 for a complete list of option keywords and possible values.

すべてのオプションと,オプションが取りうる値のリストは, pg_options の使用を参照 してください.