Databases 7 min read

How to Locate and Edit PostgreSQL’s postgresql.conf in Docker and Native Installations

This guide explains where PostgreSQL’s main configuration file lives in both Docker Compose and native installations, how to edit it with Vim, modify common parameters like max_connections, reload the settings without downtime, and avoid common pitfalls.

IT Xianyu
IT Xianyu
IT Xianyu
How to Locate and Edit PostgreSQL’s postgresql.conf in Docker and Native Installations

One, Where is the configuration file?

PostgreSQL’s main configuration file is postgresql.conf. Its location depends on how you installed PostgreSQL.

If you deployed with Docker Compose (recommended), the file resides inside the container but is mapped to the host via a volume. Check your docker-compose.yml for a volume like:

volumes:
  - /data/postgresql:/var/lib/postgresql/data  # key line

The host path is /data/postgresql/postgresql.conf and the container path is /var/lib/postgresql/data/postgresql.conf. You can also use docker exec to inspect the container.

If you installed natively (rpm/yum), the file is usually under /var/lib/pgsql/[version]/data/postgresql.conf, e.g., /var/lib/pgsql/15/data/postgresql.conf on AlmaLinux.

To confirm the exact path, connect to the database with DataGrip or psql and run:

SHOW config_file;
SHOW config_file result
SHOW config_file result

Two, Vim basics (3‑minute crash course)

Key Vim commands for editing the file:

Operation

Key

Description

Open file vim filename e.g., vim /data/postgresql/postgresql.conf Enter edit mode i Shows -- INSERT -- at the bottom

Exit edit mode ESC Returns to command mode

Save and quit :wq Write changes and exit

Quit without saving :q! Force quit

Search /keyword Find a term, e.g., /max_connections Go to line start 0 Jump cursor to column 0

Show line numbers :set nu Display line numbers for easier navigation

Vim interface with line numbers
Vim interface with line numbers

Three, Practical example: change max_connections

Goal: increase max_connections from the default 100 to 200.

Step 1: Find the setting – Open the file with Vim and search /max_connections. You’ll see a line like:

#max_connections = 100         # default is commented out

Step 2: Edit – Press i to enter insert mode, delete the leading #, change 100 to 200, then press ESC.

Step 3: Save – Type :wq and hit Enter.

Before and after editing max_connections
Before and after editing max_connections

Four, Apply the new configuration (two methods)

Method 1: SQL command (recommended, no downtime) – In DataGrip run:

SELECT pg_reload_conf();
SELECT pg_reload_conf() result
SELECT pg_reload_conf() result

Method 2: Command‑line reload (service interruption) – Inside the container or on the host run one of the following:

# Docker container
pg_ctl reload -D $PGDATA

# Native AlmaLinux installation
sudo systemctl reload postgresql-15   # replace 15 with your version

Five, Verify the change

Run: SHOW max_connections; It should return 200.

SHOW max_connections result
SHOW max_connections result

Six, Pitfall checklist

Backup the file first, e.g., cp postgresql.conf postgresql.conf.bak.

Make sure you remove the comment character # to activate a setting.

Parameter names may differ across PostgreSQL versions (e.g., shared_buffers changes before 9.4).

Docker image versions may have different defaults; always verify with SHOW parameter_name;.

If changes don’t take effect, confirm the file was saved, pg_reload_conf() was executed, and the parameter name is spelled correctly (case‑sensitive).

If Vim freezes, press ESC then :q! to force quit and reopen.

Environment

OS: AlmaLinux 8.8

PostgreSQL: 9.6 (Docker Compose deployment)

Tools: DataGrip 2023.3, Vim 8.0

Vim
IT Xianyu
Written by

IT Xianyu

We share common IT technologies (Java, Web, SQL, etc.) and practical applications of emerging software development techniques. New articles are posted daily. Follow IT Xianyu to stay ahead in tech. The IT Xianyu series is being regularly updated.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.