Skip to content

Database Cluster

This section guides you through the process of quickly setting up a PostgreSQL cluster with ECOX.

Note

Unless otherwise specified, the following operations should be performed on all database cluster nodes.

Hostname Resolution

This step is optional. To enable hostname resolution without DNS, add the node IPs and names to /etc/hosts as follows:

cat <<EOF | sudo tee -a /etc/hosts
10.9.5.5    dcs01
10.9.5.6    dcs02
10.9.5.9    dcs03
10.9.9.68   ecox01
10.9.9.69   ecox02
10.9.9.70   ecox03
EOF

Create User

Databases generally do not support running under privileged accounts (root), so a standard user account is necessary. The commands below create the postgres user and group to run ECOX and the database instance. If a postgres user already exists from a previous installation (e.g., via a package manager), you can utilize that account instead.

sudo groupadd postgres
sudo useradd -m -d /home/postgres --shell /bin/bash -g postgres postgres

Install PostgreSQL and ECOX

This guide assumes that PostgreSQL and ECOX are already installed. For installation steps, please consult the official PostgreSQL website and the ECOX installation guide.

Create Configuration File

The ECOX package provides a sample configuration file. Copy this template to create your initial configuration.

cp /opt/ecox-6alpha1/etc/ecox.conf.sample /opt/ecox-6alpha1/etc/ecox.conf

The example below shows a standard ECOX configuration. Ensure you modify node-specific values (such as node name, IP address) on each of the three servers.

/opt/ecox-6alpha1/etc/ecox.conf
[global]
namespace            = 'wwit'
cluster              = 'ecox'
nodename             = 'pg01'
sync_node_num        = 1
auto_promote_async   = true
enable_primary_slot  = true
pg_bindir            = '/usr/lib/postgresql/16/bin'
pg_datadir           = '/tmp/pgdata'
pg_conninfo          = 'ecox01:5430'
pg_super_username    = 'postgres'
pg_super_password    = 'postgres'
pg_rewind_username   = 'rewind'
pg_rewind_password   = 'Rew!nd12~'
pg_replica_username  = 'replica'
pg_replica_password  = 'Rep1!(a'

[log]
level        = 'info'
filename     = 'ecox-%d.log'
directory    = '/tmp/ecox'
rotation_age = '1d'

[vip]
enable_master_vip      = false
enable_readonly_vip    = false

[dcs]
type            = 'zookeeper'
hosts           = 'dcs01:2181,dcs02:2181,dcs03:2181'
session_timeout = '10s'
username        = 'zookeeper'
password        = 'Ec0x.pwd~'

[initdb]
data_checksums = true
encoding       = 'utf-8'

[postgres]
listen_addresses = '*'
port             = '5430'

[hba]
local   all             all                                     scram-sha-256
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             ::1/128                 scram-sha-256
local   replication     all                                     scram-sha-256
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             10.0.0.0/8              scram-sha-256
/opt/ecox-6alpha1/etc/ecox.conf
[global]
namespace            = 'wwit'
cluster              = 'ecox'
nodename             = 'pg02'
sync_node_num        = 1
auto_promote_async   = true
enable_primary_slot  = true
pg_bindir            = '/usr/lib/postgresql/16/bin'
pg_datadir           = '/tmp/pgdata'
pg_conninfo          = 'ecox02:5430'
pg_super_username    = 'postgres'
pg_super_password    = 'postgres'
pg_rewind_username   = 'rewind'
pg_rewind_password   = 'Rew!nd12~'
pg_replica_username  = 'replica'
pg_replica_password  = 'Rep1!(a'

[log]
level        = 'info'
filename     = 'ecox-%d.log'
directory    = '/tmp/ecox'
rotation_age = '1d'

[vip]
enable_master_vip      = false
enable_readonly_vip    = false

[dcs]
type            = 'zookeeper'
hosts           = 'dcs01:2181,dcs02:2181,dcs03:2181'
session_timeout = '10s'
username        = 'zookeeper'
password        = 'Ec0x.pwd~'

[initdb]
data_checksums = true
encoding       = 'utf-8'

[postgres]
listen_addresses = '*'
port             = '5430'

[hba]
local   all             all                                     scram-sha-256
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             ::1/128                 scram-sha-256
local   replication     all                                     scram-sha-256
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             10.0.0.0/8              scram-sha-256
/opt/ecox-6alpha1/etc/ecox.conf
[global]
namespace            = 'wwit'
cluster              = 'ecox'
nodename             = 'pg03'
sync_node_num        = 1
auto_promote_async   = true
enable_primary_slot  = true
pg_bindir            = '/usr/lib/postgresql/16/bin'
pg_datadir           = '/tmp/pgdata'
pg_conninfo          = 'ecox03:5430'
pg_super_username    = 'postgres'
pg_super_password    = 'postgres'
pg_rewind_username   = 'rewind'
pg_rewind_password   = 'Rew!nd12~'
pg_replica_username  = 'replica'
pg_replica_password  = 'Rep1!(a'

[log]
level        = 'info'
filename     = 'ecox-%d.log'
directory    = '/tmp/ecox'
rotation_age = '1d'

[vip]
enable_master_vip      = false
enable_readonly_vip    = false

[dcs]
type            = 'zookeeper'
hosts           = 'dcs01:2181,dcs02:2181,dcs03:2181'
session_timeout = '10s'
username        = 'zookeeper'
password        = 'Ec0x.pwd~'

[initdb]
data_checksums = true
encoding       = 'utf-8'

[postgres]
listen_addresses = '*'
port             = '5430'

[hba]
local   all             all                                     scram-sha-256
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             ::1/128                 scram-sha-256
local   replication     all                                     scram-sha-256
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             10.0.0.0/8              scram-sha-256

Note

  • If hostname resolution is not configured, you must use IP addresses for dcs.hosts and global.pg_conninfo.
  • If VIP is enabled, see VIP Parameter Configuration.

Setup Firewall

If the system firewall is enabled, you must configure it to allow PostgreSQL traffic.

sudo firewall-cmd --zone=public --add-port=5430/tcp --permanent
sudo firewall-cmd --reload
sudo ufw allow 5430/tcp
sudo ufw allow 5430/tcp

Testing

Info

Ensure the ECOX license is imported; otherwise, the service will not start.

Once the configuration is complete, ECOX is ready to manage the PostgreSQL cluster. The following are the basic commands:

su - postgres
export ECOX_CONFIG=/opt/ecox-6alpha1/etc/ecox.conf
export ECOX_LICENSE=/opt/ecox-6alpha1/LICENSE
ecox start
  • Automatic Initialization:

    If started without an existing database instance, ECOX will automatically initialize the database.

  • Foreground Mode:

    This command runs the service in the foreground. Press Ctrl+C to stop it.

Register Service

To simplify management, register ECOX as a system service using the following configuration:

sudo cp /opt/ecox-6alpha1/etc/ecox.service.sample /etc/systemd/system/ecox.service

Reload the system daemon configuration.

sudo systemctl daemon-reload