From 853919b8da1936bfab6918d29175d551124653a3 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Thu, 14 Apr 2022 11:18:11 +0200 Subject: [PATCH 1/2] Use gitlab PG user Closes https://gitlab.com/gitlab-org/database-team/gitlab-com-database-testing/-/issues/60 --- docker/gitlab/prepare.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docker/gitlab/prepare.sh b/docker/gitlab/prepare.sh index 019d3b3e..58e8d4bd 100755 --- a/docker/gitlab/prepare.sh +++ b/docker/gitlab/prepare.sh @@ -12,7 +12,7 @@ test: &test adapter: postgresql encoding: unicode database: gitlabhq_dblab - username: ${DBLAB_USER} + username: gitlab password: ${DBLAB_PASSWORD} host: postgres-main prepared_statements: false @@ -22,7 +22,7 @@ test: &test adapter: postgresql encoding: unicode database: gitlabhq_dblab - username: ${DBLAB_USER} + username: gitlab password: ${DBLAB_PASSWORD} host: postgres-ci prepared_statements: false @@ -38,7 +38,7 @@ test: &test adapter: postgresql encoding: unicode database: gitlabhq_dblab - username: ${DBLAB_USER} + username: gitlab password: ${DBLAB_PASSWORD} host: postgres prepared_statements: false @@ -85,5 +85,14 @@ for db_host in $(echo "$ALL_DB_HOSTS" | tr ',' '\n'); do else echo "Unable to connect to database lab psql for optional configuration of ${db_host}" fi + + # Reset `gitlab` user password - this is the PG user we're going to use later to execute migrations + # We re-use $DBLAB_PASSWORD variable here + if timeout 60s bash -c "until pg_isready --quiet -h ${db_host} -U ${DBLAB_USER} --dbname=gitlabhq_dblab; do sleep 1; done"; then + echo "ALTER USER gitlab PASSWORD '${DBLAB_PASSWORD}'" | PGPASSWORD="${DBLAB_PASSWORD}" psql -h "${db_host}" -U "${DBLAB_USER}" gitlabhq_dblab + else + echo "Unable to connect to database lab psql for mandatory user configuration on ${db_host}" + exit 1 + fi done -- GitLab From ceb0ce4c00252a4a4a08b2d079028fd111d03f55 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Fri, 22 Apr 2022 13:25:14 +0200 Subject: [PATCH 2/2] Grant resetting pg_stat_statements to gitlab --- docker/gitlab/prepare.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/gitlab/prepare.sh b/docker/gitlab/prepare.sh index 58e8d4bd..b86420bf 100755 --- a/docker/gitlab/prepare.sh +++ b/docker/gitlab/prepare.sh @@ -89,7 +89,7 @@ for db_host in $(echo "$ALL_DB_HOSTS" | tr ',' '\n'); do # Reset `gitlab` user password - this is the PG user we're going to use later to execute migrations # We re-use $DBLAB_PASSWORD variable here if timeout 60s bash -c "until pg_isready --quiet -h ${db_host} -U ${DBLAB_USER} --dbname=gitlabhq_dblab; do sleep 1; done"; then - echo "ALTER USER gitlab PASSWORD '${DBLAB_PASSWORD}'" | PGPASSWORD="${DBLAB_PASSWORD}" psql -h "${db_host}" -U "${DBLAB_USER}" gitlabhq_dblab + echo "ALTER USER gitlab PASSWORD '${DBLAB_PASSWORD}'; GRANT EXECUTE ON FUNCTION pg_stat_statements_reset() to gitlab;" | PGPASSWORD="${DBLAB_PASSWORD}" psql -h "${db_host}" -U "${DBLAB_USER}" gitlabhq_dblab else echo "Unable to connect to database lab psql for mandatory user configuration on ${db_host}" exit 1 -- GitLab