Error "source database "template1" is being accessed by other users" while activating Mattermost on Gitlab CE 9.0

I just upgraded from 8.17 to 9.0. After that I tried to activate Mattermost for the first time.

I edited /etc/gitlab/gitlab.rb, removed the comment from the line

mattermost_external_url 'http://mattermost.example.com'

and replaced "example.com" by our own custom intranet domain.

After that I ran sudo gitlab-ctl reconfigure.

There was a lot of output from chef, but the interesting part is probably this

Recipe: gitlab::mattermost
  * group[Mattermost user and group] action create (up to date)
  * user[Mattermost user and group] action create (up to date)
  * directory[/var/opt/gitlab/mattermost] action create (up to date)
  * directory[/var/log/gitlab/mattermost] action create (up to date)
  * directory[/var/opt/gitlab/mattermost/data] action create (up to date)
  * file[/var/log/gitlab/mattermost/mattermost.log] action create (skipped due to only_if)
  * execute[create gitlab_mattermost database user] action run (skipped due to not_if)
  * execute[create mattermost_production database] action run
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
    [execute] createdb: database creation failed: ERROR:  source database "template1" is being accessed by other users
              DETAIL:  There is 1 other session using the database.
^C/opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/omnibus-ctl-0.3.6/lib/omnibus-ctl.rb:208:in `system': Interrupt
	from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/omnibus-ctl-0.3.6/lib/omnibus-ctl.rb:208:in `run_command'
	from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/omnibus-ctl-0.3.6/lib/omnibus-ctl.rb:405:in `run_chef'
	from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/omnibus-ctl-0.3.6/lib/omnibus-ctl.rb:418:in `reconfigure'
	from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/omnibus-ctl-0.3.6/lib/omnibus-ctl.rb:575:in `run'
	from /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/omnibus-ctl-0.3.6/bin/omnibus-ctl:31:in `<top (required)>'
	from /opt/gitlab/embedded/bin/omnibus-ctl:22:in `load'
	from /opt/gitlab/embedded/bin/omnibus-ctl:22:in `<main>'
  
  Running handlers:
  Running handlers complete
  Chef Client failed. 3 resources updated in 01 minutes 24 seconds

It seems like the mattermost-database could not be created. I'm not sure how to fix it. Can anybody help?

Assignee Loading
Time tracking Loading