Internal users at GitLab have access to the Database Lab Engine (DLE) and postgres.ai for testing performance of database queries on replicated production data. Unlike a typical read-only production replica, in the DLE you can also create, update, and delete rows. You can also test the performance of schema changes, like additional indexes or columns, in an isolated copy of production data.
Database Lab quick startgitlab-production-main
.gitlab-production-ci
.gitlab-production-registry
.explain <Query Text>
in the chat box to get a plan.Access to the DLE is helpful for:
To access the DLE’s services, you can:
EXPLAIN
(analyze, buffers) plans for queries executed there.psql
access to DLE instead of a production replica. Available to authorized users only. To request psql
access, file an access request.For more assistance, use the #database
Slack channel.
If you need only temporary access to a production replica, instead of a Database Lab clone, follow the runbook procedure for connecting to the database console with Teleport. This procedure is similar to Rails console access with Teleport.
Query testingYou can access Database Lab’s query analysis features either:
Query plans are an essential part of the database review process. These plans enable us to decide quickly if a given query can be performant on GitLab.com. Running the explain
command generates an explain
plan and a link to the Postgres.ai console with more query analysis. For example, running EXPLAIN SELECT * FROM application_settings
does the following:
explain (analyze, buffers) select * from application_settings;
against a database clone.Sometimes when testing queries, a contributor may realize that the query needs an index or other schema change to make added queries more performant. To test the query, run the exec
command. For example, running this command:
exec CREATE INDEX on application_settings USING btree (restricted_visibility_levels)
creates the specified index on the table. You can test queries leveraging the new index. exec
does not return any results, only the time required to execute the query.
After many changes, such as after a destructive query or an ineffective index, you must start over. To reset your designated clone, run reset
.
Use Database Lab to check the status of an index with the meta-command \d <index_name>
.
Caveats:
main
and ci
databases, so be sure to use the instance that matches the table’s gitlab_schema
. For example, if the index is added to ci_builds
, use gitlab-production-ci
.For example: \d index_design_management_designs_on_project_id
produces:
Index "public.index_design_management_designs_on_project_id"
Column | Type | Key? | Definition
------------+---------+------+------------
project_id | integer | yes | project_id
btree, for table "public.design_management_designs"
In the case of an invalid index, the output ends with invalid
, like:
Index "public.index_design_management_designs_on_project_id"
Column | Type | Key? | Definition
------------+---------+------+------------
project_id | integer | yes | project_id
btree, for table "public.design_management_designs", invalid
If the index doesn’t exist, JoeBot throws an error like:
ERROR: psql error: psql:/tmp/psql-query-932227396:1: error: Did not find any relation named "no_index".
Migration testing
For information on testing migrations, review our database migration testing documentation.
Access the console withpsql
You must have AllFeaturesUser
psql
access to access the console with psql
.
To access the database lab instances, you must:
AllFeaturesUser
role in Postgres.aidb-lab
role in chef-repo
db-lab
role.ssh
as follows:Host lb-bastion.db-lab.gitlab.com
# Typically, the username is `name` in `name@gitlab.com`
# or your GitLab's username.
# Check with the access provisioner if it is not working.
# If not provided, defaults to your system username.
User YOUR_USERNAME_HERE
# Path to your SSH key. Adjust or remove if using a different key or SSH agent.
IdentityFile ~/.ssh/id_ed25519
Host *.gitlab-db-lab.internal
User YOUR_USERNAME_HERE # Same as above.
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519 # Same as above.
ProxyCommand ssh lb-bastion.db-lab.gitlab.com -W %h:%p
Manual access through the Postgres.ai instances page
Team members with psql
access, can gain direct access to a clone via psql
. Access to psql
enables you to see data, not just metadata.
To connect to a clone using psql
:
yourname-testing-gitlabissue
.psql
to your clone.-N
flag, meaning no shell will be started, so you should not expect any output if it runs successfully.LogLevel DEBUG3
to your ~/.ssh/config
to output detailed debugging information.psql
connection string. Use the password provided at setup and set the dbname
to gitlabhq_dblab
(or check what databases are available by using psql -l
with the same query string but dbname=postgres
).After you connect, use clone like you would any psql
console in production, but with the added benefit and safety of an isolated writeable environment.
pgai
Ruby gem
For instructions on using the pgai
Ruby gem, see: Database Lab access using the pgai Ruby gem.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4