1

I'm running a Postgres inside a docker. I want to change the default config of Postgres so I'm running :

docker container run -d postgres -c max_connections=200 -c shared_buffers = 1GB -c effective_cache_size=3GB -c maintenance_work_mem=256MB -c checkpoint_completion_target=0.7 -c wal_buffers=16MB 

But when I'm connecting to Postgres running:

 docker exec -it container_name psql

And then the result of :

SHOW max_connections;

is

 max_connections
-----------------
 100
(1 row)

And it's not just max_connections. None of the parameters are changed. And I don't know what is the problem with what I'm doing?

Update: I already have a running docker container and I want it to apply these parameters to it without needing to restart it.

2 Answers 2

0

You cannot put spaces around the equals sign when using the "-c" option. So you need something like postgres -c max_connections=200

When I try it with the spaces, it refused to start at all. So I don't know what you are connecting to in order to SHOW max_connections;. Maybe you already had a server running before you tried to start with the invalid syntax?

4
  • You are right. I already have a running server. But using the command without space did not work. Commented Nov 30, 2018 at 19:27
  • And with both spaced and not-spaced commands I get something like 35d1c90ef07bb73f4ad30951951498f574e125ba872404015d26006f3d013284 as result which I don't know what it means Commented Nov 30, 2018 at 19:31
  • I suspect that that hash value is being delivered by docker, not by postgres. You might need docker-specific help, rather than dba help, with that. If you already have a server running, you won't be able to start another one in the same container on the same port. What if you remove all the options and just try to start a default instance now? Commented Nov 30, 2018 at 20:02
  • You mean like docker-compose up -d? I get WARNING: Found orphan containers (mahan_postgres) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up. Commented Nov 30, 2018 at 20:11
0

When running Postgresql with Docker, there are many ways to change configuration when starting a container.

It is explained in the Docker image official documentation at this paragraph : Database Configuration.

In our case, there is an example :

$ docker run -d --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword postgres -c shared_buffers=256MB -c max_connections=200

So let's try this with Postgres 14 :

$ docker run -d --name pg14 -e POSTGRES_PASSWORD=mysecretpassword postgres:14 -c shared_buffers=256MB -c max_connections=200

Check it with psql :

$ docker exec -it pg14 psql -U postgres

If we execute SHOW max_connections;, 200 is displayed, so it worked 👍.

⚠️ Setting this parameter on the command line will indeed override the configuration in postgresql.conf.

We can check the configuration file used by the container with :

$ docker exec pg14 cat /var/lib/postgresql/data/postgresql.conf

It contains :

max_connections = 100                   # (change requires restart)

Even if the max_connections parameter has been successfully changed on the command line, in the logs we still see the default value (from the config file I guess) :

$ docker logs pg14  | grep max_connections
...
selecting default max_connections ... 100
...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.