質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

Q&A

解決済

1回答

12751閲覧

postgresql.conf のログ出力設定について

mi-c3

総合スコア20

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

0グッド

0クリップ

投稿2017/11/14 05:29

postgresql.confのログ出力設定についての質問です。

postgresql.conf にエラーの出力方式を記載できますが、
関連する箇所(log_destinationなど)が全てコメントアウトされていた場合、
ログは出力されるのでしょうか?

デフォルトでは'stderr'が設定されていると記載がありますが、
postgresql.confにもともと'stderr'が書かれているという意味にも捉えられますし(まあないと思いますが)、
実際にはどうなのかわかりません。
https://www.postgresql.jp/document/8.4/html/runtime-config-logging.html

具体的なコードは以下のような感じです。

#------------------------------------------------------------------------------ # ERROR 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. # This is used when logging to stderr: #logging_collector = off # Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # (change requires restart) ~省略~ #log_timezone = unknown # actually, defaults to TZ environment # setting #------------------------------------------------------------------------------ # RUNTIME STATISTICS #------------------------------------------------------------------------------

ご存知の方いらっしゃれば教えてください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

以下のような、logから始まる行を#でコメントアウトしたコンフィグを用意して、試してみました。

[root@localhost ~]# cat /var/lib/pgsql/data/postgresql.conf | grep log # "postgres -c log_connections=on". Some parameters can be changed at run time #wal_level = minimal # minimal, replica, or logical #wal_log_hints = off # also do full page writes of non-critical updates #archive_command = '' # command to use to archive a logfile segment #archive_timeout = 0 # force a logfile segment switch after this #wal_keep_segments = 0 # in logfile segments, 16MB each; 0 disables # log_destination = 'stderr' # Valid values are combinations of # stderr, csvlog, syslog, and eventlog, # depending on platform. csvlog # requires logging_collector to be on. # This is used when logging to stderr: #log_ging_collector = on # Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # These are only used if logging_collector is on: #log_directory = 'pg_log' # directory where log files are written, #log_filename = 'postgresql-%a.log' # log file name pattern, #log_file_mode = 0600 # creation mode for log files, #log_truncate_on_rotation = on # If on, an existing log file with the # same name as the new log file will be #log_rotation_age = 1d # Automatic rotation of logfiles will #log_rotation_size = 0 # Automatic rotation of logfiles will # happen after that much log output. # These are relevant when logging to syslog: #syslog_facility = 'LOCAL0' #syslog_ident = 'postgres' #syslog_sequence_numbers = on #syslog_split_messages = on # This is only relevant when logging to eventlog (win32): # log #log_min_messages = warning # values in order of decreasing detail: # log #log_min_error_statement = error # values in order of decreasing detail: # log #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements # and their durations, > 0 logs only #log_checkpoints = off #log_connections = off #log_disconnections = off #log_duration = off #log_error_verbosity = default # terse, default, or verbose messages #log_hostname = off #log_line_prefix = '< %m > ' # special values: #log_lock_waits = off # log lock waits >= deadlock_timeout #log_statement = 'none' # none, ddl, mod, all #log_replication_commands = off #log_temp_files = -1 # log temporary files equal or larger # -1 disables, 0 logs all temp files #log_timezone = 'Japan' #log_parser_stats = off #log_planner_stats = off #log_executor_stats = off #log_statement_stats = off #log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and # their durations, > 0 logs only default_text_search_config = 'pg_catalog.english'

サービスをreloadして、showコマンドで見てみると、以下の内容で起動します。

[root@localhost ~]# /usr/pgsql-9.6/bin/psql -h localhost -d SAG3 -U sa -c 'SHOW ALL' | grep log application_name | psql | Sets the application name to be reported in statistics and logs. archive_timeout | 0 | Forces a switch to the next xlog file if a new file has not been started within N seconds. default_text_search_config | pg_catalog.english | Sets default text search configuration. event_source | PostgreSQL | Sets the application name used to identify PostgreSQL messages in the event log. log_autovacuum_min_duration | -1 | Sets the minimum execution time above which autovacuum actions will be logged. log_checkpoints | off | Logs each checkpoint. log_connections | off | Logs each successful connection. log_destination | stderr | Sets the destination for server log output. log_directory | pg_log | Sets the destination directory for log files. log_disconnections | off | Logs end of a session, including duration. log_duration | off | Logs the duration of each completed SQL statement. log_error_verbosity | default | Sets the verbosity of logged messages. log_executor_stats | off | Writes executor performance statistics to the server log. log_file_mode | 0600 | Sets the file permissions for log files. log_filename | postgresql-%Y-%m-%d_%H%M%S.log | Sets the file name pattern for log files. log_hostname | off | Logs the host name in the connection logs. log_line_prefix | | Controls information prefixed to each log line. log_lock_waits | off | Logs long lock waits. log_min_duration_statement | -1 | Sets the minimum execution time above which statements will be logged. log_min_error_statement | error | Causes all statements generating error at or above this level to be logged. log_min_messages | warning | Sets the message levels that are logged. log_parser_stats | off | Writes parser performance statistics to the server log. log_planner_stats | off | Writes planner performance statistics to the server log. log_replication_commands | off | Logs each replication command. log_rotation_age | 1d | Automatic log file rotation will occur after N minutes. log_rotation_size | 10MB | Automatic log file rotation will occur after N kilobytes. log_statement | none | Sets the type of statements logged. log_statement_stats | off | Writes cumulative performance statistics to the server log. log_temp_files | -1 | Log the use of temporary files larger than this number of kilobytes. log_timezone | GMT | Sets the time zone to use in log messages. log_truncate_on_rotation | off | Truncate existing log files of same name during log rotation. logging_collector | on | Start a subprocess to capture stderr output and/or csvlogs into log files. syslog_facility | local0 | Sets the syslog "facility" to be used when syslog enabled. syslog_ident | postgres | Sets the program name used to identify PostgreSQL messages in syslog. syslog_sequence_numbers | on | Add sequence number to syslog messages to avoid duplicate suppression. syslog_split_messages | on | Split messages sent to syslog by lines and to fit into 1024 bytes. trace_recovery_messages | log | Enables logging of recovery-related debugging information. wal_block_size | 8192 | Shows the block size in the write ahead log. wal_log_hints | off | Writes full pages to WAL when first modified after a checkpoint, even for a non-critical modifications. wal_segment_size | 16MB | Shows the number of pages per write ahead log segment.

この状態で、もう1回サービスをreloadすると、
pg_logディレクトリの下に、以下のようなファイルが出来ます。

[root@localhost ~]# ll /var/lib/pgsql/data/pg_log/ 合計 12 -rw------- 1 postgres postgres 1140 11月 15 14:04 2017 postgresql-2017-11-15_045852.log -rw------- 1 postgres postgres 4130 11月 15 13:58 2017 postgresql-Wed.log [root@localhost ~]#

yumでインストールして配置されるpostgresql.confのログ出力内容とは、異なる内容で出てきますね。

postgresql-Wed.logの内容は、yumでインストールしたpostgresql.confの内容で動かすと作成されるログファイルです。

logの内容をすべてコメントアウトした場合は、postgresql-2017-11-15_045852.logという名前でログファイルができました。

というわけで、logに関する内容をすべてコメントアウトしても、ログは出ます。

投稿2017/11/15 05:12

編集2017/11/15 05:14
todanano

総合スコア13

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mi-c3

2017/11/20 09:42

試していただきありがとうございます! そのような挙動になるのですね。 非常に助かりました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問