Skip to content

Add Rake task to check readiness for two connections

What does this MR do and why?

When we enable two databases on self-managed GitLab instance, we need to verify the setting of max_connections is high enough.

From the related issue:

This can be done by checking the number of current connections to the database, and comparing it with the max_connections. And recommend increasing it if needed.

This MR adds a small Rake task. It retrieves the current number of open connections and the setting of max_connections from the PostgreSQL server that is behind ApplicationRecord. It will output the retrieved numbers and recommends to increase the max_connections setting.

When we are already using two ActiveRecord connections:

$ bundle exec rake gitlab:db:decomposition:connection_status
GitLab database already running on two connections

When we are using less than 50% of max_connections:

$ rake gitlab:db:decomposition:connection_status
Currently using 8 connections out of 100 max_connections,
which is enough for running GitLab using two database connections.

When we are using more than 50% of max_connections:

$ rake gitlab:db:decomposition:connection_status
Currently using 8 connections out of 10 max_connections,
which may run out when you switch to two database connections.

Consider increasing PostgreSQL 'max_connections' setting.
Depending on the installation method, there are different ways to
increase that setting. Please consult the GitLab documentation.

Discussion

Increase max_connections

I do not add a pointer to documentation that tells the user how to increase the max_connections setting.

This is very dependent on the installation method. The default location for the config file is PostgreSQL data directory but it is also possible it is in /etc/ or /opt. It can also be in gitlab.rb or in helm chart.

How to set up and validate locally

Locally, using Gitlab Development Kit, the number of connections is probably around 9 and max_connections is set to 100.

  • Remove the ci configuration block from database.yml (so we are using 1 main connection)
  • Run the rake task rake gitlab:db:decomposition:connection_status. It should output one line with the current status.
  • Decrease max_connections to 15, $HOME/gitlab-development-kit/gitlab/postgresql/data/gitlab.conf
  • Run the rake task rake gitlab:db:decomposition:connection_status. It should output the current status and recommendation to increase max_connections

MR acceptance checklist

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

Related to #390204 (closed)

Edited by Rutger Wessels

Merge request reports

Loading