Thursday, December 22, 2011

Postgresql - repmgr: Promoting standby repmgr: restarting server using pg_ctl sh: pg_ctl: not found . Can't restart PostgreSQL server

I was issuing this command through a remote ssh session. repmgr needs pg_ctl and pg_config to be in the PATH environment variable.
Issue: through ssh you only can use (by default) some env. variables that are not necessarily all the variables you need:

for instance, in my linux box with the postgres user:

postgres@linux-2561:~> ssh localhost env
LESSKEY=/etc/lesskey.bin
NNTPSERVER=news
MANPATH=/usr/local/man:/usr/local/share/man:/usr/share/man
XDG_SESSION_ID=38
HOSTNAME=linux-2561.site
XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
HOST=linux-2561.site
SHELL=/bin/bash
PROFILEREAD=true
HISTSIZE=1000
SSH_CLIENT=::1 53239 22
MORE=-sl
USER=postgres
XNLSPATH=/usr/share/X11/nls
HOSTTYPE=i386
CONFIG_SITE=/usr/share/site/i686-pc-linux-gnu
FROM_HEADER=
PAGER=less
CSHEDIT=emacs
XDG_CONFIG_DIRS=/etc/xdg
MINICOM=-c on
MAIL=/var/mail/postgres
PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin
CPU=i686
SSH_SENDS_LOCALE=yes
INPUTRC=/etc/inputrc
PWD=/var/lib/pgsql
LANG=en_US.UTF-8
PYTHONSTARTUP=/etc/pythonstart
GPG_TTY=not a tty
QT_SYSTEM_DIR=/usr/share/desktop-data
SHLVL=1
HOME=/var/lib/pgsql
SDL_AUDIODRIVER=pulse
ALSA_CONFIG_PATH=/etc/alsa-pulse.conf
LESS_ADVANCED_PREPROCESSOR=no
OSTYPE=linux
XCURSOR_THEME=DMZ
WINDOWMANAGER=/usr/bin/startkde
G_FILENAME_ENCODING=@locale,UTF-8,ISO-8859-15,CP1252
LESS=-M -I -R
MACHTYPE=i686-suse-linux
LOGNAME=postgres
CVS_RSH=ssh
XDG_DATA_DIRS=/usr/local/share:/usr/share
SSH_CONNECTION=::1 53239 ::1 22
LESSOPEN=lessopen.sh %s
XDG_RUNTIME_DIR=/run/user/postgres
LESSCLOSE=lessclose.sh %s %s
G_BROKEN_FILENAMES=1
COLORTERM=1
_=/usr/bin/env


Solution:

This can be achieved in 2 steps:
- Add ‘PermitUserEnvironment yes’ to your sshd_config file and restart the ssh service.
Rem: Default value is set to ‘No’.
Update: on opensuse this parameter is set into the /etc/ssh/sshd_config file
- Define your environment variables in .ssh/environment on the target host.
eg LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib

Reference:
http://www.netexpertise.eu/en/ssh/environment-variables-and-ssh.html

Once followed the aforementioned steps, everything goes just fine =-).
repmgr: Promoting standby
repmgr: restarting server using pg_ctl
repmgr: STANDBY PROMOTE successful. You should REINDEX any hash indexes you have.

No comments:

Post a Comment