gitlab遷移及遷移後500問題

gitlab遷移

背景

  • 以前gitlab在阿里雲機部署,由於外網相對不安全考慮遷到內網

環境

  • gitlab-11.11.3 docker部署

實施

  1. 備份
    docker exec -ti gitlab bash
    gitlab-rake gitlab:backup:create
    docker cp gitlab:/var/opt/gitlab/backups/1612427334_2021_02_04_11.11.3_gitlab_backup.tar .
  2. 在內網機器啓動相同版本gitlab(gitlab備份恢復須要相同版本)
docker exec -ti gitlab bash
mv 1612427334_2021_02_04_11.11.3_gitlab_backup.tar /var/opt/gitlab/backups/
chmod 755 /var/opt/gitlab/backups/1612427334_2021_02_04_11.11.3_gitlab_backup.tar
chown root:root /var/opt/gitlab/backups/1612427334_2021_02_04_11.11.3_gitlab_backup.tar
gitlab-rake gitlab:backup:restore BACKUP=1612427334_2021_02_04_11.11.3

問題

1.進入ci/cd runner頁面報500git

gitlab-rails console
Ci::Runner.all.update_all(token_encrypted: nil)

gitlab-rails dbconsole
UPDATE projects SET runners_token = null, runners_token_encrypted = null;

2.新建用戶,在強制用戶修改密碼時報500
log 顯示相似: 由於沒有第一時間寫文章,日誌顯示相似,不是我遇到的日誌。sql

The form contains the following error:

    PG::NotNullViolation: ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, 164, t). : INSERT INTO "project_ci_cd_settings" ("project_id") VALUES (164) RETURNING "id"

解決思路:查看對應表有沒有null值,啓動全新的gitlab對比表結構docker

解決:

gitlabhq_production=> CREATE SEQUENCE user_preference_id_seq INCREMENT BY 1 NO MINVALUE NO MAXVALUE START WITH 106 OWNED BY user_preferences.id;   從新建立sequence
gitlabhq_production=> ALTER TABLE user_preferences ALTER COLUMN id SET DEFAULT NEXTVAL('user_preference_id_seq'::regclass);                         恢復表結構修飾符

3.建立merge時指定給用戶時,提交後500
gitlab日誌:shell

==> /var/log/gitlab/postgresql/current <==
2021-03-18_05:52:05.23424 ERROR:  null value in column "id" violates not-null constraint
2021-03-18_05:52:05.23427 DETAIL:  Failing row contains (null, 61, 4046).
2021-03-18_05:52:05.23427 STATEMENT:  INSERT INTO "merge_request_assignees" ("user_id", "merge_request_id") VALUES (61, 4046) RETURNING "id"

解決:

gitlabhq_production=> CREATE SEQUENCE merge_request_assignees_id_seq INCREMENT BY 1 NO MINVALUE NO MAXVALUE START WITH 106 OWNED BY merge_request_assignees.id;   從新建立sequence
gitlabhq_production=> ALTER TABLE merge_request_assignees ALTER COLUMN id SET DEFAULT NEXTVAL('merge_request_assignees_id_seq'::regclass);                         恢復表結構修飾符

說明:遷移gitlab後會有數據庫序列丟失問題,重建序列,並恢復字段修飾符。對比全新gitlab你會發現,可能會丟失不少seq,建議恢復全部。

參考:https://gitlab.com/gitlab-org/gitlab/-/issues/26020
相關文章
相關標籤/搜索