database.md 3.77 KB
Newer Older
Drew Blessing's avatar
Drew Blessing committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Configuring a Database for GitLab HA

You can choose to install and manage a database server (PostgreSQL/MySQL)
yourself, or you can use GitLab Omnibus packages to help. GitLab recommends
PostgreSQL. This is the database that will be installed if you use the
Omnibus package to manage your database.

## Configure your own database server

If you're hosting GitLab on a cloud provider, you can optionally use a
managed service for PostgreSQL. For example, AWS offers a managed Relational
Database Service (RDS) that runs PostgreSQL.

If you use a cloud-managed service, or provide your own PostgreSQL:

16 17
1. Setup PostgreSQL according to the
   [database requirements document](../../install/requirements.md#database).
Drew Blessing's avatar
Drew Blessing committed
18 19 20
1. Set up a `gitlab` username with a password of your choice. The `gitlab` user
   needs privileges to create the `gitlabhq_production` database.
1. Configure the GitLab application servers with the appropriate details.
21
   This step is covered in [Configuring GitLab for HA](gitlab.md).
Drew Blessing's avatar
Drew Blessing committed
22 23 24 25 26 27 28 29

## Configure using Omnibus

1. Download/install GitLab Omnibus using **steps 1 and 2** from
   [GitLab downloads](https://about.gitlab.com/downloads). Do not complete other
   steps on the download page.
1. Create/edit `/etc/gitlab/gitlab.rb` and use the following configuration.
   Be sure to change the `external_url` to match your eventual GitLab front-end
Lee Matos's avatar
Lee Matos committed
30
   URL. If there is a directive listed below that you do not see in the configuration, be sure to add it.
Drew Blessing's avatar
Drew Blessing committed
31 32 33 34 35 36 37 38 39 40 41

    ```ruby
    external_url 'https://gitlab.example.com'

    # Disable all components except PostgreSQL
    postgresql['enable'] = true
    bootstrap['enable'] = false
    nginx['enable'] = false
    unicorn['enable'] = false
    sidekiq['enable'] = false
    redis['enable'] = false
Lee Matos's avatar
Lee Matos committed
42 43
    prometheus['enable'] = false
    gitaly['enable'] = false
Drew Blessing's avatar
Drew Blessing committed
44 45 46 47
    gitlab_workhorse['enable'] = false
    mailroom['enable'] = false

    # PostgreSQL configuration
48
    gitlab_rails['db_password'] = 'DB password'
Drew Blessing's avatar
Drew Blessing committed
49 50
    postgresql['md5_auth_cidr_addresses'] = ['0.0.0.0/0']
    postgresql['listen_address'] = '0.0.0.0'
51 52 53

    # Disable automatic database migrations
    gitlab_rails['auto_migrate'] = false
Drew Blessing's avatar
Drew Blessing committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    ```

1. Run `sudo gitlab-ctl reconfigure` to install and configure PostgreSQL.

    > **Note**: This `reconfigure` step will result in some errors.
      That's OK - don't be alarmed.

1. Open a database prompt:

    ```
    su - gitlab-psql
    /bin/bash
    psql -h /var/opt/gitlab/postgresql -d template1

    # Output:

    psql (9.2.15)
    Type "help" for help.

    template1=#
    ```

1. Run the following command at the database prompt and you will be asked to
   enter the new password for the PostgreSQL superuser.

    ```
    \password

    # Output:

    Enter new password:
    Enter it again:
    ```

1. Similarly, set the password for the `gitlab` database user. Use the same
   password that you specified in the `/etc/gitlab/gitlab.rb` file for
90
   `gitlab_rails['db_password']`.
Drew Blessing's avatar
Drew Blessing committed
91 92 93 94 95 96 97 98 99

    ```
    \password gitlab

    # Output:

    Enter new password:
    Enter it again:
    ```
100 101 102
1. Exit from editing `template1` prompt by typing `\q` and Enter.
1. Enable the `pg_trgm` extension within the `gitlabhq_production` database:
    
Drew Blessing's avatar
Drew Blessing committed
103
    ```
104 105
    gitlab-psql -d gitlabhq_production
    
Drew Blessing's avatar
Drew Blessing committed
106 107 108 109 110 111 112 113 114
    CREATE EXTENSION pg_trgm;

    # Output:

    CREATE EXTENSION
    ```
1. Exit the database prompt by typing `\q` and Enter.
1. Exit the `gitlab-psql` user by running `exit` twice.
1. Run `sudo gitlab-ctl reconfigure` a final time.
115 116
1. Configure the GitLab application servers with the appropriate details.
   This step is covered in [Configuring GitLab for HA](gitlab.md).
Drew Blessing's avatar
Drew Blessing committed
117 118 119 120 121 122 123 124 125

---

Read more on high-availability configuration:

1. [Configure Redis](redis.md)
1. [Configure NFS](nfs.md)
1. [Configure the GitLab application servers](gitlab.md)
1. [Configure the load balancers](load_balancer.md)