Run Docker postgres image with custom postgresql.conf

I’m using a postgres container to test my Rails app. But some queries are struggling and checking the RAM usage, the configuration could be optimized to use more RAM resources and more CPUs.

Checking the Docker postgres image docs you can setup a new postgresql.conf file and call it in the docker run. How could I do that in the CircleCI YAML config?

Just a guess, and might be another way to do this within CircleCI (I haven’t personally messed much with volume mounts / files on accessory containers), but maybe it would work to use POSTGRES_INITDB_ARGS, which might be easier than figuring out how to drop in a conf file?

Quickly looking through Circle’s docs on db configuration, I didn’t see another obvious way, though it may be doable some other way

1 Like

Replying to myself… funnily, I find myself running into the same need, and found this thread (and my own response) when searching for it.

I’m trying to set fsync=off etc. in a Circle config (see this article. It doesn’t seem like cimg/postgresql does this by default anymore.

From what I can tell, setting

command: "postgres -c fsync=off -c synchronous_commit=off -c full_page_writes=off"

or

command: "-c fsync=off -c synchronous_commit=off -c full_page_writes=off"

doesn’t seem to be doing anything. (either that or it’s working and just not making an improvement, but reading the output in the run, I’m pretty sure this is still just using the regular entrypoint / startup command).

The README for cimg/postgres seems to suggest overriding a custom config file, but I think because of permissions, the postgres user can’t get into the circleci workspace anyway? Maybe doing a volume mount would work?

I did verify that setting --nosync in POSTGRES_INITDB_ARGS seems to disable disk sync.

1 Like

In our case we added this env var, for a large resource of 8GB:

POSTGRES_INITDB_ARGS: "-c max_connections=20 -c shared_buffers=2GB -c effective_cache_size=6GB -c maintenance_work_mem=512MB -c checkpoint_completion_target=0.9 -c wal_buffers=16MB -c default_statistics_target=100 -c random_page_cost=1.1 -c effective_io_concurrency=200 -c work_mem=5242kB -c huge_pages=off -c min_wal_size=1GB -c max_wal_size=4GB -c max_worker_processes=4 -c max_parallel_workers_per_gather=2 -c max_parallel_workers=4 -c max_parallel_maintenance_workers=2"
1 Like

This is with "cimg/postgres?

For me, using -c xxx in POSTGRES_INITDB_ARGS seems to give errors like

initdb: invalid option -- 'c'