'Connection timed out' when connecting on heroku database using 'pg:psql' command - node.js

I am trying to connect to my database on heroku, which I would use on my app. I'm using either Command Line or Git Bash on windows.
I have created database on heroku named postgresql-rectangular-87454 and installed Postgres without any errors.
Typing heroku addons I'm making sure, database is set up:
$ heroku addons
Add-on Plan Price State
──────────────────────────────────────────────── ───────── ───── ───────
heroku-postgresql (postgresql-rectangular-87454) hobby-dev free created
└─ as DATABASE
but when I try to connect it via heroku pg:psql or also heroku pg:psql postgresql-rectangular-87454 --app salty-shelf-36209, I get this error:
$ heroku pg:psql
--> Connecting to postgresql-rectangular-87454
psql: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "ec2-54-225-97-112.compute-1.amazonaws.com" (54.225.97.112) and accepting
TCP/IP connections on port 5432?
Any advice would be appreciated. Thank you!

Without knowing more, my first guess would be network rules -- that the connection is being blocked by a local firewall. The pg:psql command simply grabs the DATABASE_URL from your application config and passes the connection string to your local psql command to create the connection. If you're behind a corporate firewall, you may need to speak with your IT department about making an outbound connection.

Related

Depending on HOST NAME value for PostgreSQL database in my .env file I get different result

I have created a PostgreSQL with a web server DOCKER CONTAINER and my app running with an API to manage all the endpoints.
The link of my git repo is: https://github.com/JulioValderrama/store-front-project.git
But I am facing problems with the connections with the Database, as depending on the Postgres HOST name value in my .env file one of the two servers (one local running in PORT 4000 and the web server running in the docker container in PORT 3000) will work or will fail.
I have tried the next:
Local server running in PORT 4000
Docker web server running in PORT 3000
HOST "127.0.0.1"
Going to¨:
http://localhost:3000/
Works fine and get response, now when trying to connect it to any of my database API:
http://localhost:3000/products
I get the error:
"Could not get PRODUCTS. Error: Error: connect ECONNREFUSED 127.0.0.1:5432"
Going to:
http://localhost:4000
Works fine and get response, now when trying to connect it to any of my database API:
http://localhost:4000/products
It works! I get the list of all my products!!
HOST "postgres"
I put "postgres" because I read online that you have to name HOST as the postgres docker image created, which is my case. And it works for the remote server.
Going to:
http://localhost:3000
Works fine and get response, then when trying to connect it to database API:
http://localhost:3000/products
It works!! It gives me the list of my products !!
Going to:
http://localhost:4000
Works fine and get response, then when trying to connect it to database API:
http://localhost:4000/products
It gives me the error:
"Could not get PRODUCTS. Error: Error: getaddrinfo ENOTFOUND postgres"
So it seems like there is an error when trying to connect to the database due to the server or the HOST name, I have no idea....
In docker-compose.yaml you have linked your machine 5432 to containers 5432 port.
If you are using docker container and want to reach postgres, use postgres as POSTGRES_HOST value.
If you are running application outside the docker environment use 0.0.0.0, 127.0.0.1.
Make sure you haven't installed postgres locally
brew uninstall postgres

Need to establish an SSH tunnel in Node.js or do it on the server

I'm going to connect to a remote database using an SSH tunnel. Currently, I'm not sure how long the server is alive, but I will check with my provider.
However, is it safe to assume that I will be able to connect to the database by running this command: ssh -fNg -L 1337:database-name:3306 user#ssh-server.com once on the client? Or do I need to establish a connection all the time? I know there exist some npm modules to connect via SSH.
Thanks in advance!

Error connecting to my redis server from my code

io.adapter(redis({ host: config.redisHost, port: config.redisPort }));
Both the confif.redisHost and config.redisPort are the correct values, but when I try to connect from my code I get the error -
'Error: Redis connection to 104.xxx.xx.xxx:6379 failed - connect ECONNREFUSED 104.xxx.xx.xxx:6379'
In redis.conf I've changed the bind to 0.0.0.0 as well as removing it completely and I've also tried setting protected mode to off just to try and get the connection working.
The IP and port are definitely, correct. Does anyone know why I might not be able to access the server from my code? My code is just being ran on my local machine and the redis server is being ran on a digital ocean ubuntu 14.04 machine. The status of the server is definitely running and I can access the redis-cli from the machine itself.
For some reason, it wasn't using redis.conf when I tried starting the server, I had to manually tell it to use it when starting up, now it's working.

Heroku NodeJs Postgres Heroku pg:psql - Connection Timeout

I'm following the tutorial:
https://devcenter.heroku.com/articles/getting-started-with-nodejs
I have everything working until the provosion a database step. My code is exactly the same as theirs, but for some reason I can't connect to
heroku pg:psql
It says Connecting to DATABASE_URL and then the connection times out. Does anyone know what's happening? I set the DATABASE_URL following the format:
"postgres://*USERNAME*:*PASSWORD*#*HOST*:*PORT:/*DATABASE*"

Cannot create redis cluster (Sorry, can't connect to node)

I'm trying to follow the redis cluster tutorial but whenever I try to run:
./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 \
127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005`
I get the error:
[ERR] Sorry, can't connect to node 127.0.0.1:7000
The server is running and I can connect to port 7000 using
redis-cli -p 7000
What am I missing?
Turns out I had REDIS_URL set in .bashrc from a previous project. Apparently the redis gem was setting the password from that url for ALL redis connections (even though I was not using the url for my cluster).
Thanks to soveran for pointing out this posibility in this question

Resources