Geo: Skipping sudo -i when starting replication results in postgresql data directory to inherit the root owner instead gitlab-psql

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

When logged in as root, you skip sudo -i when [starting database replication on a secondary site](https://docs.gitlab.com/ee/administration/geo/setup/two_single_node_sites.html#replicate-the-database). This results in the PostgreSQL data directory inheriting the root owner instead of gitlab-psql leading to a permission error.

Steps to reproduce

  1. Login as root to a secondary site. Not using sudo -i
  2. Follow [instructions for setting up secondary Geo site](https://docs.gitlab.com/ee/administration/geo/setup/two_single_node_sites.html#configure-the-secondary-server)
  3. Attempt to [replicate database on a secondary site](https://docs.gitlab.com/ee/administration/geo/setup/two_single_node_sites.html#replicate-the-database)

What is the current bug behavior?

The PostgreSQL data directory is owned by root instead of gitlab-psql resulting in the following error when replication is initiated

postgres: could not access the server configuration file "/var/opt/gitlab/postgresql/data/postgresql.conf": Permission denied

What is the expected correct behavior?

The data directory is owned by `gitlab-psql` and database replication completes successfully.

Relevant logs and/or screenshots

Possible workaround

sudo -i before initiating database replication

Edited by 🤖 GitLab Bot 🤖