postgresql - GitLab 在操作系统升级到 RHEL 7.6 后遇到 PostgreSQL 问题

标签 postgresql gitlab gitlab-ce

我们最近升级了操作系统:

$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.6 (Maipo)

升级后,我们在 GitLab(主要是 Postgres)方面面临很多问题。

我们的 GitLab 是码头化的,即 GitLab(及其所有内部服务,包括 PostgreSQL)在单个容器中运行。容器没有自己的 glibc,因此它使用操作系统中的 glibc。

ERROR: canceling statement due to statement timeout

STATEMENT:
SELECT relnamespace::regnamespace as schemaname, relname as relname, pg_total_relation_size(oid) bytes FROM pg_class WHERE relkind = 'r';

超时消息不断出现,这导致用户在访问 GitLab 时遇到 502 错误。

我检查了数据库上设置的语句超时。

gitlabhq_production=# show statement_timeout;
 statement_timeout
-------------------
 1min
(1 row)

我不知道该怎么办。这可能是默认设置。这是postgres的问题吗?这是什么意思?我能做些什么来解决这个问题?

编辑:

检查了 pg_stat_activity 并且没有看到任何锁定,因为服务器之前已重新启动。同一个查询现在运行良好,但我们一直间歇性地看到这个问题。

运行 \d pg_class 来检查表是否使用任何索引并检查字符串列。

gitlabhq_production=# \d pg_class
         Table "pg_catalog.pg_class"
       Column        |   Type    | Modifiers
---------------------+-----------+-----------
 relname             | name      | not null
 relnamespace        | oid       | not null
 reltype             | oid       | not null
 reloftype           | oid       | not null
 relowner            | oid       | not null
 relam               | oid       | not null
 relfilenode         | oid       | not null
 reltablespace       | oid       | not null
 relpages            | integer   | not null
 reltuples           | real      | not null
 relallvisible       | integer   | not null
 reltoastrelid       | oid       | not null
 relhasindex         | boolean   | not null
 relisshared         | boolean   | not null
 relpersistence      | "char"    | not null
 relkind             | "char"    | not null
 relnatts            | smallint  | not null
 relchecks           | smallint  | not null
 relhasoids          | boolean   | not null
 relhaspkey          | boolean   | not null
 relhasrules         | boolean   | not null
 relhastriggers      | boolean   | not null
 relhassubclass      | boolean   | not null
 relrowsecurity      | boolean   | not null
 relforcerowsecurity | boolean   | not null
 relispopulated      | boolean   | not null
 relreplident        | "char"    | not null
 relfrozenxid        | xid       | not null
 relminmxid          | xid       | not null
 relacl              | aclitem[] |
 reloptions          | text[]    |
Indexes:
    "pg_class_oid_index" UNIQUE, btree (oid)
    "pg_class_relname_nsp_index" UNIQUE, btree (relname, relnamespace)
    "pg_class_tblspc_relfilenode_index" btree (reltablespace, relfilenode)

重新索引所有表并可能改变表有帮助吗?

最佳答案

您应该检查查询是否运行了一分钟,或者它是否被数据库锁阻塞了。这可以从后端的 pg_stat_activity 行看出,它将显示查询是否正在等待锁(state=activewait_event_typewait_event 表示锁定)。

如果是锁,去掉锁事务。它可能是一个准备好的交易,所以也要检查这些。

如果没有锁定错误,可能是您的索引已被操作系统升级损坏:

由于 PostgreSQL 使用操作系统归类,字符串上的数据库索引按归类顺序排序,并且操作系统升级可能(并且经常)导致归类因 C 库中的错误修复而发生更改,因此您应该重建字符串上的所有索引此类升级后的列。

您显示的语句不使用索引扫描,因此它不应该受到影响,但其他语句可能会受到影响。

另外,如果你使用的是Docker,可能是你的容器使用了自己的glibc,没有升级,那么你不受影响。

关于postgresql - GitLab 在操作系统升级到 RHEL 7.6 后遇到 PostgreSQL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56697274/

相关文章:

ruby-on-rails - 通过 Rails PostgreSQL 中的迁移将旧字符串值转换为日期时间

github - 在推送时自动将 Gitlab 存储库镜像到 Github

gitlab - Gitlab 的 "pages"作业在内部是如何工作的?

git - ssh:无法解析主机名(Docker、gitlab-ce)

django - Django 1.11.8 中的子查询非常慢 - 我可以加快速度吗?

sql - 在 GROUP BY 中使用 SELECT 的 Case 语句的 columnName

docker - 在构建 Docker 镜像时使用来自私有(private) gitlab 存储库的 pip install

gitlab:将存储库移动到 gitlab 中的另一个组

docker - Gitlab 不加载新的 ssl 证书和 key

postgresql - Postgres 会将 WHERE 子句下推到带有窗口函数(聚合)的 VIEW 中吗?