极狐GitLab 如何管理 PostgreSQL 扩展?

GitLab 是一个全球知名的一体化 DevOps 平台,很多人都通过私有化部署 GitLab 来进行源代码托管。极狐GitLabhttps://gitlab.cn/install?channel=content\&utm_source=csdn 是 GitLab 在中国的发行版,专门为中国程序员服务。可以一键式部署极狐GitLab。

极狐GitLab 在 5 月 28 日正式发布了 AI 产品驭码CodeRider。现已开启免费试用,登录官网:https://coderider.gitlab.cn/ 即可申请试用。

更多关于极狐GitLabhttps://gitlab.cn 或者 DevOps 的最佳实践,可以关注文末的极狐GitLab 公众号。

学习极狐GitLab 的相关资料:

  1. 极狐GitLab 官网https://gitlab.cn
  2. 极狐GitLab 官网文档https://docs.gitlab.cn
  3. 极狐GitLab 论坛https://forum.gitlab.cn/
  4. 极狐GitLab 安装配置https://gitlab.cn/install
  5. 极狐GitLab 资源中心https://resources.gitlab.cn/
  6. AI 产品驭码CodeRiderhttps://coderider.gitlab.cn/

搜索【极狐GitLab】公众号,后台输入加群 ,备注gitlab,即可加入官方微信技术交流群。

本指南记录了如何管理安装外部 PostgreSQL 数据库的 PostgreSQL 扩展。

您必须将以下扩展加载到主要极狐GitLab 数据库中(默认为 gitlabhq_production):

扩展 最小极狐GitLab 版本
pg_trgm 8.6
btree_gist 13.1
plpgsql 11.7

如果您使用 Geo,则必须将以下扩展加载到所有次要跟踪数据库中(默认为 gitlabhq_geo_production):

扩展 最小极狐GitLab 版本
plpgsql 9.0

为了安装扩展,PostgreSQL 要求用户具有超级用户权限。通常,极狐GitLab 数据库用户不是超级用户。因此,在安装扩展时不能使用常规数据库迁移,而是必须在将极狐GitLab 升级到更新版本之前手动安装扩展。

手动安装 PostgreSQL 扩展

为了安装 PostgreSQL 扩展,应遵循以下过程:

  1. 使用超级用户连接到极狐GitLab PostgreSQL 数据库,例如:

    sudo gitlab-psql -d gitlabhq_production

  2. 使用 CREATE EXTENSION 安装扩展程序(本例中为 btree_gist):

    CREATE EXTENSION IF NOT EXISTS btree_gist

  3. 验证已安装的扩展:

    gitlabhq_production=# \dx
    List of installed extensions
    Name | Version | Schema | Description
    ------------+---------+------------+-------------------------------------------------------------------
    btree_gist | 1.5 | public | support for indexing common datatypes in GiST
    pg_trgm | 1.4 | public | text similarity measurement and index searching based on trigrams
    plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
    (3 rows)

在某些系统上,您可能需要安装额外的软件包(例如,postgresql-contrib)才能使某些扩展可用。

典型故障场景

以下是由于未先安装扩展而导致新的极狐GitLab 安装失败的示例。

复制代码
---- Begin output of "bash"  "/tmp/chef-script20210513-52940-d9b1gs" ----
STDOUT: psql:/opt/gitlab/embedded/service/gitlab-rails/db/structure.sql:9: ERROR:  permission denied to create extension "btree_gist"
HINT:  Must be superuser to create this extension.
rake aborted!
failed to execute:
psql -v ON_ERROR_STOP=1 -q -X -f /opt/gitlab/embedded/service/gitlab-rails/db/structure.sql --single-transaction gitlabhq_production

以下是在运行迁移之前未安装扩展的情况示例。

在这种情况下,由于权限不足,数据库迁移无法创建扩展 btree_gist

复制代码
== 20200515152649 EnableBtreeGistExtension: migrating =========================
-- execute("CREATE EXTENSION IF NOT EXISTS btree_gist")

GitLab requires the PostgreSQL extension 'btree_gist' installed in database 'gitlabhq_production', but
the database user is not allowed to install the extension.

You can either install the extension manually using a database superuser:

  CREATE EXTENSION IF NOT EXISTS btree_gist

Or, you can solve this by logging in to the GitLab database (gitlabhq_production) using a superuser and running:

    ALTER regular WITH SUPERUSER

This query will grant the user superuser permissions, ensuring any database extensions
can be installed through migrations.

要从失败的迁移中恢复,必须由超级用户手动安装扩展,并且通过重新运行数据库迁移完成极狐GitLab 升级:

复制代码
sudo gitlab-rake db:migrate
相关推荐
广州灵眸科技有限公司7 小时前
xfce桌面触摸校准:基于灵眸科技EASY-EAl-Orin-Nano
数据库·windows·科技
憧憬成为web高手10 小时前
皮卡丘靶场速通--sql 2
数据库·sql·mybatis
段一凡-华北理工大学10 小时前
向量数据库实战:选型、调优与落地~系列文章12:文本分块策略实战:chunk_size 怎么选?重叠多少?
开发语言·数据库·后端·oracle·rust·工业智能体·高炉智能化
oradh12 小时前
Oracle XTTS实现跨版本迁移和升级(Oracle 11g单库升级至19C RAC集群)
数据库·oracle·11g升级19c·xtts跨版本迁移和升级
z1234567898613 小时前
2026最新两款AI编程工具深度对比实测
java·数据库·ai编程
程序猿DD13 小时前
一个 API Key,统一调用大模型、生图和联网搜索
数据库·网关
java_logo13 小时前
Docker Compose 部署 ClickHouse:快速搭建高性能列式数据库
数据库·clickhouse·docker·列式数据库·轩辕镜像·高性能数据库·clickhouse部署教程
MC皮蛋侠客13 小时前
uv 系列(七):CI/CD、Docker 与私有索引——生产级交付
python·ci/cd·docker·uv
尽兴-14 小时前
企业业务系统架构选型与渐进式演进
运维·系统架构·devops
TlSfoward14 小时前
抓包代理链路下的 TLS 指纹变化分析 TLSFOWARD抓包工具
数据库·爬虫·网络协议·搜索引擎·php