Database Lab access using the pgai Ruby gem

caution
The pgai gem has not yet been updated to use the new database lab instances so you will only be able to access gitlab-production-main and gitlab-production-ci using this tool.

@mbobin created the pgai Ruby Gem that greatly simplifies access to a database clone, with support for:

If you have AllFeaturesUser psql access, you can follow the steps below to configure the pgai Gem:

  1. To get started, you need to gather some values from the Postgres.ai instances page:

    1. Go to the instance that you want to configure and the on right side of the screen.
    2. Under Connection, select Connect. The menu might be collapsed.

      A dialog with everything that’s needed for configuration appears, using this format:

      dblab init --url "http://127.0.0.1:1234" --token TOKEN --environment-id <environment-id>
      
      ssh -NTML 1234:localhost:<environment-port> <postgresai-user>@<postgresai-proxy> -i ~/.ssh/id_rsa
      
  2. Add the following snippet to your SSH configuration file at ~/.ssh/config, replacing the variable values:

    Host pgai-proxy
      HostName <postgresai-proxy>
      User <postgresai-user>
      IdentityFile ~/.ssh/id_ed25519
    
  3. Run the following command so you can accept the server key fingerprint:

    ssh pgai-proxy
    
  4. Run the following commands:

    gem install pgai
    
    # Grab an access token: https://console.postgres.ai/gitlab/tokens
    # GITLAB_USER is your GitLab handle
    pgai config --dbname=gitlabhq_dblab --prefix=$GITLAB_USER --proxy=pgai-proxy
    
    # Grab the respective port values from https://console.postgres.ai/gitlab/instances
    # for the instances you'll be using (in this case, for the `main` database instance)
    pgai env add --alias main --id <environment-id> --port <environment-port>
    
  5. Once this one-time configuration is done, you can use pgai connect to connect to a particular database. For instance, to connect to the main database:

    pgai connect main
    
  6. Once done with the clone, you can destroy it:

    pgai destroy main