Update 17.8.5 to (17.9.0, 17.9.1, 17.9.2)

Hello everyone, I’m not sure if I’m writing in the right category. I need help
When updating from 17.8.5 to (17.9.0, 17.9.1, 17.9.2) an error occurs

main: == 20250129135703 AddNotNullCheckConstraintMrComplianceViolationsTargetProjectId: migrating 
main: -- current_schema(nil)
main:    -> 0.0003s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("ALTER TABLE merge_requests_compliance_violations\nADD CONSTRAINT check_860e317e6f\nCHECK ( target_project_id IS NOT NULL )\nNOT VALID;\n")
main:    -> 0.0005s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- execute("ALTER TABLE merge_requests_compliance_violations VALIDATE CONSTRAINT check_860e317e6f;")
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == [advisory_lock_connection] object_id: 48820, pg_backend_pid: 21898
STDERR: 
---- End output of "bash"  ----
Ran "bash"  returned 1
===
There was an error running gitlab-ctl reconfigure. Please check the output above for more
details.
===

dpkg: error processing package gitlab-ce (--install):
 installed gitlab-ce package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 gitlab-ce

next gitlab-ctl reconfigure

Caused by:
PG::CheckViolation: ERROR:  check constraint "check_860e317e6f" of relation "merge_requests_compliance_violations" is violated by some row
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/constraints_helpers.rb:122:in `block in validate_check_constraint'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/timeout_helpers.rb:31:in `disable_statement_timeout'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/constraints_helpers.rb:119:in `validate_check_constraint'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/constraints_helpers.rb:109:in `add_check_constraint'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/constraints_helpers.rb:218:in `add_not_null_constraint'
/opt/gitlab/embedded/service/gitlab-rails/db/post_migrate/20250129135703_add_not_null_check_constraint_mr_compliance_violations_target_project_id.rb:14:in `up'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:33:in `block in exec_migration'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/query_analyzer.rb:83:in `within'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:30:in `exec_migration'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migration_helpers/automatic_lock_writes_on_tables.rb:21:in `exec_migration'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/lock_retry_mixin.rb:54:in `ddl_transaction'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/runner_backoff/active_record_mixin.rb:21:in `execute_migration_in_transaction'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/pg_backend_pid.rb:28:in `block in with_advisory_lock_connection'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/pg_backend_pid.rb:25:in `with_advisory_lock_connection'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:145:in `configure_database'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:112:in `configure_pg_databases'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:99:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:25:in `load'
/opt/gitlab/embedded/bin/bundle:25:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Running db:migrate rake task
main: == [advisory_lock_connection] object_id: 48780, pg_backend_pid: 29686
main: == 20250129135703 AddNotNullCheckConstraintMrComplianceViolationsTargetProjectId: migrating 
main: -- current_schema(nil)
main:    -> 0.0004s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0003s
main: -- execute("ALTER TABLE merge_requests_compliance_violations VALIDATE CONSTRAINT check_860e317e6f;")
main: -- execute("RESET statement_timeout")
main:    -> 0.0003s
main: == [advisory_lock_connection] object_id: 48780, pg_backend_pid: 29686
STDERR: 
---- End output of "bash"  ----
Ran "bash"  returned 1

gitlabhq_production=> select * from merge_requests_compliance_violations where target_project_id is null;

 id | violating_user_id | merge_request_id | reason | severity_level | merged_at | target_project_id | title | target_branch 
