Skip to content

Commit f8a10c3

Browse files
authored
Merge pull request #2624 from infosiftr/pg-18-docs-update
Update PostgreSQL documentation now that 18 is GA
2 parents 9a15740 + a5b1248 commit f8a10c3

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

postgres/content.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,7 @@ Users who wish to opt-in to this change on older releases can do so by setting `
102102

103103
> **Important Note:** (for PostgreSQL 17 and below) Mount the data volume at `/var/lib/postgresql/data` and not at `/var/lib/postgresql` because mounts at the latter path WILL NOT PERSIST database data when the container is re-created. The Dockerfile that builds the image declares a volume at `/var/lib/postgresql/data` and if no data volume is mounted at that path then the container runtime will automatically create an [anonymous volume](https://docs.docker.com/engine/storage/#volumes) that is not reused across container re-creations. Data will be written to the anonymous volume rather than your intended data volume and won't persist when the container is deleted and re-created.
104104
105-
This optional variable can be used to define another location - like a subdirectory - for the database files. The default is `/var/lib/postgresql/data`. If the data volume you're using is a filesystem mountpoint (like with GCE persistent disks), or remote folder that cannot be chowned to the `postgres` user (like some NFS mounts), or contains folders/files (e.g. `lost+found`), Postgres `initdb` requires a subdirectory to be created within the mountpoint to contain the data.
106-
107-
For example:
108-
109-
```console
110-
$ docker run -d \
111-
--name some-postgres \
112-
-e POSTGRES_PASSWORD=mysecretpassword \
113-
-e PGDATA=/var/lib/postgresql/data/pgdata \
114-
-v /custom/mount:/var/lib/postgresql/data \
115-
%%IMAGE%%
116-
```
117-
118-
This is an environment variable that is not Docker specific. Because the variable is used by the `postgres` server binary (see the [PostgreSQL docs](https://www.postgresql.org/docs/14/app-postgres.html#id-1.9.5.14.7)), the entrypoint script takes it into account.
105+
This (`PGDATA`) is an environment variable that is not Docker specific. Because the variable is used by the `postgres` server binary (see the [PostgreSQL docs](https://www.postgresql.org/docs/14/app-postgres.html#id-1.9.5.14.7)), the entrypoint script takes it into account.
119106

120107
## Docker Secrets
121108

@@ -204,7 +191,7 @@ When using the Alpine variants, any postgres extension not listed in [postgres-c
204191

205192
As of [docker-library/postgres#253](https://github.com/docker-library/postgres/pull/253), this image supports running as a (mostly) arbitrary user via `--user` on `docker run`. As of [docker-library/postgres#1018](https://github.com/docker-library/postgres/pull/1018), this is also the case for the Alpine variants.
206193

207-
The main caveat to note is that `postgres` doesn't care what UID it runs as (as long as the owner of `/var/lib/postgresql/data` matches), but `initdb` *does* care (and needs the user to exist in `/etc/passwd`):
194+
The main caveat to note is that `postgres` doesn't care what UID it runs as (as long as the owner of `PGDATA` matches), but `initdb` *does* care (and needs the user to exist in `/etc/passwd`):
208195

209196
```console
210197
$ docker run -it --rm --user www-data -e POSTGRES_PASSWORD=mysecretpassword %%IMAGE%%
@@ -230,13 +217,13 @@ The three easiest ways to get around this:
230217
3. initialize the target directory separately from the final runtime (with a `chown` in between):
231218

232219
```console
233-
$ docker volume create pgdata
234-
$ docker run -it --rm -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=mysecretpassword %%IMAGE%%
220+
$ docker volume create pg
221+
$ docker run -it --rm -v pg:/var/lib/postgresql -e POSTGRES_PASSWORD=mysecretpassword %%IMAGE%%
235222
The files belonging to this database system will be owned by user "postgres".
236223
...
237224
( once it's finished initializing successfully and is waiting for connections, stop it )
238-
$ docker run -it --rm -v pgdata:/var/lib/postgresql/data bash chown -R 1000:1000 /var/lib/postgresql/data
239-
$ docker run -it --rm --user 1000:1000 -v pgdata:/var/lib/postgresql/data %%IMAGE%%
225+
$ docker run -it --rm -v pg:/var/lib/postgresql bash chown -R 1000:1000 /var/lib/postgresql
226+
$ docker run -it --rm --user 1000:1000 -v pg:/var/lib/postgresql %%IMAGE%%
240227
LOG: database system was shut down at 2017-01-20 00:03:23 UTC
241228
LOG: MultiXact member wraparound protections are now enabled
242229
LOG: autovacuum launcher started
@@ -262,7 +249,7 @@ The Docker documentation is a good starting point for understanding the differen
262249
2. Start your `%%IMAGE%%` container like this:
263250

264251
```console
265-
$ docker run --name some-%%REPO%% -v /my/own/datadir:/var/lib/postgresql/data -e POSTGRES_PASSWORD=mysecretpassword -d %%IMAGE%%:tag
252+
$ docker run --name some-%%REPO%% -v /my/own/datadir:/var/lib/postgresql -e POSTGRES_PASSWORD=mysecretpassword -d %%IMAGE%%:tag
266253
```
267254

268-
The `-v /my/own/datadir:/var/lib/postgresql/data` part of the command mounts the `/my/own/datadir` directory from the underlying host system as `/var/lib/postgresql/data` inside the container, where PostgreSQL by default will write its data files.
255+
The `-v /my/own/datadir:/var/lib/postgresql` part of the command mounts the `/my/own/datadir` directory from the underlying host system as `/var/lib/postgresql` inside the container, where PostgreSQL by default will write its data files.

0 commit comments

Comments
 (0)