Can't connect to Postgresql on port 5432

后端 未结 6 1939
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 19:46

I have PostgreSQL 9.3 installed on a server running Ubuntu Server 14.04.

If I ssh into the server via terminal, I\'m able to connect with psql. But when I try to con

相关标签:
6条回答
  • 2020-12-04 19:59

    You have to edit postgresql.conf file and change line with 'listen_addresses'.

    This file you can find in the /etc/postgresql/9.3/main directory.

    Default Ubuntu config have allowed only localhost (or 127.0.0.1) interface, which is sufficient for using, when every PostgreSQL client work on the same computer, as PostgreSQL server. If you want connect PostgreSQL server from other computers, you have change this config line in this way:

    listen_addresses = '*'
    

    Then you have edit pg_hba.conf file, too. In this file you have set, from which computers you can connect to this server and what method of authentication you can use. Usually you will need similar line:

    host    all         all         192.168.1.0/24        md5
    

    Please, read comments in this file...

    EDIT:

    After the editing postgresql.conf and pg_hba.conf you have to restart postgresql server.

    EDIT2: Highlited configuration files.

    0 讨论(0)
  • 2020-12-04 20:00

    Remember to check firewall settings as well. after checking and double-checking my pg_hba.conf and postgres.conf files I finally found out that my firewall was overriding everything and therefore blocking connections

    0 讨论(0)
  • 2020-12-04 20:00

    I had the same problem after a MacOS system upgrade. Solved it by upgrading the postgres with brew. Details: it looks like the system was trying to access Postgres 11 using older Postgres 10 settings. I'm sure it was my mistake somewhere in the past, but luckily it all got sorted out with the upgrade above.

    0 讨论(0)
  • 2020-12-04 20:05

    This has bitten me a second time so I thought might be worth mentioning. The line listen_addresses = '*' in the postgresql.conf is by default commented. Be sure to uncomment (remove the pound sign, # at the beginning) it after updating otherwise, remote connections will continue to be blocked.

    0 讨论(0)
  • 2020-12-04 20:05

    Had same problem with psql via command line connecting and pgAdmin not connecting on RDS with AWS. I did have my RDS set to Publicly Accessible. I made sure my ACL and security groups were wide open and still problem so, I did the following: sudo find . -name *.conf then sudo nano ./data/pg_hba.conf then added to top of directives in pg_hba.conf file host all all 0.0.0.0/0 md5 and pgAdmin automatically logged me in.

    This also worked in pg_hba.conf file host all all md5 without any IP address and this also worked with my IP address host all all <myip>/32 md5

    As a side note, my RDS was in my default VPC. I had an identical RDS instance in my non-default VPC with identical security group, ACL and security group settings to my default VPC and I could not get it to work. Not sure why but, that's for another day.

    0 讨论(0)
  • 2020-12-04 20:19

    You probably need to either open up the port to access it in your LAN (or outside of it) or bind the network address to the port (make PostgreSQL listen on your LAN instead of just on localhost)

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