Обсуждение: using pg_ctl over ssh hangs
All
I am wanting to run pg_ctl as a command over ssh, however when I pass start it hangs until I do a Ctl-C
This works fine:
$ node3=172.16.171.132
$ ssh -T postgres@${node3} "/usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data stop"
waiting for server to shut down.... done
server stopped
$
I am immediately returned to a command prompt
However , this does not return me to a command prompt until I do a Ctl-C:
$ node3=172.16.171.132
$ ssh -T postgres@${node3} "/usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data start"
waiting for server to start....2023-10-19 19:23:42.947 MDT [2053] LOG: redirecting log output to logging collector process
2023-10-19 19:23:42.947 MDT [2053] HINT: Future log output will appear in directory "log".
done
server started
^C
$
Thanks in advance
$ ssh -T postgres@${node3} "/usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data start"
waiting for server to start....2023-10-19 19:23:42.947 MDT [2053] LOG: redirecting log output to logging collector process
2023-10-19 19:23:42.947 MDT [2053] HINT: Future log output will appear in directory "log".
done
server started
^C
Sbob <sbob@quadratum-braccas.com> writes: > I am wanting to run pg_ctl as a command over ssh, however when I pass > start it hangs until I do a Ctl-C > $ ssh -T postgres@${node3} "/usr/pgsql-14/bin/pg_ctl -D > /var/lib/pgsql/14/data start" If you don't specify a log file (-l option to pg_ctl) then the postmaster's stdout doesn't get dissociated from the calling terminal, which likely explains why ssh doesn't think the session is done. regards, tom lane
the first thing that comes to mind would be trying to send the remote command into the background
$ ssh -T postgres@${node3} "/usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data start &"
this may come with the disadvantage that you do not receive the "server started" feedback.
the second was to try Ansible
- name: start postgres @ node 3
hosts: node3
tasks:
- name: start postgresql
ansible.builtin.cmd
cmd: "/usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data start"
become: true
become_user: postgres
this of course requires for you to have Ansible available (which may come handy anyway).
All
I am wanting to run pg_ctl as a command over ssh, however when I pass start it hangs until I do a Ctl-C
This works fine:
$ node3=172.16.171.132
$ ssh -T postgres@${node3} "/usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data stop"
waiting for server to shut down.... done
server stopped
$I am immediately returned to a command prompt
However , this does not return me to a command prompt until I do a Ctl-C:
$ node3=172.16.171.132
$ ssh -T postgres@${node3} "/usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data start"
waiting for server to start....2023-10-19 19:23:42.947 MDT [2053] LOG: redirecting log output to logging collector process
2023-10-19 19:23:42.947 MDT [2053] HINT: Future log output will appear in directory "log".
done
server started
^C
$
Thanks in advance