e7lT2P
e7lT2P

Reputation: 1931

Failed to run patroni

I have follow this tutorial: https://linode.com/docs/databases/postgresql/create-a-highly-available-postgresql-cluster-using-patroni-and-haproxy/ , in order to set up Highly Available PostgreSQL Cluster Using Patroni and HAProxy.

But when I try to start patroni I get this error:

ubuntu@sudo patroni /etc/patroni.yml 
2018-05-31 09:49:37,159 INFO: Failed to import patroni.dcs.consul
2018-05-31 09:49:37,166 INFO: Selected new etcd server http://privateetcdIP:2379
2018-05-31 09:49:37,173 INFO: Lock owner: None; I am postgresqlm
2018-05-31 09:49:37,175 INFO: trying to bootstrap a new cluster
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
2018-05-31 09:49:37,185 INFO: removing initialize key after failed attempt to bootstrap the cluster
2018-05-31 09:49:37,673 INFO: Lock owner: None; I am postgresqlm
Traceback (most recent call last):
  File "/usr/local/bin/patroni", line 9, in <module>
    load_entry_point('patroni==1.4.4', 'console_scripts', 'patroni')()
  File "/usr/local/lib/python2.7/dist-packages/patroni/__init__.py", line 176, in main
    return patroni_main()
  File "/usr/local/lib/python2.7/dist-packages/patroni/__init__.py", line 145, in patroni_main
    patroni.run()
  File "/usr/local/lib/python2.7/dist-packages/patroni/__init__.py", line 114, in run
    logger.info(self.ha.run_cycle())
  File "/usr/local/lib/python2.7/dist-packages/patroni/ha.py", line 1164, in run_cycle
    info = self._run_cycle()
  File "/usr/local/lib/python2.7/dist-packages/patroni/ha.py", line 1077, in _run_cycle
    return self.post_bootstrap()
  File "/usr/local/lib/python2.7/dist-packages/patroni/ha.py", line 976, in post_bootstrap
    self.cancel_initialization()
  File "/usr/local/lib/python2.7/dist-packages/patroni/ha.py", line 971, in cancel_initialization
    raise PatroniException('Failed to bootstrap cluster')

The configuration of /etc/patroni.yml is:

scope: postgres
namespace: /db/
name: postgresqlm

restapi:
    listen: privateIPoffirstnode:8008
    connect_address: privateIPoffirstnode:8008

etcd:
    host: privateIPofetcd:2379

bootstrap:
    dcs:
        ttl: 30
        loop_wait: 10
        retry_timeout: 10
        maximum_lag_on_failover: 1048576
        postgresql:
            use_pg_rewind: true
            max_connections: 100

    initdb:
    - encoding: UTF8
    - data-checksums

    pg_hba:
    - host replication replicator 127.0.0.1/32 md5
    - host replication replicator privateIPoffirstnode/0 md5
    - host replication replicator privateIPofsecondnode/0 md5
    - host replication replicator privateIPofthirdnode/0 md5
    - host all all 0.0.0.0/0 md5

    users:
        admin:
            password: admin
            options:
                - createrole
                - createdb

postgresql:
    listen: privateIPoffirstnode:5432
    connect_address: privateIPoffirstnode:5432
    data_dir: /data/patroni
    pgpass: /tmp/pgpass
    bin_dir: /usr/lib/postgresql/9.5/bin
    authentication:
        replication:
            username: replicator
            password: rep-pass
        superuser:
            username: postgres
            password: '12345'
    parameters:
        unix_socket_directories: '.'

tags:
    nofailover: false
    noloadbalance: false
    clonefrom: false
    nosync: false

The configuration of /etc/systemd/system/patroni.service is:

[Unit]
Description=Runners to orchestrate a high-availability PostgreSQL
After=syslog.target network.target

[Service]
Type=simple

User=postgres
Group=postgres

ExecStart=/usr/local/bin/patroni /etc/patroni.yml

KillMode=process

TimeoutSec=30

Restart=no

[Install]
WantedBy=multi-user.targ

etcd congiguration:

ETCD_LISTEN_PEER_URLS="http://privateIPofetcd:2380"

ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://privateIPofetcd:2379"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://privateIPofetcd:2380"

ETCD_INITIAL_CLUSTER="etcd0=http://privateIPofetcd:2380,"

ETCD_ADVERTISE_CLIENT_URLS="http://privateIPofetcd:2379"

ETCD_INITIAL_CLUSTER_TOKEN="cluster1"

ETCD_INITIAL_CLUSTER_STATE="new"

Of course, I have the real ips in privateIPoffirstnode, privateIPofsecondnode etc.

So, does anyone know what this error means?

Upvotes: 1

Views: 9727

Answers (2)

Vikram Aruchamy
Vikram Aruchamy

Reputation: 182

Follow this guide to configure highly available Postgresql cluster.

Its fully tested and working.

Upvotes: 1

Laurenz Albe
Laurenz Albe

Reputation: 247625

I think the answer is obvious. If you start patroni with sudo, it will run as root, and that is exactly the error message you get.

Why don't you start it via systemctl? Your /etc/systemd/system/patroni.service has correctly configured a User that is not root.

Upvotes: 1

Related Questions