Skip to content

Commit 3513992

Browse files
committed
Demonstrate how to enable postgres query logs for debugging
1 parent 4fad65b commit 3513992

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

toolset/databases/postgres/postgresql.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ synchronous_commit = off
291291

292292
# - Where to Log -
293293

294-
#log_destination = 'stderr' # Valid values are combinations of
294+
log_destination = 'stderr' # Valid values are combinations of
295295
# stderr, csvlog, syslog, and eventlog,
296296
# depending on platform. csvlog
297297
# requires logging_collector to be on.
@@ -392,7 +392,7 @@ synchronous_commit = off
392392
#log_duration = off
393393
#log_error_verbosity = default # terse, default, or verbose messages
394394
#log_hostname = off
395-
log_line_prefix = '%t ' # special values:
395+
log_line_prefix = '%t %c %v %x ' # special values:
396396
# %a = application name
397397
# %u = user name
398398
# %d = database name
@@ -413,7 +413,7 @@ log_line_prefix = '%t ' # special values:
413413
# %% = '%'
414414
# e.g. '<%u%%%d> '
415415
#log_lock_waits = off # log lock waits >= deadlock_timeout
416-
#log_statement = 'none' # none, ddl, mod, all
416+
log_statement = 'all' # none, ddl, mod, all
417417
#log_temp_files = -1 # log temporary files equal or larger
418418
# than the specified size in kilobytes;
419419
# -1 disables, 0 logs all temp files

toolset/utils/docker_helper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ def start_database(self, database):
281281
Sets up a container for the given database and port, and starts said docker
282282
container.
283283
'''
284+
285+
def watch_container(docker_container):
286+
for line in docker_container.logs(stream=True):
287+
print(line)
288+
284289
image_name = "techempower/%s:latest" % database
285290
log_prefix = image_name + ": "
286291

@@ -302,6 +307,12 @@ def start_database(self, database):
302307
remove=True,
303308
log_config={'type': None})
304309

310+
watch_thread = Thread(
311+
target=watch_container,
312+
args=[container])
313+
watch_thread.daemon = True
314+
watch_thread.start()
315+
305316
# Sleep until the database accepts connections
306317
slept = 0
307318
max_sleep = 60

0 commit comments

Comments
 (0)