4

I'm using rails to develop a website but i get this error when i try to open my localhost

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?

How to fix it guys

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
Gary Vlc
  • 141
  • 1
  • 2
  • 10

4 Answers4

6

In Windows, search for "services" and search for postgres in the list. Right click and select "Start".

SHILPA AR
  • 332
  • 2
  • 7
  • 18
1

It looks like your postgreql server is not running. You can try to launch it with :

On Linux :

 sudo service postgresql start

On windows : changing XX by your postgresql version run :

 net start postgresql-XX

You can also stop using postgres and specify a sqlite database in your config/database.yml file :

changing this line :

adapter: postgresql

by this line :

adapter: sqlite3
Raphayol
  • 1,266
  • 11
  • 14
  • Thanks for the reply, the sudo is which folder? and how specify a sqlite database in my database.yml file? – Gary Vlc Oct 06 '16 at 08:38
  • sudo is a part of the command but it is not absolutely sure that you need it. So try : service postgresql start If this failed with something like 'permission denied', you can try : sudo service postgresql start And if you want you can stop using postgres for your database and use sqlite : in your config/database.yml change this line adapter: postgresql into this line : adapter: sqlite – Raphayol Oct 06 '16 at 08:40
  • I tried to write on C:/Users/name>services postgresql start, but it still can't fix the problem :( – Gary Vlc Oct 06 '16 at 08:45
  • On windows : changing XX by your postgresql version run : net start postgresql-XX – Raphayol Oct 06 '16 at 08:47
  • Sorry how do I find my postgresql? I know is psql -V but everytime i typed in CMD, it says it is not recognised as an internal or external command – Gary Vlc Oct 06 '16 at 08:57
  • This app is configured to be used with a postgresql server. Have you already launch this rails application on your computer ? If yes you should remember how do you launch postgresql : maybe with a software like pgAdmin... see this for more details : http://stackoverflow.com/questions/36629963/how-to-start-postgresql-on-windows If no maybe you have to install it – Raphayol Oct 06 '16 at 09:06
1

If you are using postgreql this issue is due to not starting a server, so you should start the server, one way to do it is to cd to postgresql bin and start it with pg_ctl, here is an example:

cd "C:\Program Files\PostgreSQL\14\bin"
pg_ctl -D "C:\Program Files\PostgreSQL\14\data" start
DINA TAKLIT
  • 7,074
  • 10
  • 69
  • 74
0

If you are running postgres in a docker image, be sure to map the container port to the host. You can do this with docker run -p 5432:5432 <container-name> or by adding the following to your docker-compose.yml file:

ports:
- 5342:5342
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268