Still need to install postgresql when installing Gitlab from source even if using a remote postgresql?

Hello:

I’m trying to install Gitlab from source following the official installation document.

When I was installing the database, I decided to install the database on a different host to separate the database from Gitlab to facilitate sharing with my other services. Therefore, I run the database installation command on another host.

Suppose I install Gitlab on host A(ip: 172.16.142.160) and PostgreSQL on host B(ip: 172.16.142.161). And the postgre service on host B is running:

root@postgresql:~# service postgresql status
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Thu 2021-12-09 15:57:52 CST; 6 days ago
    Process: 44138 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 44138 (code=exited, status=0/SUCCESS)

Dec 09 15:57:52 mysql systemd[1]: Starting PostgreSQL RDBMS...
Dec 09 15:57:52 mysql systemd[1]: Finished PostgreSQL RDBMS.

I followed the document to configure the db settings (only adapted the production settings):

#
# PRODUCTION
#
production:
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_production
    username: git
    password: "my passwd"
    host: "172.16.142.161"
    # load_balancing:
    #   hosts:
    #     - host1.example.com
    #     - host2.example.com
    #   discover:
    #     nameserver: 1.2.3.4
    #     port: 8600
    #     record: secondary.postgresql.service.consul
    #     interval: 300

#
# Development specific
#
development:
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_development
    username: postgres
    password: "secure password"
    host: localhost
    variables:
      statement_timeout: 15s

#
# Staging specific
#
staging:
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_staging
    username: git
    password: "secure password"
    host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_test
    username: postgres
    password:
    host: localhost
    prepared_statements: false
    variables:
      statement_timeout: 15s

But when I tried to initialize the database as the document said, the command failed:

root@demo:/home/git/gitlab# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production force=yes
Database 'gitlabhq_production' does not exist
FATAL:  no pg_hba.conf entry for host "172.16.142.160", user "git", database "postgres", SSL on
FATAL:  no pg_hba.conf entry for host "172.16.142.160", user "git", database "postgres", SSL off
Couldn't create 'gitlabhq_production' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  no pg_hba.conf entry for host "172.16.142.160", user "git", database "postgres", SSL on
FATAL:  no pg_hba.conf entry for host "172.16.142.160", user "git", database "postgres", SSL off
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/home/git/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:111:in `block in read_write'
/home/git/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:172:in `retry_with_backoff'
/home/git/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:110:in `read_write'
/home/git/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:125:in `write_using_load_balancer'
/home/git/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:95:in `method_missing'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:133:in `create'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:193:in `block in create_current'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:506:in `block (2 levels) in each_current_configuration'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:503:in `each'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:503:in `block in each_current_configuration'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:502:in `each'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:502:in `each_current_configuration'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:193:in `create_current'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>'
/home/git/gitlab/lib/tasks/gitlab/setup.rake:35:in `setup_db'
/home/git/gitlab/lib/tasks/gitlab/setup.rake:7:in `block (2 levels) in <top (required)>'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'

Caused by:
PG::ConnectionBad: FATAL:  no pg_hba.conf entry for host "172.16.142.160", user "git", database "postgres", SSL on
FATAL:  no pg_hba.conf entry for host "172.16.142.160", user "git", database "postgres", SSL off
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/home/git/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:111:in `block in read_write'
/home/git/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:172:in `retry_with_backoff'
/home/git/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:110:in `read_write'
/home/git/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:125:in `write_using_load_balancer'
/home/git/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:95:in `method_missing'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:133:in `create'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:193:in `block in create_current'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:506:in `block (2 levels) in each_current_configuration'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:503:in `each'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:503:in `block in each_current_configuration'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:502:in `each'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:502:in `each_current_configuration'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/tasks/database_tasks.rb:193:in `create_current'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>'
/home/git/gitlab/lib/tasks/gitlab/setup.rake:35:in `setup_db'
/home/git/gitlab/lib/tasks/gitlab/setup.rake:7:in `block (2 levels) in <top (required)>'
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => db:reset => db:setup => db:create
(See full trace by running task with --trace)

The error is: ActiveRecord::NoDatabaseError: FATAL: no pg_hba.conf entry for host "172.16.142.160", user "git", database "postgres"

I don’t know what I did wrong :sob:

It seems like that the command sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production force=yes is looking for file pg_hba.conf on host A(ip: 172.16.142.160). But I don’t actually have PostgreSQL installed on host A.

Do I still need to install PostgreSQL on host A even if I’m using a remote PostgreSQL which is installed on host B?

Or do I need to remove any Settings in database.yml other than production Settings?

Really appreciate!!

You need to add a line to pg_hba.conf on the server running postgresql so that server_a where gitlab is installed can connect to it. Something like this to start with:

host	all		all		172.16.142.160/32		md5

then restart postgresql and try again. You may need to alter that line to secure it even further, but you would want to check postgres documentation for that. It’s sufficient, but maybe not completely ideal.

1 Like

I added a new line host all all 172.16.142.0/24 md5.

Thank you so much! :blush:

1 Like