Find the host name and port using PSQL commands

前端 未结 13 2202
眼角桃花
眼角桃花 2020-12-12 11:15

I have PSQL running, and am trying to get a perl application connecting to the database. Is there a command to find the current port and host that the database is running on

相关标签:
13条回答
  • 2020-12-12 11:40

    From the terminal you can do:

    \conninfo

    I would suggest reading a documentation on their exhaustive list of all commands using:

    \?

    0 讨论(0)
  • 2020-12-12 11:43

    The default PostgreSQL port is 5432. The host that the database is operating on should have been provided by your hosting provider; I'd guess it would be the same host as the web server if one wasn't specified. Typically this would be configured as localhost, assuming your web server and database server are on the same host.

    0 讨论(0)
  • 2020-12-12 11:43

    This command will give you postgres port number

     \conninfo
    

    If postgres is running on Linux server, you can also use the following command

    sudo netstat -plunt |grep postgres
    

    OR (if it comes as postmaster)

    sudo netstat -plunt |grep postmaster
    

    and you will see something similar as this

    tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      140/postgres
    tcp6       0      0 ::1:5432                :::*                    LISTEN      140/postgres
    

    in this case, port number is 5432 which is also default port number

    credits link

    0 讨论(0)
  • This is non-sql method. Instructions are given on the image itself. Select the server that you want to find the info about and then follow the steps.

    enter image description here

    0 讨论(0)
  • 2020-12-12 11:43

    The postgresql port is defined in your postgresql.conf file.

    For me in Ubuntu 14.04 it is: /etc/postgresql/9.3/main/postgresql.conf

    Inside there is a line:

    port = 5432
    

    Changing the number there requires restart of postgresql for it to take effect.

    0 讨论(0)
  • 2020-12-12 11:44

    select inet_server_addr(); gives you the ip address of the server.

    0 讨论(0)
提交回复
热议问题