问题
I've failed to set up postgreSQL
to work with my Ruby-on-Rails
project for the past week.
I've tried to uninstall and reinstall, postgreSQL
, twice now.
But when I try to launch postgreSQL
I keep getting the error below:
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and
accepting TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and
accepting TCP/IP connections on port 5432?"
I've looked at many online resources, including stackoverflow and none seem helpful.
The key parts of my pg_hba.conf
file looks like this:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
And the key part of my postgresql.conf
file is as follows:
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
Most of the suggestions, I've seen so far, were based on those two files. (For my case, they were already configured correctly). I also tried disabling the firewall and restarting postgreSQL but it didn't help. Does anyone have any suggestions for me? Thanks!
回答1:
Got the same issue while settings up PostgreSQL 9.6.16 to work with Python/Django, but this is purely a database issue.
The solution lies in the error: In fact, I found this error mentioned within the official PostgreSQL documentation thus it's a common error.
And here is how I resolved this issue:
- Always first start the postgres database server, use
postgres
or the wrapper programpg_ctl
.
I used the command, below, onwindows 10
.
Remember, whatever comes after-D
should be the path to where you installed PostgreSQL, to thedata
folder, which holds thepg_hba.conf
andpostgresql.conf
files.
> pg_ctl start -D "C:/Program Files/PostgreSQL/9.6/data"
- If that runs well, you are ready to access the database server.
Open anothercmd
shell, and type the command below.
Remember the password you entered while installingPostgreSQL
?
Enter that password when askedPassword for user postgres:
> psql -U postgres
Once done, you can now go ahead to CREATE ROLE
and CREATE DATABASE
accordingly.
回答2:
[SOLVED]
After much more research. I looked in depth at the error I was receiving post downloading and came to this solution here
Best of luck for anyone having the same issue!
来源:https://stackoverflow.com/questions/41125185/postgresql-could-not-connect-to-server-connection-refused-error