1

I am trying to setup HA solution for PostgreSQL. For that, I am running pgpool service.

In that service, it calls a script whenever my primary node fails by calling it like this:

/etc/pgpool-II-94/failover.sh %d %H'

where %d is my node id and %H is the hostname for the new server. Think of them simply as two parameters.

My Failover script is below:

#!/bin/sh
failed_node=$1
new_master=$2
(
date
echo "Failed node: $failed_node"
set -x
/usr/bin/ssh -T -l postgres $new_master "/usr/pgsql-9.4/bin/repmgr -f /var/lib/pgsql/repmgr/repmgr.conf standby promote 2>/dev/null 1>/dev/null <&-"
exit 0;
) 2>&1 | tee -a /tmp/pgpool_failover.log

The problem I am facing here is that when this script gets executed, it gets executed as root and hence I cannot authenticate it for postgres user for other server.

How to run my pgpool service as postgres user itself so that my authentication get passed?

Right now I am using:

systemctl start pgpool-II-94

from postgres to postgres in all the servers I have setup passwordless ssh so that would not be an issue.

For example: when I run through postgres user

-bash-4.2$ /usr/bin/ssh -T -l postgres lbdevsecondary 'echo $HOSTNAME'
lbdevsecondary

But when I run through root user, it asks for password

/usr/bin/ssh -T -l postgres lbdevsecondary 'echo $HOSTNAME'
postgres@lbdevsecondary's password:
lbdevsecondary

Or please tell me a way to rewrite the above statement in the way that I first logged in as postgres user and then run the commands from my scripts.

I am using CentOS 7 and fairly new to Linux.

  • 1
    Add root's ssh public key to postgreql's .ssh/authorized_keys – Jasen Dec 25 '16 at 11:21
0
  1. Su

You can change the user in your script at any time:

su - postres
  1. Ssh-copy-id

Add ssh keys for root to the remote server:

ssh-copy-id postgres@your.box

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.