rails db:migrate Failed to open TCP connection connection refused - ruby-on-rails

I'm getting connection refused whenever I try to migrate on rails. Running rails db:migrate gives:
Failed to open TCP connection to 127.0.0.1:8126 (Connection refused - connect(2) for "127.0.0.1" port 8126)
I tried checking if something is already taking up this port using:
netstat -vanp tcp | grep 8126
but there is nothing.
For extra measure, I made sure that docker is not running. Nothing seems to fix the issue though. Not sure what other info to include or what other thing can I try.
Any hints would be greatly appreciated

Related

Communication between Docker Application and localhost application [duplicate]

This question already has answers here:
From inside of a Docker container, how do I connect to the localhost of the machine?
(40 answers)
Closed 2 years ago.
I have an application running inside Docker(M1). And an another application running on localhost(M2-Not Dockerized). Both are Ruby on Rails applications running on ports 3000 and 3001. I am calling M2 from inside of M1 by using
response = http_client.post("127.0.0.1:3001", query, {}, options)
But I keep on getting
Error: Failed to open TCP connection to 127.0.0.1:3001 (Connection refused - connect(2) for "127.0.0.1" port 3001), Backtrace: ["/usr/local/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'", "/usr/local/lib/ruby/2.5.0/net/http.rb:936:in `block in connect'", "/usr/local/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'", "/usr/local/lib/ruby/2.5.0/timeout.rb:103:in `timeout'", "/usr/local/lib/ruby/2.5.0/net/http.rb:935:in `connect'"
If i use -
response = http_client.post("localhost:3001", query, {}, options)
then i get
Error: Failed to open TCP connection to localhost:3001 (Cannot assign requested address - connect(2) for "localhost" port 3001), Backtrace: ["/usr/local/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'", "/usr/local/lib/ruby/2.5.0/net/http.rb:936:in `block in connect'"
So it changed from Connection refused to Cannot assign requested address.
I am able to access both the applications by calling localhost:3000 and localhost:3001 from the browser individually. I am assuming it is happening because of a Dockerized application calling a Non-Dockerized one. Can someone suggest how to establish the connection between the two, I have tried many things. I am running Docker-2.1.0.5 on macOS Mojave 10.14.6 and Ruby 2.5.0. Let me know if any other information is required.
The issue may be in your request for "localhost". In your request, replace localhost with 0.0.0.0. It will most likely work. See https://github.com/moby/moby/issues/2522 for more info. As according to muellermichel:
It's basically the same when you want to make couchdb accessible from outside your host, no matter whether it runs in a container or not: you need to bind it's address to 0.0.0.0:
So just use 0.0.0.0 and you'll most likely be okay!
EDIT:
This may be an active issue, with a fix not yet available. See https://github.com/topofocus/active-orient/issues/22 for the github thread, no solutions still exist.
EDIT 2:
See Failed to open TCP connection to localhost:9200 (Cannot assign requested address - connect(2) for "localhost" port 9200). It may solve your problems.

heroku pg:psql not working [connection refused]

I am running a Ruby on Rails app on Heroku with Postgres Database.
I used to be able to connect to my database from my terminal using heroku pg:psql command
Recently, things have changed. After running heroku pg:psql command, I get the following error.
--> Connecting to postgresql-perpendicular-94363
psql: could not connect to server: Connection refused
Is the server running on host "ec2-23-23-130-158.compute-1.amazonaws.com" (23.23.130.158) and accepting
TCP/IP connections on port 5432?
I tried to search online about it, but nothing useful has been found.
Please help. Thanks 😄
I've just tried connect to your database:
psql "dbname=postgresql-perpendicular-94363 host=ec2-23-23-130-158.compute-1.amazonaws.com user=test_user port=5432 sslmode=require"
And I've got:
psql: FATAL: password authentication failed for user "test_user"
Because, of course I don't know you credentials :)
However, it seems that connection works. I suppose, that you forgot set sslmode. As you can see in documentation, it is required:
All connections require SSL: sslmode=require.
Update:
I've checked connection without sslmode, and message is other than yours:
FATAL: no pg_hba.conf entry for host "31.42.24.63", user "test_user", database "postgresql-perpendicular-94363", SSL off
So, I suppose that this is a problem with you internet connection. Check you firewall setup.
As per the description mentioned in the post, the way you have specified is correct.
Moreover you can also try the below mentioned command where you specify the database as well.
heroku pg:psql DATABASE_URL
Note: This is only used when there are multiple databases linked.

Running localhost:3000 using Ruby on rails with pgadmin3 database i get following errors

Can anyone help me fix this problem?? when i run localhost:3000 i encounter this?
"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?..... Now, again when i try to run "net start postgresql-9.5" in CMD line it says
'system error 5 has occured,access is denied'.
what is wrong i cant understand?
I know in windows it's struggling to learn rails but if you want to continue below is some tips when I test running rails with windows
for rails installer, you can download from http://railsinstaller.org/en it include git , ruby and rails
for postgres, I think it's easier to install from this site, you just follow windows instruction and make sure you write down the password as you will need it later for your database.yml (database configuration)
after you install both programs, when you want to open command prompt, make sure you choose command prompt with ruby on rails, as this command prompt will include git, ruby and rails command.
hopefully can help

Rails 4 + Postgres: Randomly cannot connect to development server

I am running Rails 4.2.2 and my postgres gem is 0.17.1 and everything was running fine yesterday but today when I opened the console and tried connecting to the database I saw this error:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
...then when I tried connecting to the database through running psql, I see the following:
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/bin/psql
Reason: image not found
Abort trap: 6
As far I know I havent changed anythingsince yesterday so I'm not sure why this is happenning. I tried adding host: localhost to my database.yml with no luck. It may be worth noting when I try to connect to the DB using a program like PSequel, I see the following:
could not connect to server: Connection refused
is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
Has anyone seen this?
Neara's response to this post provided an answer for me: PostgreSQL server won't stop.
Basically had to run:
$ brew services list
$ brew services restart postgresql
They posted a workaround in case services cannot be found.

connection failed for: localhost (Errno::ECONNREFUSED: Connection refused - connect(2))

I am using capistrano 2.15.5 for my rails application deployment. I am using localhost for server and have also tried with 127.0.0.1 in place of localhost. After running *cap production deploy:setup* the error that i am getting is: **Errno::ECONNREFUSED: Connection refused - connect(2)**.
After searching for it i found out ECONNREFUSED means the client couldn't make a TCP connection to the server, either because it's down, or its DNS is not resolving..
how to fix this issue?
thanks.
You have to add your ssh key in server's ssh authorize keys

Resources