Skip to content

gitlab-rails dbconsole is broken on GItLab 14.2.3

Summary

While troubleshooting a different issue with a customer, we encountered an error when running gitlab-rails dbconsole:

`db_config': 'primary' database is not configured for 'production'. Available configuration: #<ActiveRecord::DatabaseConfigurations:0x00007f7c10dc7cb8 @configurations=[#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007f7c10dc7b28 @env_name="production", @name="main", @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :collation=>nil, :database=>"gitlabhq_production", :username=>"gitlab", :password=>nil, :host=>"/var/opt/gitlab/postgresql", :port=>5432, :socket=>nil, :sslmode=>nil, :sslcompression=>0, :sslrootcert=>nil, :sslca=>nil, :load_balancing=>{"hosts"=>[]}, :prepared_statements=>false, :statement_limit=>1000, :connect_timeout=>nil, :keepalives=>nil, :keepalives_idle=>nil, :keepalives_interval=>nil, :keepalives_count=>nil, :tcp_user_timeout=>nil, :application_name=>nil, :variables=>{"statement_timeout"=>nil}}>]> (ActiveRecord::AdapterNotSpecified)

However, GitLab is still working properly. I managed to reproduced this on a new install of GitLab 14.2.3.

Steps to reproduce

  1. Install GitLab 14.2.3
  2. Run gitlab-rails dbconsole

Example Project

N/A

What is the current bug behavior?

gitlab-rails dbconsole fails with an error where it thinks that

What is the expected correct behavior?

gitlab-rails dbconsole should drop you in a Postgres session.

Relevant logs and/or screenshots

# gitlab-rails dbconsole
Traceback (most recent call last):
        11: from bin/rails:4:in `<main>'
        10: from bin/rails:4:in `require'
         9: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<top (required)>'
         8: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/command.rb:50:in `invoke'
         7: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/command/base.rb:69:in `perform'
         6: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
         5: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
         4: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
         3: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/dbconsole/dbconsole_command.rb:181:in `perform'
         2: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/dbconsole/dbconsole_command.rb:10:in `start'
         1: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/dbconsole/dbconsole_command.rb:19:in `start'
/opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/dbconsole/dbconsole_command.rb:108:in `db_config': 'primary' database is not configured for 'production'. Available configuration: #<ActiveRecord::DatabaseConfigurations:0x00007f7c10dc7cb8 @configurations=[#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007f7c10dc7b28 @env_name="production", @name="main", @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :collation=>nil, :database=>"gitlabhq_production", :username=>"gitlab", :password=>nil, :host=>"/var/opt/gitlab/postgresql", :port=>5432, :socket=>nil, :sslmode=>nil, :sslcompression=>0, :sslrootcert=>nil, :sslca=>nil, :load_balancing=>{"hosts"=>[]}, :prepared_statements=>false, :statement_limit=>1000, :connect_timeout=>nil, :keepalives=>nil, :keepalives_idle=>nil, :keepalives_interval=>nil, :keepalives_count=>nil, :tcp_user_timeout=>nil, :application_name=>nil, :variables=>{"statement_timeout"=>nil}}>]> (ActiveRecord::AdapterNotSpecified)

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

System information
System:		Ubuntu 20.04
Proxy:		no
Current User:	git
Using RVM:	no
Ruby Version:	2.7.2p137
Gem Version:	3.1.4
Bundler Version:2.1.4
Rake Version:	13.0.6
Redis Version:	6.0.14
Git Version:	2.32.0
Sidekiq Version:5.2.9
Go Version:	unknown

GitLab information
Version:	14.2.3-ee
Revision:	b5eea856eca
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	PostgreSQL
DB Version:	12.7
URL:		http://192.168.100.5
HTTP Clone URL:	http://192.168.100.5/some-group/some-project.git
SSH Clone URL:	git@192.168.100.5:some-group/some-project.git
Elasticsearch:	no
Geo:		no
Using LDAP:	no
Using Omniauth:	yes
Omniauth Providers:

GitLab Shell
Version:	13.19.1
Repository storage paths:
- default: 	/var/opt/gitlab/git-data/repositories
GitLab Shell path:		/opt/gitlab/embedded/service/gitlab-shell
Git:		/opt/gitlab/embedded/bin/git

Results of GitLab application Check

Expand for output related to the GitLab application check

Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 13.19.1 ? ... OK (13.19.1) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/1

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 2/1 ... yes 1/4 ... yes 1/5 ... yes 1/6 ... yes 1/7 ... yes 1/8 ... yes 1/9 ... yes 1/10 ... yes 1/11 ... yes 1/12 ... yes 1/13 ... yes 1/14 ... yes Redis version >= 5.0.0? ... yes Ruby version >= 2.7.2 ? ... yes (2.7.2) Git version >= 2.31.0 ? ... yes (2.32.0) Git user has default SSH configuration? ... yes Active users: ... 3 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x (6.4 - 6.x deprecated to be removed in 13.8)? ... skipped (elasticsearch is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

Possible fixes

It seems that it thinks that this is a Geo install, and then it tries to access the Primary database.