Skip to content

Commit daa8e74

Browse files
committed
fix issues for mealie
1 parent d07170d commit daa8e74

4 files changed

Lines changed: 78 additions & 19 deletions

File tree

Containerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ RUN pkg update && \
2828
pkg clean -ay && \
2929
rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
3030

31-
# Create directories
32-
RUN mkdir -p /var/db/postgres/data${PG_VERSION} /var/run/postgresql /run/secrets /docker-entrypoint-initdb.d && \
33-
chown -R bsd:bsd /var/db/postgres /var/run/postgresql /run/secrets /docker-entrypoint-initdb.d
31+
# Create directories (use Linux-compatible paths for drop-in replacement)
32+
RUN mkdir -p /var/lib/postgresql/data /var/run/postgresql /run/secrets /docker-entrypoint-initdb.d && \
33+
chmod 755 /var/lib && \
34+
chown -R bsd:bsd /var/lib/postgresql /var/run/postgresql /run/secrets /docker-entrypoint-initdb.d
3435

3536
# Copy service definitions and init scripts
3637
COPY root/ /
@@ -39,13 +40,13 @@ COPY root/ /
3940
RUN chmod +x /etc/services.d/*/run /etc/cont-init.d/* 2>/dev/null || true
4041

4142
# Store PG version for scripts
42-
RUN echo "${PG_VERSION}" > /var/db/postgres/pg_version
43+
RUN mkdir -p /var/db/postgres && echo "${PG_VERSION}" > /var/db/postgres/pg_version
4344

4445
# Extract package version for tagging (e.g., 17.7 or 14.20)
4546
RUN mkdir -p /app && \
4647
pkg query '%v' postgresql${PG_VERSION}-server | sed 's/_.*$//' > /app/version
4748

48-
ENV PGDATA="/var/db/postgres/data${PG_VERSION}" \
49+
ENV PGDATA="/var/lib/postgresql/data" \
4950
PG_VERSION="${PG_VERSION}" \
5051
POSTGRES_USER="postgres" \
5152
POSTGRES_PASSWORD="" \
@@ -54,4 +55,4 @@ ENV PGDATA="/var/db/postgres/data${PG_VERSION}" \
5455
POSTGRES_HOST_AUTH_METHOD="scram-sha-256"
5556

5657
EXPOSE 5432
57-
VOLUME /var/db/postgres
58+
VOLUME /var/lib/postgresql/data

README.md

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PostgreSQL
22

3-
PostgreSQL database server on FreeBSD.
3+
PostgreSQL database server on FreeBSD. **Drop-in replacement** for the official `postgres` Docker image.
44

55
> **Requires [patched ocijail](https://github.com/daemonless/daemonless#ocijail-patch)** for SysV IPC support (`org.freebsd.jail.allow.sysvipc=true`)
66
@@ -10,7 +10,7 @@ PostgreSQL database server on FreeBSD.
1010
podman run -d --name postgres \
1111
-p 5432:5432 \
1212
-e POSTGRES_PASSWORD=mysecretpassword \
13-
-v /path/to/data:/var/db/postgres \
13+
-v /path/to/data:/var/lib/postgresql/data \
1414
--annotation 'org.freebsd.jail.allow.sysvipc=true' \
1515
ghcr.io/daemonless/postgres:17
1616
```
@@ -27,7 +27,7 @@ services:
2727
- POSTGRES_PASSWORD=mysecretpassword
2828
- POSTGRES_DB=mydb
2929
volumes:
30-
- /data/postgres:/var/db/postgres
30+
- /data/postgres:/var/lib/postgresql/data
3131
ports:
3232
- 5432:5432
3333
annotations:
@@ -56,7 +56,7 @@ services:
5656
| `POSTGRES_USER` | `postgres` | Database superuser name |
5757
| `POSTGRES_PASSWORD` | (empty) | Superuser password |
5858
| `POSTGRES_DB` | `postgres` | Default database name |
59-
| `PGDATA` | `/var/db/postgres/dataXX` | Data directory (XX = version) |
59+
| `PGDATA` | `/var/lib/postgresql/data` | Data directory |
6060
| `POSTGRES_INITDB_ARGS` | (empty) | Extra args for initdb (e.g., `--data-checksums`) |
6161
| `POSTGRES_HOST_AUTH_METHOD` | `scram-sha-256` | Auth method (`scram-sha-256`, `md5`, `trust`) |
6262

@@ -84,7 +84,7 @@ Scripts run in sorted filename order after database creation.
8484

8585
| Path | Description |
8686
|------|-------------|
87-
| `/var/db/postgres` | PostgreSQL data directory |
87+
| `/var/lib/postgresql/data` | PostgreSQL data directory |
8888

8989
## Ports
9090

@@ -96,6 +96,64 @@ Scripts run in sorted filename order after database creation.
9696

9797
- **User:** `bsd` (UID/GID 1000)
9898

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+
99157
## Links
100158

101159
- [PostgreSQL Website](https://www.postgresql.org/)

root/etc/cont-init.d/10-postgres-config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ for var in $(env | grep '_FILE=' | cut -d= -f1); do
1414
fi
1515
done
1616

17-
PG_VERSION=$(cat /var/db/postgres/pg_version 2>/dev/null || echo "17")
18-
PGDATA="/var/db/postgres/data${PG_VERSION}"
17+
# Use Linux-compatible path for drop-in replacement
18+
PGDATA="/var/lib/postgresql/data"
1919

20-
echo "Setting up PostgreSQL ${PG_VERSION}..."
20+
echo "Setting up PostgreSQL..."
2121

2222
# Create required directories
2323
mkdir -p "$PGDATA" /var/run/postgresql
2424

2525
# Set ownership (bsd:bsd is UID/GID 1000:1000)
26-
chown -R bsd:bsd /var/db/postgres /var/run/postgresql
26+
chown -R bsd:bsd /var/lib/postgresql /var/run/postgresql
2727

2828
echo "PostgreSQL configuration complete"

root/etc/services.d/postgresql/run

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/sh
22
# PostgreSQL s6 service
33

4-
PG_VERSION=$(cat /var/db/postgres/pg_version 2>/dev/null || echo "17")
5-
PGDATA="/var/db/postgres/data${PG_VERSION}"
4+
# Use Linux-compatible path for drop-in replacement
5+
PGDATA="/var/lib/postgresql/data"
66

77
# Initialize database if needed
88
if [ ! -f "$PGDATA/PG_VERSION" ]; then
9-
echo "Initializing PostgreSQL ${PG_VERSION} database..."
9+
echo "Initializing PostgreSQL database..."
1010

1111
# Build initdb command with optional args
1212
INITDB_CMD="/usr/local/bin/initdb -D $PGDATA -E UTF8 --locale=C"
@@ -79,5 +79,5 @@ if [ ! -f "$PGDATA/PG_VERSION" ]; then
7979
/usr/local/bin/s6-setuidgid bsd /usr/local/bin/pg_ctl -D "$PGDATA" -w stop
8080
fi
8181

82-
echo "Starting PostgreSQL ${PG_VERSION}..."
82+
echo "Starting PostgreSQL..."
8383
exec /usr/local/bin/s6-setuidgid bsd /usr/local/bin/postgres -D "$PGDATA"

0 commit comments

Comments
 (0)