Cannot connect to db server to specified port - postgresql

I am trying to set up db using docker. However I am facing the following issue that my port is not accepting following connections to this port. I've ran docker-compose up, all worked fine. Now I just can't connect to the server using pgAdmin.
Screenshot of error below:
Image
Code src: https://github.com/khezen/compose-postgres

It's because your IP address is resolved in pgadmin service and localhost(127.0.0.1) resolved in pgadmin container, not in the host machine.
You should add a public or machine IP address or if both pgadmin and postgres service in the same network add the hostname of postgres service.

Related

How can I connect to a PostgreSQL server running inside a Docker container on a GCP virtual machine?

I have pgAdmin4 and PostgreSQL running inside Docker containers on a GCP virtual machine. I have already ingested data into PostgreSQL and I can access the tables and databases using pgcli. However, I am unable to connect to pgAdmin4. How can I connect to the pgAdmin4?
You will access pgadmin with your browser.
When you start up the pgadmin container, you should have configured a port mapping. Add a firewall rule to your VM's network configuration for this mapped port (for example, I've configured an ingress firewall rule for 15432 because I mapped 15432 to 80 in my docker config).
Example snippet from docker-compose:
ports:
- 15432:80
Assuming you have configured an external IP address, use the external IP address and the port number in your browser to access pgadmin. Like this, where XX.XX.XX.XXX is your external IP and 15432 was mapped to port 80:
http://XX.XX.XX.XXX:15432/login

How to Connect using Port Forwarding Database Postgrsql on Openshift 3

I Have a problem on Connect from Port Forwarding Database on Openshift :
Running Pods Postgresql :
I Try Connect to Container running the database to check process and psql command, then it works :
Next, I Try Port Forwarding for Try Connection from outside Openshift Cluster:
Then I Try Connect from Outside Cluster to connect Postgresql have Error: Connection Refuse
Im Using IP Based or Hostname / FQDN Not Working and Error Still Exist
And When I Try Check Firewall port it has been opened port 5432/TCP :
Anyone Can Help Me With This problem ?
Thanks
Note: Before I have Been Looking Documentation but Not Working Resolve the Problem
Source Documentation:
https://www.openshift.com/blog/openshift-connecting-database-using-port-forwarding
"psql: could not connect to server: Connection refused" Error when connecting to remote database
The oc port-forward command is forwarding from only your loopback interfaces.
If you are running your client on the same machine where the cluster is running, then use localhost as your "Host".
If you are running your client on a different machine, they you need more network redirection to get this to work. Please see this post for more information as well as work-arounds for your problem: Access OpenShift forwarded ports from remote host

Docker container, running PostgreSQL not allowing php's pg_connect from another container

I have the following architecture:
A network with 3 containers:
container_db, running PostgreSQL
container_pg_admin, running a simple pgAdmin environment
container_php_dev, running the whole environment, needed for the application to function properly (nginx, php, angular for the frontend, etc.)
When I try to pg_connect() from container_php_dev to container_db the connection gets refused. This is the actual error message I get: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host↵ Is the server running on host "container_db" (172.18.0.4) and accepting↵ TCP/IP connections on port 5432?.
However, when I try to connect to container_db from container_pg_admin I face no problem achieving this (host is container_db and port is 5432). Even if I map port 5432 of container_db to 5555 on host, I'm able to connect to 127.0.0.1:5555 from DBeaver or other DB Manager (TeamSQL).
All containers were restarted a few times as well as docker itself. And as this is my development machine, the host PC was restarted as well.
What might be the problem, how to diagnose and possibly solve? Have any of you experienced such strange docker behaviour?
Try running the container_db in the hosted network using flag --network host

HEROKU POSTGRES error: Connection refused Is the server running on host "..compute-1.amazonaws.com..." and accepting TCP/IP connections on port 5432?

I have been trying for weeks to figure out what's the issue, but I cannot seem to fix this.
I am developing a web app, and I have deployed to production using Heroku. I'm using Heroku Postgres for my database, and I'd like to psql into that hosted database from my local machine to make changes to it. I have tried from both Mac OS X and Linux Mint.
However, no matter what I try, I keep getting the following error:
---> Connecting to HEROKU_POSTGRESQL_ORANGE_URL (DATABASE_URL)
psql: could not connect to server: Connection refused
Is the server running on host "ec2-***-**-***-**.compute-1.amazonaws.com" (***.**.***.**) and accepting
TCP/IP connections on port 5432?
I'm starting to think that I may have to SSH into the Amazon EC2 instance and change the Postgres configuration? Would that even be possible?
You can't connect directly to the EC2 instance where the Heroku Postgres instance is running; it is managed by Heroku and normal users aren't allowed to connect to it.
If your application is running fine in Heroku, and you're running heroku pg:psql to attempt to connect to the DB, then most likely there is some issue with your local network that is preventing you from connecting to the Postgres database, like a firewall blocking outbound connections. Heroku Postgres databases are open to the public without any restriction on IP ranges.
It could be a problem with the proxy or firewall of the internet connection you are using.
Try to connect your PC to your mobile phone tethering and then launch the command again, just to verify if the problem lies there.
I was getting this kind of error when my pg_hba.conf or AWS security groups have not been configured properly. There are plenty of docs about how to resolve this. For example, you can check this list link
You can directly connect to EC2 Heroku Postgress instance by adding this attributes to the end of your DB connection url:
jdbc:postgresql://<host>/<dbname>?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

OpenShift: How to connect to postgresql from my PC

I have an openshift app, and I just installed a postgresql DB on the same cartridge.
I have the postgresql DB installed but now I want to connect to the DB from my PC so I can start creating new tables.
Using port forwarding I found my IP for the postgresql db to be
127.3.146.2:5432
under my webaccount I see my
Database: txxx
User: admixxx
Password: xxxx
Then Using RazorSQl I try to setup a new connection
keeps coming as user password incorrect.
If I try and use the local IP to connect such as the 127.0.0.1 then I can connect fine.
How can I resolve this issue, all I am trying to do is connect to this DB so that I can create new tables.
As shown below, after running the "rhc port-forward $appname" command, you would need to connect to the ip address of 127.0.0.1 and port that shows up next to it to connect to the service you want to reach, such as postgresql. In the below example, i would connect to 127.0.0.1, port 5432. If you already have something running locally on the postgresql port, it will select another port and display it in the table. But the connection will be forwarded to your openshift gear and postgresql on your gear.
Corey-Red-Hat:~ cdaley$ rhc port-forward rt2
Checking available ports ... done
Forwarding ports ...
To connect to a service running on OpenShift, use the Local address
Service Local OpenShift
---------- -------------- ---- ---------------
httpd 127.0.0.1:8080 => 127.7.74.1:8080
postgresql 127.0.0.1:5432 => 127.7.74.2:5432
Press CTRL-C to terminate port forwarding
You can refer to the OpenShift Developer Portal for more information about using the PostgreSQL cartridge here: https://developers.openshift.com/en/databases-postgresql.html