----+-------------------+------------------+--------+----------------+-----------+-------------------+-------+---------------
  1 |               134 |             1286 |      2 |              3 |           |                   |       | 
  2 |               136 |             1283 |      2 |              3 |           |                   |       | 
  3 |                83 |             1290 |      2 |              3 |           |                   |       | 
  4 |                82 |             1291 |      0 |              3 |           |                   |       | 
  5 |                82 |             1291 |      1 |              3 |           |                   |       | 
  6 |                82 |             1291 |      2 |              3 |           |                   |       | 
  8 |               412 |             1296 |      2 |              3 |           |                   |       | 
  9 |               136 |             1297 |      2 |              3 |           |                   |       | 
 10 |               136 |             1298 |      2 |              3 |           |                   |       | 
 11 |               136 |             1287 |      2 |              3 |           |                   |       | 
 12 |               134 |             1299 |      2 |              3 |           |                   |       | 
 13 |               136 |             1300 |      2 |              3 |           |                   |       | 
 14 |               136 |             1301 |      2 |              3 |           |                   |       | 
 15 |               136 |             1293 |      2 |              3 |           |                   |       | 
 16 |               134 |             1303 |      2 |              3 |           |                   |       | 
 17 |               134 |             1304 |      2 |              3 |           |                   |       | 
 18 |               134 |             1308 |      2 |              3 |           |                   |       | 
 19 |               136 |             1305 |      2 |              3 |           |                   |       | 
 20 |               293 |             1311 |      2 |              3 |           |                   |       | 
 21 |               134 |             1314 |      2 |              3 |           |                   |       | 
 22 |               345 |             1313 |      2 |              3 |           |                   |       | 
 23 |               294 |             1310 |      2 |              3 |           |                   |       | 
 24 |               136 |             1315 |      2 |              3 |           |                   |       | 
 25 |               293 |             1320 |      2 |              3 |           |                   |       | 
 26 |               293 |             1321 |      2 |              3 |           |                   |       | 
 27 |               377 |             1324 |      2 |              3 |           |                   |       | 
 28 |               136 |             1322 |      2 |              3 |           |                   |       | 
 29 |               136 |             1319 |      2 |              3 |           |                   |       | 
 30 |               340 |             1325 |      2 |              3 |           |                   |       | 
 31 |               340 |             1326 |      2 |              3 |           |                   |       | 
 32 |               136 |             1327 |      2 |              3 |           |                   |       | 
 33 |               136 |             1328 |      2 |              3 |           |                   |       | 
 34 |               136 |             1316 |      2 |              3 |           |                   |       | 
 35 |               340 |             1332 |      2 |              3 |           |                   |       | 
 36 |               294 |             1329 |      2 |              3 |           |                   |       | 
 37 |               134 |             1333 |      2 |              3 |           |                   |       | 
 38 |               134 |             1323 |      2 |              3 |           |                   |       | 
 39 |               134 |             1282 |      2 |              3 |           |                   |       | 
 40 |               136 |             1334 |      2 |              3 |           |                   |       | 
 41 |               136 |             1336 |      2 |              3 |           |                   |       | 
 42 |               134 |             1337 |      2 |              3 |           |                   |       | 
 43 |               134 |             1341 |      2 |              3 |           |                   |       | 
 44 |               136 |             1307 |      2 |              3 |           |                   |       | 
 45 |               136 |             1343 |      2 |              3 |           |                   |       | 
 46 |               136 |             1339 |      2 |              3 |           |                   |       | 
 47 |               136 |             1345 |      2 |              3 |           |                   |       | 
 48 |               136 |             1346 |      2 |              3 |           |                   |       | 
 50 |               134 |             1351 |      2 |              3 |           |                   |       | 
 51 |               136 |             1348 |      2 |              3 |           |                   |       | 
 52 |               136 |             1349 |      2 |              3 |           |                   |       | 
 53 |               136 |             1347 |      2 |              3 |           |                   |       | 
 54 |               337 |             1354 |      2 |              3 |           |                   |       | 
 55 |               136 |             1355 |      2 |              3 |           |                   |       | 
 56 |               137 |             1356 |      2 |              3 |           |                   |       | 
 58 |               134 |             1360 |      2 |              3 |           |                   |       | 
(55 rows)

got the contents of the merge_requests_compliance_violations table. Is it possible to clear this table? How much can this affect the further work of GitLab?

Hello everyone
Here’s what I got
I was able to find target_project_id

SELECT target_project_id
FROM merge_requests
WHERE id = 1360;
 target_project_id 
-------------------
                71
(1 row)

If you do this with each merge_request_id, you can find all the values ​​of target_project_id.
Can I enter all target_project_id values ​​into the merge_requests_compliance_violations table myself, will it work?

Seeing as how the latest version is 17.10.0, it might be a good idea to try that (if it will work- unsure if you’d want to only go to 17.9.x for any reason.)

I’ve found that if you are upgrading to “unstable” releases that there are usually some DB migration issues. Ie. not at a defined “stop” according to that guide. Which even at this point 17.10.0 would not be a defined stop yet either.

I can’t tell if this- https://gitlab.com/gitlab-org/gitlab/-/merge_requests/110426/pipelines - is related or not as it appears it would’ve entered in a previous release rather than 17.9.x.

Did you retry the migration after it failed? Either via UI or via gitlab-rake db:migrate

What version of postgres are you running?