Postgres performance within Docker #219
-
Hi Bret, I am not in devops/engineering and I'm desperately in need of some help with something that may be very trivial to you. We have a large-ish Postgres database (1.5Gb dumped) which we are running in a Docker container which was set up for us by a previous 3rd party provider. But the performance of our queries seem to be more than 3 times slower within the container. I have been testing a specific query on my machine, so same technical specs, exact same database, same query, same result when running an EXPLAIN - just much slower in the container. I've Googled and asked on Stackoverflow and applied PGTune recommendations without much success. I'll attach our docker-compose.yml file and a list of my changes to our postgresql.conf below. Please let me know if there's any other info I can give you. I would SO appreciate a little bit of your time and any advice you could give. docker-compose.yml version: '3.7'
volumes:
postgres:
services:
postgres:
build:
context: ./
dockerfile: ./repo/postgres.docker
shm_size: '2gb'
shm_size: '2gb'
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "w@gw00rD"
PGDATA: "/data/postgres"
volumes:
- postgres:/data/postgres
- ./postgresbackups:/var/postgresbackups
- ./repo/postgres_init.sql:/docker-entrypoint-initdb.d/postgres_init.sql
- ./repo/postgresql.conf:/etc/postgresql/postgresql.conf
ports:
- "15432:5432"
restart: unless-stopped postgresql.conf changes
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hmm, not sure I'm much help in psql tuning. I just follow internet guides for conf changes. On your local machine, the query will be slower because it's running in a VM (Docker Desktop), which is always a bit slower than the host OS, particularly on macOS. You can't really compare performance of running in Docker Desktop vs a server. What you can do, is compare one query to another on the same host after you've optimized db indexes and .conf settings. On the server side, there wouldn't be any change in performance inside a container vs. outside a container because a Linux container is just running on the host OS Kernel with the same CPU/memory, and File I/O specs. DB query speed is often about these concerns:
Notice, on the server, none of those are related to it being a container. If you were running a single postgres db on a Linux VM host OS, and then you moved postgres on that server into a single container, I wouldn't expect performance to change. |
Beta Was this translation helpful? Give feedback.
Hmm, not sure I'm much help in psql tuning. I just follow internet guides for conf changes.
On your local machine, the query will be slower because it's running in a VM (Docker Desktop), which is always a bit slower than the host OS, particularly on macOS.
You can't really compare performance of running in Docker Desktop vs a server. What you can do, is compare one query to another on the same host after you've optimized db indexes and .conf settings.
On the server side, there wouldn't be any change in performance inside a container vs. outside a container because a Linux container is just running on the host OS Kernel with the same CPU/memory, and File I/O specs. DB query speed is often …