|
1 | 1 | # PostgreSQL |
2 | 2 |
|
3 | | -PostgreSQL database server on FreeBSD. **Drop-in replacement** for the official `postgres` Docker image. |
| 3 | +The World's Most Advanced Open Source Relational Database on FreeBSD. |
4 | 4 |
|
5 | | -> **Requires [patched ocijail](https://github.com/daemonless/daemonless#ocijail-patch)** for SysV IPC support (`org.freebsd.jail.allow.sysvipc=true`) |
| 5 | +| | | |
| 6 | +|---|---| |
| 7 | +| **Port** | 5432 | |
| 8 | +| **Registry** | `ghcr.io/daemonless/postgres` | |
| 9 | +| **Source** | [https://www.postgresql.org/](https://www.postgresql.org/) | |
| 10 | +| **Website** | [https://www.postgresql.org/](https://www.postgresql.org/) | |
6 | 11 |
|
7 | | -## Quick Start |
| 12 | +## Deployment |
8 | 13 |
|
9 | | -```bash |
10 | | -podman run -d --name postgres \ |
11 | | - -p 5432:5432 \ |
12 | | - -e POSTGRES_PASSWORD=mysecretpassword \ |
13 | | - -v /path/to/data:/var/lib/postgresql/data \ |
14 | | - --annotation 'org.freebsd.jail.allow.sysvipc=true' \ |
15 | | - ghcr.io/daemonless/postgres:17 |
16 | | -``` |
17 | | - |
18 | | -## podman-compose |
| 14 | +### Podman Compose |
19 | 15 |
|
20 | 16 | ```yaml |
21 | 17 | services: |
22 | 18 | postgres: |
23 | | - image: ghcr.io/daemonless/postgres:17 |
| 19 | + image: ghcr.io/daemonless/postgres:latest |
24 | 20 | container_name: postgres |
25 | 21 | environment: |
26 | 22 | - POSTGRES_USER=postgres |
27 | | - - POSTGRES_PASSWORD=mysecretpassword |
28 | | - - POSTGRES_DB=mydb |
| 23 | + - POSTGRES_PASSWORD=postgres |
| 24 | + - POSTGRES_DB=postgres |
| 25 | + - PUID=1000 |
| 26 | + - PGID=1000 |
| 27 | + - TZ=UTC |
29 | 28 | volumes: |
30 | | - - /data/postgres:/var/lib/postgresql/data |
| 29 | + - /path/to/containers/postgres/var/lib/postgresql/data:/var/lib/postgresql/data |
31 | 30 | ports: |
32 | 31 | - 5432:5432 |
33 | | - annotations: |
34 | | - org.freebsd.jail.allow.sysvipc: "true" |
35 | 32 | restart: unless-stopped |
36 | 33 | ``` |
37 | 34 |
|
38 | | -## Tags |
39 | | -
|
40 | | -| Tag | Base | Description | |
41 | | -|-----|------|-------------| |
42 | | -| `:17` | quarterly | PostgreSQL 17 | |
43 | | -| `:17-pkg` | quarterly | Alias for `:17` | |
44 | | -| `:17-pkg-latest` | latest | PostgreSQL 17 (latest packages) | |
45 | | -| `:14` | quarterly | PostgreSQL 14 | |
46 | | -| `:14-pkg` | quarterly | Alias for `:14` | |
47 | | -| `:14-pkg-latest` | latest | PostgreSQL 14 (latest packages) | |
48 | | -| `:latest` | quarterly | Alias for `:17` | |
49 | | -| `:pkg` | quarterly | Alias for `:17` | |
50 | | -| `:pkg-latest` | latest | Alias for `:17-pkg-latest` | |
| 35 | +### Podman CLI |
51 | 36 |
|
52 | | -## Environment Variables |
53 | | - |
54 | | -| Variable | Default | Description | |
55 | | -|----------|---------|-------------| |
56 | | -| `POSTGRES_USER` | `postgres` | Database superuser name | |
57 | | -| `POSTGRES_PASSWORD` | (empty) | Superuser password | |
58 | | -| `POSTGRES_DB` | `postgres` | Default database name | |
59 | | -| `PGDATA` | `/var/lib/postgresql/data` | Data directory | |
60 | | -| `POSTGRES_INITDB_ARGS` | (empty) | Extra args for initdb (e.g., `--data-checksums`) | |
61 | | -| `POSTGRES_HOST_AUTH_METHOD` | `scram-sha-256` | Auth method (`scram-sha-256`, `md5`, `trust`) | |
62 | | - |
63 | | -### Docker Secrets |
64 | | - |
65 | | -Secrets can be passed via `*_FILE` environment variables: |
| 37 | +```bash |
| 38 | +podman run -d --name postgres \ |
| 39 | + -p 5432:5432 \ |
| 40 | + -e POSTGRES_USER=postgres \ |
| 41 | + -e POSTGRES_PASSWORD=postgres \ |
| 42 | + -e POSTGRES_DB=postgres \ |
| 43 | + -e PUID=@PUID@ \ |
| 44 | + -e PGID=@PGID@ \ |
| 45 | + -e TZ=@TZ@ \ |
| 46 | + -v /path/to/containers/postgres/var/lib/postgresql/data:/var/lib/postgresql/data \ |
| 47 | + ghcr.io/daemonless/postgres:latest |
| 48 | +``` |
| 49 | +Access at: `http://localhost:5432` |
66 | 50 |
|
67 | | -| Variable | Description | |
68 | | -|----------|-------------| |
69 | | -| `POSTGRES_PASSWORD_FILE` | Path to file containing password | |
| 51 | +### Ansible |
70 | 52 |
|
71 | | -## Initialization Scripts |
| 53 | +```yaml |
| 54 | +- name: Deploy postgres |
| 55 | + containers.podman.podman_container: |
| 56 | + name: postgres |
| 57 | + image: ghcr.io/daemonless/postgres:latest |
| 58 | + state: started |
| 59 | + restart_policy: always |
| 60 | + env: |
| 61 | + POSTGRES_USER: "postgres" |
| 62 | + POSTGRES_PASSWORD: "postgres" |
| 63 | + POSTGRES_DB: "postgres" |
| 64 | + PUID: "1000" |
| 65 | + PGID: "1000" |
| 66 | + TZ: "UTC" |
| 67 | + ports: |
| 68 | + - "5432:5432" |
| 69 | + volumes: |
| 70 | + - "/path/to/containers/postgres/var/lib/postgresql/data:/var/lib/postgresql/data" |
| 71 | +``` |
72 | 72 |
|
73 | | -Place scripts in `/docker-entrypoint-initdb.d/` to run on first startup: |
| 73 | +## Configuration |
74 | 74 |
|
75 | | -| Extension | Behavior | |
76 | | -|-----------|----------| |
77 | | -| `*.sh` | Executed if executable, sourced otherwise | |
78 | | -| `*.sql` | Run via psql against `$POSTGRES_DB` | |
79 | | -| `*.sql.gz` | Decompressed and run via psql | |
| 75 | +### Environment Variables |
80 | 76 |
|
81 | | -Scripts run in sorted filename order after database creation. |
| 77 | +| Variable | Default | Description | |
| 78 | +|----------|---------|-------------| |
| 79 | +| `POSTGRES_USER` | `postgres` | Database superuser name (default: postgres) | |
| 80 | +| `POSTGRES_PASSWORD` | `postgres` | Database superuser password | |
| 81 | +| `POSTGRES_DB` | `postgres` | Default database to create (default: same as user) | |
| 82 | +| `PUID` | `1000` | | |
| 83 | +| `PGID` | `1000` | | |
| 84 | +| `TZ` | `UTC` | | |
82 | 85 |
|
83 | | -## Volumes |
| 86 | +### Volumes |
84 | 87 |
|
85 | 88 | | Path | Description | |
86 | 89 | |------|-------------| |
87 | | -| `/var/lib/postgresql/data` | PostgreSQL data directory | |
| 90 | +| `/var/lib/postgresql/data` | Database data directory | |
88 | 91 |
|
89 | | -## Ports |
| 92 | +### Ports |
90 | 93 |
|
91 | | -| Port | Description | |
92 | | -|------|-------------| |
93 | | -| 5432 | PostgreSQL | |
| 94 | +| Port | Protocol | Description | |
| 95 | +|------|----------|-------------| |
| 96 | +| `5432` | TCP | PostgreSQL port | |
94 | 97 |
|
95 | 98 | ## Notes |
96 | 99 |
|
97 | | -- **User:** `bsd` (UID/GID 1000) |
98 | | - |
99 | | -## Migrating from Linux |
100 | | - |
101 | | -**You cannot copy a Linux postgres data directory directly to FreeBSD.** PostgreSQL stores locale information (`en_US.utf8`) in the database cluster, and FreeBSD uses a different locale format (`en_US.UTF-8`). Attempting to use copied data will fail with: |
102 | | - |
103 | | -``` |
104 | | -FATAL: database locale is incompatible with operating system |
105 | | -DETAIL: The database was initialized with LC_COLLATE "en_US.utf8", which is not recognized by setlocale(). |
106 | | -``` |
107 | | -
|
108 | | -### Migration Steps |
109 | | -
|
110 | | -1. **Dump from Linux** (while postgres is running): |
111 | | - ```bash |
112 | | - podman exec postgres pg_dump -U myuser mydb > mydb.sql |
113 | | - ``` |
114 | | - |
115 | | -2. **Start fresh FreeBSD postgres**: |
116 | | - ```bash |
117 | | - podman run -d --name postgres \ |
118 | | - -e POSTGRES_USER=myuser \ |
119 | | - -e POSTGRES_PASSWORD=mypassword \ |
120 | | - -e POSTGRES_DB=mydb \ |
121 | | - -v /containers/myapp/pgdata:/var/lib/postgresql/data \ |
122 | | - --annotation 'org.freebsd.jail.allow.sysvipc=true' \ |
123 | | - ghcr.io/daemonless/postgres:17 |
124 | | - ``` |
125 | | - |
126 | | -3. **Restore the dump**: |
127 | | - ```bash |
128 | | - cat mydb.sql | podman exec -i postgres psql -U myuser -d mydb |
129 | | - ``` |
130 | | - |
131 | | -### Full Database Cluster Migration |
132 | | - |
133 | | -To migrate all databases and roles: |
134 | | - |
135 | | -```bash |
136 | | -# On source (Linux or FreeBSD) |
137 | | -podman exec postgres pg_dumpall -U postgres > all_databases.sql |
138 | | - |
139 | | -# On target (after starting fresh postgres) |
140 | | -cat all_databases.sql | podman exec -i postgres psql -U postgres |
141 | | -``` |
142 | | - |
143 | | -## Migrating from FreeBSD to Linux |
144 | | - |
145 | | -The same locale incompatibility applies in reverse. FreeBSD uses `C` or `en_US.UTF-8` locales, which Linux postgres may not recognize. Use pg_dump/restore: |
146 | | - |
147 | | -```bash |
148 | | -# On FreeBSD |
149 | | -podman exec postgres pg_dump -U myuser mydb > mydb.sql |
150 | | - |
151 | | -# On Linux (after starting fresh postgres) |
152 | | -cat mydb.sql | podman exec -i postgres psql -U myuser -d mydb |
153 | | -``` |
154 | | - |
155 | | -**Bottom line:** Always use `pg_dump`/`pg_restore` when moving postgres data between Linux and FreeBSD, regardless of direction. |
156 | | - |
157 | | -## Links |
158 | | - |
159 | | -- [PostgreSQL Website](https://www.postgresql.org/) |
160 | | -- [FreshPorts postgresql17-server](https://www.freshports.org/databases/postgresql17-server/) |
161 | | -- [FreshPorts postgresql14-server](https://www.freshports.org/databases/postgresql14-server/) |
| 100 | +- **User:** `bsd` (UID/GID set via PUID/PGID) |
| 101 | +- **Base:** Built on `ghcr.io/daemonless/base` (FreeBSD) |
0 commit comments