Mittu Rajareddy
Mittu Rajareddy

Reputation: 21

ActiveRecord::ConnectionNotEstablished: PostGreSQL

I work on windows 11 Germ versions `

ruby "2.7.3"

Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"

gem "rails", "~> 7.0.7"

Use postgresql as the database for Active Record

gem "pg", "~> 1.1" `

when I try to migrate the db migrations for the first time, it started showing the error

` rails aborted! ActiveRecord::ConnectionNotEstablished: connection to server at "localhost" (::1), port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?

Caused by: PG::ConnectionBad: connection to server at "localhost" (::1), port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?

Tasks: TOP => db:migrate (See full trace by running task with --trace)
`

I tried re-installing pg, I cant find postgresql in services also to restart. I tried changing the port, still it is not working

Upvotes: 0

Views: 1209

Answers (1)

Allacassar
Allacassar

Reputation: 214

The problem is that you dont have the postgress installed. The pg gem is just the adapter (communication layer) between your project and postgress. You need to install and setup the postgress separately and for that there is a lot of tutorials in google. ChatGPT also can provide a lot of helpfull instructions on postgres instalation. Here is the basic steps you should fulfill:

  1. You need to first install the postgres on your machine outside of rails project.
  2. you need to start the postgres service in order for it to receive the requests from your rails application
  3. you need to launch plsql console and create a db user with some password, and grant him the rights to make all changes in db
  4. in database.yml file in your project you should put that user and password in config
  5. restart your rails project, and that should do the trick.

Upvotes: 1

Related Questions