pg_options の使用

Note: Contributed by Massimo Dal Zotto

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. The file 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.

data/pg_options というオプションファイルには、 バックエンドがトレースメッセージを制御するための実行時用オプション やその他のバックエンドのチューニング用パラメータを記述します。バッ クエンドは SIGHUP シグナルを受け取ると、このファイルを再読み込みし ます。これにより、Postgres を再起動する ことなく、実行した状態のまま実行時用オプションを変更することができ ます。このファイルでは、トレース用パッケージ( backend/utils/misc/trace.c )で使用されるデバ ッグ用フラグやバックエンドの動作を制御するための数値パラメータとい ったオプションを指定できます。

All pg_options are initialized to zero at backend startup. New or modified options will be read by all new backends when they are started. To make effective any changes for all running backends we need to send a SIGHUP to the postmaster. The signal will be automatically sent to all the backends. We can also activate the changes only for a specific backend by sending the SIGHUP directly to it.

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

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

バックエンドが起動する時、全ての pg_options は 0 に初期化されて います。新しいもしくは変更されたオプションは新しくバックエンドが 起動した時に読み込まれます。実行中のバックエンドでオプションの変 更を有効にするには、postmaster に対して SIGHUP シグナルを送信する 必要があります。そのシグナルは自動的に全てのバックエンドに対して 送信されます。特定のバックエンドに対してのみに SIGHUP を直接送信 することにより、そのバックエンドに対してのみ変更を有効にすること もできます。

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) 機能を使用するように設定できるよ うになりました。標準出力や標準エラーに表示されるメッセージに時刻 とバックエンドのプロセス番号を前につけた、以下のように形式で出力 されます。

#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 を使用するかどうかは syslog pg_option で設定でき ます。残念ながら、多くの関数は 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
# コメント
オプション=整数値  # オプション に値を設定します。
オプション    # オプション を 1 に設定します。
オプション+   # オプション を 1 に設定します。
オプション-   # オプション を 0 に設定します。
    
Note that keyword can also be an abbreviation of the option name defined in backend/utils/misc/trace.c. keyword は、 backend/utils/misc/trace.cで定義されたオプ ション名の省略形にもなることに注意して下さい。

Example 7-1. pg_options ファイル

For example my pg_options file contains the following values:

例として、私が使用している pg_options を以下に示します。

verbose=2
query
hostlookup
showportnumber
      

認知可能なオプション

The options currently defined are:

現在、以下のオプションが定義されています。

all

Global trace flag. Allowed values are:

大域的なトレースフラグ。以下の値を設定できます。

0

Trace messages enabled individually

個別にトレースメッセージを出力可能にします。

1

Enable all trace messages

全てのトレースメッセージを出力可能にします。

-1

Disable all trace messages

全てのトレースメッセージの出力を無効にします。

verbose

Verbosity flag. Allowed values are:

冗長性フラグ。以下の値を設定できます。

0

No messages. This is the default.

メッセージを出力しません。デフォルトの設定です。

1

Print information messages.

情報メッセージを出力します。

2

Print more information messages.

より多くの情報メッセージを出力します。

query

Query trace flag. Allowed values are:

問い合わせトレースフラグ。以下の値を設定できます。

0

Don't print query.

問い合わせを表示しません。

1

Print a condensed query in one line.

問い合わせを 1 行に要約して表示します。

4

Print the full query.

問い合わせ全体を表示します。

plan

Print query plan.

問い合わせ計画を表示します。

parse

Print parser output.

パーサの出力を表示します。

rewritten

Print rewritten query.

書き換えられた問い合わせを表示します。

parserstats

Print parser statistics.

パーサの統計情報を表示します。

plannerstats

Print planner statistics.

プランナの統計情報を表示します。

executorstats

Print executor statistics.

エグゼキュータの統計情報を表示します。

shortlocks

Currently unused but needed to enable features in the future.

今のところ使用していませんが、予定している機能を実現するために 必要となります。

locks

Trace locks.

ロックについてトレースします。

userlocks

Trace user locks.

ユーザロックについてトレースします。

spinlocks

Trace spin locks.

スピンロックについてトレースします。

notify

Trace notify functions.

通知関数についてトレースします。 ※src/backend/commands/async.cで使われています。非同期な コマンドをバックエンドに(が)通知する(された)時の関数 のトレース情報を出力しているようです。

malloc

Currently unused.

今のところ使用していません。

palloc

Currently unused.

今のところ使用していません。

lock_debug_oidmin

Minimum relation oid traced by locks.

ロックについてのトレースを行なうリレーションの最小 oid を 指定します。 ※ storage/lmgr/lock.cによると、 lockDebugOidMin is is used to avoid tracing postgres relations, which would produce a lot of output. postgresシステム用のリレーションについてのトレースを行 なわないようにするための値のようです。

lock_debug_relid

oid, if not zero, of relation traced by locks.

非 0 の場合、ロックについてのトレース対象となるリレーショ ンの oid を指定します。

lock_read_priority

Currently unused.

今のところ使用していません。

deadlock_timeout

Deadlock check timer.

デッドロックを検出するためのタイマー。

syslog

syslog flag. Allowed values are:

syslog フラグ。以下の値を設定できます。

0

Messages to stdout/stderr.

メッセージを標準出力/標準エラーに出力します。

1

Messages to stdout/stderr and syslog.

メッセージを標準出力/標準エラーと syslog の両方に出力 します。

2

Messages only to syslog.

メッセージを syslog にのみ出力します。

hostlookup

Enable hostname lookup in ps_status.

ps_status においてホスト名の検索を有効にします。 ※ps_status は include/utils/ps_status.h で定義された一連 のマクロのようです。ps コマンドのステータスに現れる文字列

showportnumber

を操作しているようです。 Show port number in ps_status.

ps_status においてポート番号を表示します。

notifyunlock

Unlock of pg_listener after notify.

通知後に pg_listener のロックを解除します。

notifyhack

Remove duplicate tuples from pg_listener.

pg_listener から重複したタプルを削除します。