Skip to content

Commit 1df6416

Browse files
authored
Merge pull request #1095 from infosiftr/pg-config
Add notes on how to configure postgres
2 parents 7c3c703 + cca7584 commit 1df6416

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

postgres/content.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ $ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d %%IMA
1818

1919
This image includes `EXPOSE 5432` (the postgres port), so standard container linking will make it automatically available to the linked containers. The default `postgres` user and database are created in the entrypoint with `initdb`.
2020

21-
> The postgres database is a default database meant for use by users, utilities and third party applications.
21+
> The postgres database is a default database meant for use by users, utilities and third party applications.
22+
>
2223
> [postgresql.org/docs](http://www.postgresql.org/docs/9.5/interactive/app-initdb.html)
2324
2425
## connect to it from an application
@@ -160,6 +161,30 @@ ENV LANG de_DE.utf8
160161

161162
Since database initialization only happens on container startup, this allows us to set the language before it is created.
162163

164+
## Database Configuration
165+
166+
There are many ways to set PostgreSQL server configuration. For information on what is available to configure, see the postgresql.org [docs](https://www.postgresql.org/docs/current/static/runtime-config.html) for the specific version of PostgreSQL that you are running. Here are a few options for setting configuration:
167+
168+
- Use a custom config file. Create a config file and get it into the container. If you need a starting place for your config file you can use the sample provided by PostgreSQL which is available in the container at `/usr/share/postgresql/postgresql.conf.sample`.
169+
170+
- **Important note:** you must set `listen_addresses = '*'`so that other containers will be able to access %%REPO%%.
171+
172+
```console
173+
$ # get the default config
174+
$ docker run -i --rm postgres cat /usr/share/postgresql/postgresql.conf.sample > my-postgres.conf
175+
176+
$ # customize the config
177+
178+
$ # run postgres with custom config
179+
$ docker run -d --name some-postgres -v "$PWD/my-postgres.conf":/etc/postgresql/postgresql.conf %%IMAGE%% -c 'config_file=/etc/postgresql/postgresql.conf'
180+
```
181+
182+
- Set options directly on the run line. The entrypoint script is made so that any options passed to the docker command will be passed along to the `postgres` server daemon. From the [docs](https://www.postgresql.org/docs/current/static/app-postgres.html) we see that any option available in a `.conf` file can be set via `-c`.
183+
184+
```console
185+
$ docker run -d --name some-postgres %%IMAGE%% -c 'shared_buffers=256MB' -c 'max_connections=200'
186+
```
187+
163188
# Caveats
164189

165190
If there is no database when `postgres` starts in a container, then `postgres` will create the default database for you. While this is the expected behavior of `postgres`, this means that it will not accept incoming connections during that time. This may cause issues when using automation tools, such as `docker-compose`, that start several containers simultaneously.

0 commit comments

Comments
 (0)