F
F
furyon2018-05-29 19:37:55
PostgreSQL
furyon, 2018-05-29 19:37:55

How to set up Postgres in Docker?

Hey!
I have a web application. The PosgreSQL database is used, a separate VPS is allocated for it, there is now an SSD, 1 Intel Xeon E5-2620 core and 2GB of RAM. I deploy Postgres via docker compose like this:

version: '2'

services:
  postgres:
    image: postgres:10
    ports:
      - 5432:5432
    volumes:
      - postgres:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: example
    command: postgres -c shared_buffers=512MB -c effective_cache_size=1536MB -c work_mem=2621kB -c maintenance_work_mem=128MB
    shm_size: '1gb'

volumes:
  postgres:

The mythical highload has arrived. The database starts to slow down on a large number of requests. I will figure out the index and query structures myself, but I would like to ask you about setting up the database:
1. Is there a specific use of Postgres in docker? For example, recently I began to receive errors like https://meta.discourse.org/t/pg-throws-could-not-r... , it turned out that the problem was in the docker, or rather in the details of the OS settings, which for me, a simple pimp - Dark forest.
2. Have I passed the settings correctly, maybe something is missing.
3. Maybe it makes sense to just install the base without any dockers (I use docker for ease of development, porting, etc.).
4. Will there be an effect if physical cores are added? Do I need to configure docker separately for this?
Approximately 95% of queries to the database are selects. Now the processor is 100% loaded at peaks, while the memory is only 150mb, which surprises me. The database currently weighs ~ 2GB.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2018-05-29
@melkij

Why do you need it? Tell me why? So far, none of the docker adepts I have met have coped with such a simple question "why do you need a base in the docker?", maybe you can handle it.
To use the base you must provide a normal file system, you must provide the host network. Insulation? So you have a system entirely under the base and so on. Migrating to another host? Yes, you only have base binaries in this docker. Exactly the same as in the repositories, the base itself is outside in a normal FS. In principle, you will not drag datadir to another architecture. Several clusters of bases on one machine? And why docker for this? There are some awesome pg_ctlcluster scripts on ubuntu/debian. About the perversions with pg_upgrade updating the database, I will not reprint the answer from ruSO.
In the opinion of postgresql dba, you did not pass any settings at all, and work_mem was completely reduced, it has a default of 4mb. Accordingly, the database will work by default, i.e. from the calculation to start on any calculator, and not to work clearly. Not enough, respectively, everything. More aggressive checkpointer, bgwriter and autovacuum settings first.
See pg_stat_statements for queries

O
OnYourLips, 2018-05-29
@OnYourLips

1. Is there a specific use of Postgres in docker?
There is. Typically, DBMSs are deployed in clusters on bare metal, and docker and orchestration tools are used for applications.
stateless containers are our everything.
3. Yes.
Just do not forget that DBMSs are usually bound to the localhost, and other interfaces will need to be listened to. And don't forget the firewall.
Bases in docker are convenient to use for development, but not in production.
Upd: if you want to use docker efficiently, forget about -v/--volume/volumeseverything related to them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question