I am having hard time in configuring the postgres logging level in Docker. From logging level, what I mean is that say my query is something like - SELECT COUNT(*) FROM tablethatnotexist
then in output returned by the database driver will tell me that in a way - relation "tablethatnotexist" does not exist
.
It's fine until here but getting the same log in the database sometime is just irritating. I mean that I know I queried the databse with that relation which doesn't exist and I also got a response for that. So getting a log like -
doesn't makes any sense and also it just adds up extra logs in the file.
I have searched all around but I just can't found the way to disable the extra logging or just set it to log on the critical errors only since the database driver handles the most errors.
My dev environment -
- Using docker compose.
Docker compose Postgres
service section -
postgres:
build: ./postgresql
container_name: postgres
ports:
- '127.0.0.1:5432:5432'
volumes:
- pg-data:/var/lib/postgresql/data
postgresql
directory has two files, Dockerfile
and init.sql
. Dockerfile
code -
FROM postgres:14-alpine
ENV POSTGRES_USER: ...
ENV POSTGRES_PASSWORD: ...
ENV POSTGRES_DB: ...
COPY *.sql /docker-entrypoint-initdb.d/
Please help on how to customize postgres
to only log the critical logs.
CodePudding user response:
If using Docker Compose, you can add this line to your docker-compose.yaml file:
command: ["postgres", "-c", "log_statement=none"]
and all your queries will be written into the container log file.
In the official docs you can find details