Skip to content

Fix gitlab:setup when connections are shared

Patrick Bair requested to merge pb-fix-setup-with-shared-connections into master

What does this MR do and why?

This task was originally changed to support multiple databases as part of #352770 (closed)

Fix the gitlab:setup rake task when multiple databases are configured to share the same primary connection. The task currently fails with:

ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.

because it terminates all the connections to main, and then tries to terminate all connections to ci, but the connection to ci has already been terminated in the first step, since ci points at main.

Instead, if ci isn't setup to use database_tasks, we should skip over it.

How to set up and validate locally

Since this task will delete your development db, you can test it against a separate database.

  1. Create development and test databases:
    create database foobar_development;
    create database foobar_test;
  2. Update your database.yml to point at these (other usual parameters like host, user, password, etc. omitted):
    development:
      main:
        database: foobar_development
      ci:
        database: foobar_development
        database_tasks: false
    
    test:
      main:
        database: foobar_test
      ci:
        database: foobar_test
        database_tasks: false
  3. Run the rake task rails gitlab:setup. On master, this will fail with the error:
    ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
    But on this branch, it should properly setup the database.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Patrick Bair

Merge request reports