$ sudo vim /etc/postgresql/14/main/postgresql.conf
데이터베이스 서버를 관리하다 하다 보면 클라이언트에서 요청한 쿼리(Query)를 확인해야 하는 경우가 종종 있습니다. 그래서 요청받은 쿼리를 파일에 저장하는 방법을 알아보겠습니다.
PostgreSQL의 설정 파일을 에디터로 열어서,
"log_directory",
"log_filename",
"log_statement",
"logging_collector",
"log_destination"
항목의 주석을 제거하거나 값을 변경해 줘야 합니다.
$ sudo vim /etc/postgresql/14/main/postgresql.conf
#------------------------------------------------------------------------------
# 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 = on # Enable capturing of stderr and csvlog
# into log files. Required to be on for
# csvlogs.
# (change requires restart)
# These are only used if logging_collector is on:
log_directory = 'pg_log' # directory where log files are written,
# can be absolute or relative to PGDATA
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
# can include strftime() escapes
...
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
설정 파일을 변경했으면 다시 재시작해야겠지요?
$ sudo systemctl restart postgresql
로그 폴더 (pg_log) 확인하기
$ sudo ls /var/lib/postgresql/14/main
base global pg_dynshmem pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase pg_wal postgresql.auto.conf postmaster.pid
current_logfiles pg_commit_ts pg_log pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc PG_VERSION pg_xact postmaster.opts
'BACKEND > PostgreSQL' 카테고리의 다른 글
Ubuntu PostgreSQL 백업(backup) 및 복구(restore) (0) | 2023.03.12 |
---|---|
Linux(Ubuntu) pgAdmin4 설치 (0) | 2023.03.11 |
pgRouting 설치 (0) | 2023.01.31 |
PostGIS 설치 (0) | 2023.01.31 |
PostgreSQL 설치 (0) | 2022.07.14 |