情報応用演習Ⅰ(2024)

PostgreSQLのセットアップ(4/7)

p3-4. PostgreSQLのログ関連の設定

エラーメッセージの言語設定

デフォルトではDBサーバ側が表示するエラーメッセージなどが日本語(SJIS)となる. このままだと後述するフレームワークで使用する際にエラーメッセージが文字化けしてエラー内容をチェックすることが 困難になるため,メッセージの内容を英語に変更する1

PostgreSQLの設定ファイルはデフォルトでは C:\Program Files\PostgreSQL\16\data\postgresql.conf にある. これを適当なテキストエディタで開き,lc_messagesの設定値をJapanese_Japan.932からen_USに変更する(_).

postgresql.confの695行目付近

変更前:

1
2
3
4
5
6
7
8
9
#client_encoding = sql_ascii		# actually, defaults to database
					# encoding

# These settings are initialized by initdb, but they can be changed.
lc_messages = 'Japanese_Japan.932'			# locale for system error message
					# strings
lc_monetary = 'Japanese_Japan.932'			# locale for monetary formatting
lc_numeric = 'Japanese_Japan.932'			# locale for number formatting
lc_time = 'Japanese_Japan.932'				# locale for time formatting
変更後:
1
2
3
4
5
6
7
8
9
#client_encoding = sql_ascii		# actually, defaults to database
					# encoding

# These settings are initialized by initdb, but they can be changed.
lc_messages = 'en_US'			# locale for system error message
					# strings
lc_monetary = 'Japanese_Japan.932'			# locale for monetary formatting
lc_numeric = 'Japanese_Japan.932'			# locale for number formatting
lc_time = 'Japanese_Japan.932'				# locale for time formatting
上記の指示では何をしていいかわからない人向けの説明

この授業に限らず,こういった作業はよく必要になるので 上記ていどの粒度の指示でも理解できるようにしておこう . ここでは念のためステップバイステップのスクリーンショットも提示しておく.

表示するにはここをクリック

エクスプローラで以下のフォルダを開く(_).エクスプローラーでC:ドライブからナビゲートするか, エクスプローラーのアドレスバーに以下のパスを打ち込む.

C:\Program Files\PostgreSQL\16\data

このフォルダが今回のインストールにおける,DBのデフォルトの保存フォルダである.

DB保存フォルダ

このフォルダにある postgresql.conf を適当なテキストエディタ(たとえば「メモ帳」など)で開く(_).

postgresql.confを開く

lc_messagesを検索し,設定値をJapanese_Japan.932からen_USに変更し,保存して閉じる(_).

postgresql.confの編集
表示するにはここをクリック : 閉じる
上記の指示では何をしていいかわからない人向けの説明 : 閉じる
ログメッセージにSQL文を含める

PostgreSQLのログメッセージに,受け付けたSQL文を含めるように設定しておくとデバッグの役に立つ場合が多い. ステップC.4と同じく postgresql.conf を適当なテキストエディタで開き,以下2か所を変更する. なお,これらの設定値が書かれている行の先頭に#がある場合は削除すること(≒コメント解除)

  • 450行目付近:log_destinationの設定値をstderrからeventlogに変更する(_).
  • 598行目付近:log_statementの設定値をnoneからallに変更する(_).
postgresql.confの450行目付近

変更前:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#------------------------------------------------------------------------------
# REPORTING AND LOGGING
#------------------------------------------------------------------------------

# - Where to Log -

log_destination = 'stderr'		# Valid values are combinations of
					# stderr, csvlog, syslog, and eventlog,
					# depending on platform.  csvlog
					# requires logging_collector to be on.
変更後:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#------------------------------------------------------------------------------
# REPORTING AND LOGGING
#------------------------------------------------------------------------------

# - Where to Log -

log_destination = 'eventlog'		# Valid values are combinations of
					# stderr, csvlog, syslog, and eventlog,
					# depending on platform.  csvlog
					# requires logging_collector to be on.
postgresql.confの598行目付近

変更前:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
					# -1 means print in full, 0 disables
#log_parameter_max_length_on_error = 0	# when logging an error, limit logged
					# bind-parameter values to N bytes;
					# -1 means print in full, 0 disables
#log_statement = 'none'			# none, ddl, mod, all
#log_replication_commands = off
#log_temp_files = -1			# log temporary files equal or larger
					# than the specified size in kilobytes;
					# -1 disables, 0 logs all temp files
log_timezone = 'Asia/Tokyo'
変更後:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
					# -1 means print in full, 0 disables
#log_parameter_max_length_on_error = 0	# when logging an error, limit logged
					# bind-parameter values to N bytes;
					# -1 means print in full, 0 disables
log_statement = 'all'			# none, ddl, mod, all
#log_replication_commands = off
#log_temp_files = -1			# log temporary files equal or larger
					# than the specified size in kilobytes;
					# -1 disables, 0 logs all temp files
log_timezone = 'Asia/Tokyo'

  1. ちなみにWindows版では日本語(UTF-8)のロケールを指定することは不可能である. ↩︎

Last updated on 2024-03-25
Published on 2024-03-25

Powered by Hugo. Theme by TechDoc. Designed by Thingsym.