Check if Postgresql is listening

后端 未结 3 750
北荒
北荒 2021-02-06 03:15

Given an IP Address and port number, is it possible to check if the machine with that IP address has Postgresql listening on the specified port? If so, how?

I just want

3条回答
  •  遇见更好的自我
    2021-02-06 03:53

    In brief

    In details

    Fastest way is to use netcat aka nc with timeout ability as shared here

    Results as 0/1 means postgres working/not-working

    echo 'QUIT' | nc -w SECONDS YOUR_HOST PORT; echo $?
    # eg
    echo 'QUIT' | nc -w 1       localhost 5432; echo $?
    

    Another also-faster way that works for me is to use telnet as discussed here.

    echo -e '\x1dclose\x0d' | telnet YOUR_HOST PORT
    # eg
    echo -e '\x1dclose\x0d' | telnet localhost 5432
    

提交回复
热议问题