惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
G
Google Developers Blog
B
Blog
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
The Cloudflare Blog
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
雷峰网
雷峰网
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
量子位
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Help Net Security
Help Net Security
P
Palo Alto Networks Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
N
News | PayPal Newsroom
AWS News Blog
AWS News Blog
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
腾讯CDC
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker

烧饼博客

Ubuntu 24.04 Noble 升级 Ubuntu 26.04 Resolute WSL 2 使用 Docker 桥接模式网络访问 HTTPS 超时的解决方法 Debian / Ubuntu 下使用 nginx-acme 自动签发并配置 SSL 证书 使用 acme.sh 配置 Let's Encrypt 签发的 IP 地址 SSL 证书 RDAP.SS - 基于 RDAP 协议的 Whois 查询网站 Debian 使用 extrepo 配置第三方软件源 Debian 12 Bookworm 升级 Debian 13 Trixie Ubuntu 22.04 Jammy 升级 Ubuntu 24.04 Noble Docker 安装 FreshRSS 教程 Docker 安装 Shlink 自建短网址 Debian 安装 Nextcloud 服务端 Debian 双栈网络时开启 IPv4 优先 Debian / Ubuntu 使用源安装 LAMP 教程 Debian / Ubuntu 使用源安装 LEMP 教程
升级 Debian 后 GitLab PostgreSQL 无法启动的解决方法
Showfom · 2025-09-16 · via 烧饼博客
升级 Debian 后 GitLab PostgreSQL 无法启动的解决方法

本文将介绍在升级 Debian 系统后,GitLab 的 PostgreSQL 数据库无法正常启动的问题。

#背景前提

本文的 GitLab 是基于官方源安装的,具体安装和升级方法限于篇幅,不再阐述。

我们从 Debian 11 升级到 Debian 12 后,再更新 GitLab 会发现如下报错:

gitlab [execute] WARNING: database "postgres" has a collation version mismatch DETAIL: The database was created using collation version 2.31, but the operating system provides version 2.36.

或者从 Debian 12 升级到 Debian 13 后更新 GitLab 也会有如下报错:

WARNING:  database “gitlabhq_production” has a collation version mismatch
DETAIL:  The database was created using collation version 2.36, but the operating system provides version 2.41.
HINT:  Rebuild all objects in this database that use the default collation and run ALTER DATABASE gitlabhq_production REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.

我们以 Debian 13 为例,可以看到系统自带的 glibc 版本为 2.41:

# ldd --version
ldd (Debian GLIBC 2.41-12) 2.41

而 Debian 12 自带的 glibc 版本为 2.36:

# ldd --version
ldd (Debian GLIBC 2.36-9+deb12u13) 2.36

Debian 11 的 glibc 版本为 2.31:

# ldd --version
ldd (Debian GLIBC 2.31-13+deb11u13) 2.31

所以我们直接升级系统以后 GitLab 的 PostgreSQL 数据库仍使用旧版本的排序规则,导致版本不匹配,所以 GitLab 升级会失败。

#解决方法

我们以 Debian 11 升级到 Debian 12 后的情况举例,首先备份一下 GitLab:

sudo gitlab-backup create

然后我们进入 GitLab 的 PostgreSQL 控制台:

接着重新建立索引并修复 gitlabhq_production 数据库:

SET statement_timeout = 0;
REINDEX DATABASE gitlabhq_production;
ALTER DATABASE gitlabhq_production REFRESH COLLATION VERSION;

重建完成后输入 \q 并按回车退出,然后我们修复 template1postgres 数据库:

sudo gitlab-psql -d template1 -c "ALTER DATABASE template1 REFRESH COLLATION VERSION;"
sudo gitlab-psql -d postgres -c "ALTER DATABASE postgres REFRESH COLLATION VERSION;"

修复完成后验证结果:

sudo gitlab-psql -c "
SELECT 
    datname,
    datcollversion,
    pg_collation_actual_version((SELECT oid FROM pg_collation WHERE collname = 'default')) as system_version,
    CASE 
        WHEN datcollversion = pg_collation_actual_version((SELECT oid FROM pg_collation WHERE collname = 'default')) 
        THEN '✅ Good' 
        ELSE '❌ Bad' 
    END as status
FROM pg_database 
WHERE datname IN ('template1', 'postgres', 'gitlabhq_production')
ORDER BY datname;"

如果出现如下结果,则修复完成:

       datname       | datcollversion | system_version | status  
---------------------+----------------+----------------+---------
 gitlabhq_production | 2.36           | 2.36           | ✅ Good
 postgres            | 2.36           | 2.36           | ✅ Good
 template1           | 2.36           | 2.36           | ✅ Good

然后我们就可以重新配置 GitLab 并更新升级了:

sudo gitlab-ctl reconfigure

完成以后重启 GitLab 即可恢复服务: