Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log all queries in the official Postgres docker image

I have a docker container based on Postgres's official docker image. I want to see the incoming queries when I look at the logs of the docker container using docker logs -f. This is my Dockerfile:

FROM postgres:11.1-alpine  COPY mock_data.sql /docker-entrypoint-initdb.d/mock_data.sql  ENV PGDATA=/data 

and this is the part of my docker-compose.yml file related to this service:

version: '3' services:   mock_data:     image: mock_data     container_name: mock_data     ports:          - 5434:5432/tcp 

What is the eaasiest way to include the incoming queries in docker logs?

like image 229
svakili Avatar asked Jul 12 '19 23:07

svakili


People also ask

How do I get full docker logs?

First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.

How do I monitor logs from a docker container?

Viewing Container Logs You can use docker ps -a to get the IDs and names of your containers. The logs command prints the container's entire log output to your terminal. The output will not be continuous. If you'd like to keep streaming new logs, add the --follow flag to the command.


1 Answers

If using Docker Compose, you can add this line to your docker-compose.yaml file:

command: ["postgres", "-c", "log_statement=all"] 

and all your queries will be written into the container log file.

like image 83
sprat Avatar answered Sep 23 '22 14:09

sprat