You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派Docker环境下PostgreSQL容器启动失败(Segmentation Fault错误)求助

PostgreSQL Docker container crashes with segmentation fault on Raspberry Pi after reboot when using existing data directory

I've had a Docker Compose setup running smoothly for months, but after rebooting my Raspberry Pi, it's no longer working. Here's the breakdown:

  • When pointing the database to an empty DB folder, the PostgreSQL container starts up fine with no errors.
  • But when using the backup of my existing database data folder, the container fails to start with a segmentation fault.

The error logs from PostgreSQL are:

PostgreSQL Database directory appears to contain a database; Skipping initialization
2021-03-30 13:38:46.052 UTC [1] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on arm-unknown-linux-gnueabihf, compiled by gcc (Debian 8.3.0-6) 8.3.0, 32-bit
2021-03-30 13:38:46.053 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-03-30 13:38:46.053 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-03-30 13:38:46.063 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-03-30 13:38:48.195 UTC [1] LOG: startup process (PID 26) was terminated by signal 11: Segmentation fault
2021-03-30 13:38:48.195 UTC [1] LOG: aborting startup due to startup process failure
2021-03-30 13:38:48.272 UTC [1] LOG: database system is shut down

Here's the relevant Docker Compose snippet for the database:

miniflux-db:
  container_name: miniflux-db
  image: postgres:12-alpine
  environment:
    - POSTGRES_USER=${MINIFLUX_DB_USER}
    - POSTGRES_PASSWORD=${MINIFLUX_DB_PASSWORD}
  restart: unless-stopped
  volumes:
    - ${MINIFLUX_DB}:/var/lib/postgresql/data:shared
  networks:
    - miniflux-net

Environment details:

  • Raspberry Pi 4
  • Docker version 20.10.5, build 55c4c88

I can't migrate the data to PostgreSQL 13, and I can't use this data directory on Intel architecture either. I now realize PostgreSQL data directories are architecture-dependent, but I need help recovering my data. Thanks!


Answer

First, let's break down what's happening here: that segmentation fault on startup almost always means your PostgreSQL data directory got corrupted during the Pi reboot. Since empty directories work fine, the issue is definitely with the existing data files, not the container image or Docker setup.

Here are the steps you can try to recover your data:

1. First, make a full backup of your corrupted data directory

Before you do anything else, copy the entire MINIFLUX_DB folder to a safe location. You don't want to make the corruption worse:

cp -r /path/to/your/miniflux-db /path/to/safe/backup/location

2. Try running PostgreSQL's built-in repair tool

PostgreSQL has a utility called pg_resetwal (formerly pg_resetxlog) that can fix corrupted transaction logs, which are often the cause of startup crashes after an unexpected shutdown.

To run this, you'll need to start a temporary container that has access to your data directory, and execute the tool:

docker run --rm -v ${MINIFLUX_DB}:/var/lib/postgresql/data postgres:12-alpine pg_resetwal -f /var/lib/postgresql/data

The -f flag forces the reset even if the tool detects potential issues. Once this is done, try starting your original container again with docker-compose up -d miniflux-db.

3. If repair fails, extract data using a temporary container

If pg_resetwal doesn't work, you can try to export the data by starting a container in single-user mode, which might let you dump the database even if it's corrupted:

  1. Start the container in single-user mode:
docker run -it --rm -v ${MINIFLUX_DB}:/var/lib/postgresql/data postgres:12-alpine postgres --single -D /var/lib/postgresql/data
  1. If you get a prompt, try running a dump command to save your data to a file:
COPY (SELECT * FROM your_table_name) TO '/var/lib/postgresql/data/your_table_dump.csv' WITH CSV HEADER;

Replace your_table_name with each table in your Miniflux database (you might need to recall the schema, or if you can list tables with \dt if the single-user mode allows it).

Alternatively, if single-user mode doesn't work, try using pg_dump in a temporary container, even if it's partial:

docker run --rm -v ${MINIFLUX_DB}:/var/lib/postgresql/data -v $(pwd):/dump postgres:12-alpine pg_dump -U ${MINIFLUX_DB_USER} -d miniflux > /dump/miniflux_dump.sql

Note: You might need to specify the database name (usually miniflux for Miniflux) and adjust the user/path as needed.

4. Restore to a fresh database

Once you have a dump file, create a new empty database container (using the empty folder that works), then import the dump:

  1. Start the fresh container:
docker-compose up -d miniflux-db
  1. Wait for it to initialize, then import the dump:
docker exec -i miniflux-db psql -U ${MINIFLUX_DB_USER} -d miniflux < /path/to/miniflux_dump.sql

A note about architecture dependency

You're right that PostgreSQL data directories are tied to the CPU architecture (ARM vs Intel) and major PostgreSQL version. That's why you can't just copy the folder to an Intel machine or upgrade directly to 13 without a dump/restore. Going forward, it's a good practice to regularly take SQL dumps of your database so you can easily restore it across different environments or versions.


内容的提问来源于stack exchange,提问作者Sovereign108

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 11:57:29