I keep getting this error when i try to run my localhost using \"$rails s\":
(Mac OSX 10.8.3) (ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]) (R
The error message is instrumental:
could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5433?
You may be trying to connect to the wrong port.
Standard port is 5432. Check how (and whether at all) you started your postgres server:
postgres@db:~$ ps -auxww | grep ^postgres
... <stripped more lines>
postgres 1274 0.0 0.3 1437240 57308 ? S May27 5:01 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf
The manual has related information here.
In my example, settings from /etc/postgresql/9.1/main/postgresql.conf
got used, which says (among many other settings):
port = 5432
Or run:
netstat -nlp | grep postgres
Or just look here (at least in Debian or Ubuntu):
ls -lA /var/run/postgresql/
PostgreSQL picks the next free port if you create a new database cluster. Since you installed repeatedly, you may have confused port numbers.
Or you just forgot to allow TCP/IP connections. Related answers:
In my case, the problem was caused by the upgrade of postgresql-9.4 to postgresql-9.5 in Ubuntu 16.04. Since, There were two versions installed at some point in time, the later installed version i.e. postgresql-9.5's config changed to default port of 5433
(instead of standard default 5432
).
The problem occurred when my Rails project tried to connect to the default port of postgresql (since the port was not defined explicitly defined in database.yml
file) and kept failing. Even after removal of postgresql-9.4 later.
The solution is changing the port in the configuration of updated postgresql (9.5). To do this open the file /etc/postgresql/9.5/main/postgresql.conf
and change the line
port = 5433 # (change requires restart)
to
port = 5432 # (change requires restart)
and then restart the server with sudo service postgresql restart
.
Alternatively, you can change rails' database.yml
file by explicitly mention the new port (that ie 5433
) without changing the postgresql's config file. To do this, simply add a line like this
port: 5433
and restart the rails server.
sudo -u postgres pg_ctlcluster 9.3 main stop
followed by
sudo -u postgres pg_ctlcluster 9.3 main restart
worked for me
This may resolve the issue :-
Get the hba.conf file address by using command SHOW config_file;
and SHOW hba_file;
in sql prompt
Now open hba.conf
and add this host all all 0.0.0.0/0 trust
Now open postgresql.conf
and add listen_address = '*'
I got this error message hooking up to Jira (from the Jira side) and the solution was to change the "Hostname or IP address of the database server." to "localhost". If you're running locally you can't just put in your local ip address.
Also the next issue for a local install is the password always fails even though that's correct because pg_hba.conf needs to be edited so the authentication method is "trust".
In postgresql.conf, /var/lib/pgsql/data/postgresql.conf
:
change the listen_addresses = 'localhost' to listen_addresses = '*'
enable the default port as 5432, port = 5432
Also in pg_hba.conf, /var/lib/pgsql/data/pg_hba.conf
,
try the authentication method as trust