Remote PostgreSQL connection with pgAdmin

前端 未结 1 1627
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 18:23

I\'m trying to set up a remote connection through PostgreSQL running on my server , based on Ubuntu 16.04. So far, when I click on the Save button on pgAdmin, it sort of fre

相关标签:
1条回答
  • 2021-01-06 18:54

    First of all test if you can connect to the database via psql:

    psql -h ip_address -d name_of_the_database -U username
    

    If you get connection refused error you had to set up something wrong and check the What should I check if remote connect to PostgreSQL not working?

    psql: could not connect to server: Connection refused Is the server running on host ip_address
    

    What should I check if remote connect to PostgreSQL not working?

    1. Check the authentication configuration in pg_hba.conf

      Usually located on linux - /etc/postgresql/version/main/pg_hba.conf. You should allow authentication for client for specific IP all from all IP addresses:

      # Database administrative login by Unix domain socket
      local     all            postgres        peer
      
      # TYPE  DATABASE        USER            ADDRESS                 METHOD
      
      # "local" is for Unix domain socket connections only
      local     all            all             peer
      # IPv4 local connections:
      host     all             all             0.0.0.0/0               md5
      # IPv6 local connections:
      host     all             all             ::0/0                   md5
      #all ips
      host     all             all             all                     md5
      

      More information how to set up pg_hba.conf you can find in documentation.

    2. Then you should set up listening on specific port.

      You have to find the postgresql.conf. Usually located /etc/postgresql/9.1/main/postgresql.conf) file and change the line with listen_address from:

      #listen_address = ''
      

      to (don't forget remove # which means comment):

      listen_address = '*'
      
    3. After every step you should restart Postgresql service:

      sudo service postgresql restart
      
    4. After step 2 you should see port 5432 (or 5433) in listening address after netstat command:

      netstat -ntlp
      
    5. After that you have to open port for PostgreSQL in firewall:

      sudo ufw allow 5432
      

      You can check firewall settings with (you should see 5432 in the list):

      sudo ufw status
      
    6. If any of the previous step doesn't work you should check if PostgreSQL is not running on different port (usually 5433) and repeat the previous steps.

      This happens very often when you have more running versions of PostgreSQL or you upgrade database and forgot stop the previous version of PostgreSQL.

    If you have problems to find configuration files you can check this thread Where are my postgres *.conf files?.

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