Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
My server is Debian 7 and I use PostgreSQL 9.3.
This is my hosts fileļ¼
root#localhost:/etc# cat hosts
127.0.0.1 localhost.localdomian localhost
127.0.1.1 virtualserver.com virtualserver
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
And when I want to startup a new console of psql:
root#localhost:/var/lib/postgresql/9.3/main# service postgresql restart
[ ok ] Restarting PostgreSQL 9.3 database server: main.
root#localhost:/var/lib/postgresql/9.3/main# sudo -u postgres psql
sudo: unable to resolve host localhost.localdomain
psql (9.3.0)
Type "help" for help.
You can see that the the machine can not find the localhsot.localdomain. But I changed the root files, and make it as correct in my /etc/hosts files and reboot it already.
Your /etc/hosts has a typo, it should be:
127.0.0.1 localhost.localdomain localhost
127.0.1.1 virtualserver.com virtualserver
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
localdomain was spelled localdomIAn.
Related
I have a Docker container with Redmine. I run it and it works, except the fact that it doesn't connect to the host's database.
I've searched for all similar questions, and tried what was suggested everytime, but it doesn't work.
Here is how I run the container:
docker run -d --name redmine-4.2.5 -e REDMINE_DB_POSTGRES=172.17.0.1 -e REDMINE_DB_PORT=5432 -e REDMINE_DB_USERNAME=redmine -e REDMINE_DB_PASSWORD=XXX -e REDMINE_DB_DATABASE=redmine -e REDMINE_NO_DB_MIGRATE=1 --add-host=database:172.17.0.1 redmine
When I enter the container and try to connect manually I have this:
root#86a42eae3adf:/usr/src/redmine# psql -U redmine -h database
psql: error: could not connect to server: Connection refused
Is the server running on host "database" (172.17.0.1) and accepting
TCP/IP connections on port 5432?
When I check the open ports, I have this:
root#86a42eae3adf:/usr/src/redmine# nmap 172.17.0.1
Starting Nmap 7.80 ( https://nmap.org ) at 2022-04-02 16:33 UTC
Nmap scan report for database (172.17.0.1)
Host is up (0.000024s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
111/tcp open rpcbind
8080/tcp open http-proxy
MAC Address: XXXX (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.25 seconds
So I checked the configuration on my host, and I have everything correct:
pg_hba.conf has this line:
host redmine redmine 172.17.0.0/16 trust
And postgresql.conf has this one:
listen_addresses = '*'
(I know I shouldn't put '*' but I'll limit to 172.17.0.2 when it will work for '*')
I restarted postgresql and reloaded the config, up to no avail.
I have no clue on how to investigate to see what I should modify to have my container be able to contact the host on port 5432. I'm open (on all ports) to any suggestion.
Thanks in advance.
I have read several SO questions revolving the same question, but due to insufficient points, I cannot comment on existing questions. Therefore, I must spawn my own question thread regarding docker-compose and links.
I was under the impression that having the following in a docker-compose file would add 'db' to my container's hostfile
web:
links:
- db
I was thinking that my web code could establish a db connection with something along the lines of
db := sql.Open("postgres", "user=foo dbname=baz host=db")
where hostname db exists in my web container's /etc/hostfile and therefore resolves to some address that reaches the db container.
My web application does not resolve to the address where my db is running, instead it resolves to an address (172.19.0.3) and I cannot figure out where it has come from or how to fix.
docker exec $WEB_CONTAINER_ID cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.19.0.2 6f52f9e78f00
I was expecting to see an entry for db. Furthermore:
docker exec $WEB_CONTAINER_ID nslookup db
Name: db
Address 1: 172.19.0.3 apiserver_postgres_1.apiserver_default
What am I misunderstanding? How do I enable my web code to resolve my db address?
This is no longer your classic docker 1.8 or less "link", especially if you are using version 2 of docker-compose.yml file.
As mentioned in issue 3002:
version:"2" creates a bridge network by default for your project. If you run docker network ls you'll see a new bridged network where your project containers will be created. (which makes totally sense)
Docker itself has removed these variables from links on any network except for the old bridge network.
There is now an embedded DNS.
There are similar questions but nothing worked for me. I have already added this line to my pg_hba.conf:
host all all all trust
And this one to my postgresql.conf:
listen_addresses = '*'
My networking settings in the Vagrantfile are:
config.vm.network "private_network", ip: "10.0.0.0"
config.vm.network :forwarded_port, guest: 3000, host: 3000, auto_correct: true
When I try to connect from the host, I get:
$ psql -h 10.0.0.0 -U <username> -d <database>
psql: could not connect to server: Permission denied
Is the server running on host "10.0.0.0" and accepting
TCP/IP connections on port 5432?
The same command from the guest works with no problems. What am I missing??
[UPDATE]
I changed the private network ip to "192.168.1.77" (got it from a working example) and it worked. Still don't know why 10.0.0.0 wasn't good though, since it is in the reserved private address space, so I'll leave the question unanswered.
You need to forward the postgres port, you're only forwarding 3000, not 5432.
I believe the reason you could not connect is that technically 10.0.0.0 is the network address of the range 10.0.0.0/8 (and 10.255.255.255 is the broadcast address and should also not work). The first address of each range is the network address and is not allowed to be a routable host (similarly 192.168.0.0 should fail in the same way since it's a 16-bit block).
In addition to forwarding port 5432 to another port on my host machine in my Vagrantfile, I added the following to my pg_hba.conf file in my vagrant machine, restarted postgresql, and it finally allowed me to connect from the host:
host all all 0.0.0.0/0 md5
I found the suggestion here: https://github.com/laravel/framework/issues/11339
This question already has answers here:
Connection refused (PGError) (postgresql and rails)
(6 answers)
Closed 9 years ago.
I am trying to connect postgresql but I am getting this error.
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
My pg_hba.conf file is like this.
TYPE DATABASE USER CIDR-ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
I would be much obliged if anyone please be so kind enough to explain whats hoing on here and how should I correct it.
The error you quote has nothing to do with pg_hba.conf; it's failing to connect, not failing to authorize the connection.
Do what the error message says:
Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections
You haven't shown the command that produces the error. Assuming you're connecting on localhost port 5432 (the defaults for a standard PostgreSQL install), then either:
PostgreSQL isn't running
PostgreSQL isn't listening for TCP/IP connections (listen_addresses in postgresql.conf)
PostgreSQL is only listening on IPv4 (0.0.0.0 or 127.0.0.1) and you're connecting on IPv6 (::1) or vice versa. This seems to be an issue on some older Mac OS X versions that have weird IPv6 socket behaviour, and on some older Windows versions.
PostgreSQL is listening on a different port to the one you're connecting on
(unlikely) there's an iptables rule blocking loopback connections
(If you are not connecting on localhost, it may also be a network firewall that's blocking TCP/IP connections, but I'm guessing you're using the defaults since you didn't say).
So ... check those:
ps -f -u postgres should list postgres processes
sudo lsof -n -u postgres |grep LISTEN or sudo netstat -ltnp | grep postgres should show the TCP/IP addresses and ports PostgreSQL is listening on
BTW, I think you must be on an old version. On my 9.3 install, the error is rather more detailed:
$ psql -h localhost -p 12345
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 12345?
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am having problem with connect with database from outside server. I read a lot of topics about of this subject. And nothing...
Postgresql 8.4 / Debian
My /etc/postgresql/8.4/main/postgresql.conf:
listen_addresses = '*'
port = 5432
max_connections = 100
My /etc/postgresql/8.4/main/pg_hba.conf:
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
host all all 0.0.0.0/0 trust
netstat -nlp | grep 5432
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 6520/postgres
tcp6 0 0 :::5432 :::* LISTEN 6520/postgres
unix 2 [ ACC ] STREAM LISTENING 15338180 6520/postgres /var/run/postgresql/.s.PGSQL.5432
telnet localhost 5432
Trying 127.0.0.1...
Connected to localhost.localdomain.
But when I try connect from my computer I always get "Failed to establish a connection to".
Any idea what I am doing wrong ? :/ Thanks for yours help :)
Did you disable the firewall on the server on which postgres is running?
If not, disable and test. If you are able to connect after the firewall is disabled, you need to open the port 5432 in your firewall.
Check the obvious like IPTABLES, ensure this is not running:
iptables -L
http://wiki.debian.org/iptables
If it's running and the default rules are in place, then this could cause issues.