本文由 AI 分析生成
建立時間: 2026-03-28 來源: https://vonng.com/db/no-docker-pg/
Summary
Feng Ruohang (老冯) explains a specific and dangerous failure mode in Docker’s official PostgreSQL images: when a minor PostgreSQL version upgrade triggers a Debian base image update, glibc is updated, changing locale/collation files. Data and indexes built on old collation rules are now inconsistent with the new glibc — causing incorrect query results, wrong sort orders, and potential data corruption. The fix normally required only for major version upgrades becomes necessary for minor ones too.
老冯解析 Docker 官方 PostgreSQL 映像中一個危險的失敗模式:PostgreSQL 小版本升級觸發 Debian 基礎映像更新時,glibc 也隨之更新,導致排序規則(locale/collation)文件改變。建置在舊排序規則上的資料和索引與新 glibc 不一致,可能導致查詢結果錯誤、排序錯誤,甚至資料損毀。
Key Points
- Docker official Postgres images support only 2 Debian versions; when Debian updates, the base image changes automatically unless you pin the version
- New Debian = new glibc = new locale/collation files — but existing DB data/indexes were built on old collation
- Result: collation version mismatch warning, potentially incorrect sort results, corrupted indexes
- Fix requires
ALTER DATABASE "mydb" REFRESH COLLATION VERSIONand rebuilding all affected objects — normally only needed for major PG upgrades - Solution: always pin the Debian base image version in Docker image tags
- Better solution: don’t run PostgreSQL in Docker for production
Insights
This is a cautionary tale about implicit transitive dependencies: you’re upgrading PostgreSQL patch version, but Docker makes you also implicitly upgrade Debian and therefore glibc and therefore locale files. The compound dependency chain makes otherwise safe operations (minor version updates) dangerous. The “official” label on Docker Hub creates false confidence — official means maintained, not production-safe.
Connections
Raw Excerpt
Docker 官方镜像强行把这东西甩到用户脸上:小版本升级也可能触发 glibc/locale 变化。小心!官方镜像并不意味着”负责任的生产环境表现”