Skip to content

Stackgres standby cluster feature: Missing postgresql configuration files in the source server.

Summary

When creating a new SG Cluster replicating from an external source, postgresql.conf and pg_hba.conf files must be in the source data directory. Some Linux distributions (Debian family) are used to place these files outside the data directory by default.

Current Behaviour

Steps to reproduce

  • Review the connection between the StackGres k8s node and the origin server.
  • Enable Streaming Replication at the origin.
  • Create the authenticator user with the password and superuser role granted.
CREATE USER authenticator with password 'auth_pass' superuser;
  • Create the secret in your Kubernetes setup
kubectl -n your_namespace create secret generic postgresql-origin \
--from-literal=superuser-username=postgres \
--from-literal=superuser-password=postgresql \
--from-literal=replicator-username=postgres \
--from-literal=replicator-password=postgresql \
--from-literal=authenticator-username=authenticator \
--from-literal=authenticator-password=auth_pass

NOTE: Make sure that postgresql.conf and pg_hba.conf files exist in the source PostgreSQL data directory; otherwise, you will need to put these files beforehand. The postgresql.conf file can be empty but not the pg_hba.conf file. For example, use the following as template:

touch /var/lib/postgresql/15/main/postgresql.conf
echo '
# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

host all all 0.0.0.0/0 md5
' > /var/lib/postgresql/15/main/pg_hba.conf

Create the SGCluster

The replicateFrom spec must be added to the SGCluster and the users

replicateFrom:
    instance:
      external:
        host: the_origin_server
        port: 5432
    users:
      superuser:
        username:
          name: postgresql-origin
          key: superuser-username
        password:
          name: postgresql-origin
          key: superuser-password
      replication:
        username:
          name: postgresql-origin
          key: replicator-username
        password:
          name: postgresql-origin
          key: replicator-password
      authenticator:
        username:
          name: postgresql-origin
          key: authenticator-username
        password:
          name: postgresql-origin
          key: authenticator-password

Apply the SGCluster:

kubectl apply -f SGCluster.yaml

Expected Behaviour

It should be done automatically

Possible Solution

Add the pre-checks in SG

Environment

  • On-premises, cloud.

  • Any postgres server.

  • StackGres version:

Release Name: stackgres-operator
StackGres Version: 1.10.0

   _____ _             _     _____
  / ____| |           | |   / ____|
 | (___ | |_ __ _  ___| | _| |  __ _ __ ___  ___
  \___ \| __/ _` |/ __| |/ / | |_ | '__/ _ \/ __|
  ____) | || (_| | (__|   <| |__| | | |  __/\__ \
 |_____/ \__\__,_|\___|_|\_\\_____|_|  \___||___/
                                  by OnGres, Inc.

``

### Relevant logs and/or screenshots

/label ~Bug ~StackGres ~Triage