I recently installed postgresql on my ubuntu 14.04 vm, but I can't seem to be able to connect to my database from localhost: postgres://127.0.0.1:5432/mydb?sslmode=disable is not found, although psql mydb brings me to the correct terminal, sudo netstat -plunt |grep postgres returns nothing, but su postgres -c "netstat -plunt |grep postgres" prints:
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 31/postgres
tcp6 0 0 ::1:5432 :::* LISTEN 31/postgres
So it's clearly there, just somehow under the postgres ubuntu user (but with the database belonging to root). I know that there is a way to reconfigure my postgresql installation such that it can be reached through localhost (postgres://127.0.0.1:5432/mydb?sslmode=disable works), and if anyone could tell me what I need to do, that would be awesome. Thank you!
Related
I used to be able to run docker-compose using 5432:5432 port mapping, but am recently getting this error:
Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use
I've gone through all of the older posts relating to this issue but have yet to be able to solve this.
I've been driving myself mad with this error for the past week trying to figure out how to stop whatever process is running with no avail.
I've tried running
lsof -i tcp:5432
which returns no results (as long as my pgadmin/server is not running)
I've also seen other posts mention running
netstat -anp tcp | grep 5432
which does return two lines:
tcp4 0 0 *.5432 *.* LISTEN
tcp6 0 0 *.5432 *.* LISTEN
But I'm not entirely sure what to do with that output?
Run lsof -i tcp:5432 with sudo rights:
sudo lsof -i tcp:5432
A process (very likely PostgreSQL) is listening on port 5432, preventing another to listen on that port. Stop the process, e.g. with systemctl, then you will be able to start your docker PostgreSQL.
There is a possibility that this might be happening due to multiple instances of postgres running on your machine.
In my case, I had previously installed postgres which was always running on the machine because of which docker-based postgres was unable to start due to the above error. Uninstalling previously installed postgres helped to resolve the issue.
I'm struggling to enable remote access for Postgres DB version 9.6 on MacOS Sierra.
What I have done so far:
modify postgres.conf, set listen_addresses = "*"
modify pg_hb.conf, add these lines:
host all all 0.0.0.0/0 md5
host all all * md5
I checked the Firewall setting (GUI), and see the postgres process is allowing incoming connections.
From PgAdmin tool running on the macOS machine, I can use the ip of macOS machine to connect to the PG database.
The result of running netstat -an | grep 5432:
tcp4 0 0 *.5432 . LISTEN
tcp6 0 0 *.5432 . LISTEN
d06ae6d89823b48f stream 0 0 d06ae6d89b32fcb7 0 0 0 /tmp/.s.PGSQL.5432
However, I couldn't access to the PG database from another machine in same wifi network. (I can ping the ip of the PG database machine).
Any idea of suggestion is highly appreciate.
Thanks.
I have followed all the advice I've found online, but I can't seem to get this to work.
Background:
I have setup Postgresql 9.6 on a server running RHEL 6.8. I am trying to remotely connect to this server's Postgresql service from a client running Linux Mint 17.3.
What I've tried:
1) In postgresql.conf, I added these two lines:
listen_addresses = '*'
port = 5432
2) In pg_hba.conf, I added this line:
host all all 0.0.0.0/0 md5
3) Restarted postgresql server afterwards:
service postgresql-9.6 restart
4) Added rule to firewall to allow connections to port 5432 just in case:
iptables -A INPUT -s 0/0 -p tcp --dport 5432 -j ACCEPT
5) Ran netstat -tulpn | grep 5432 and got this output:
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 2625/postmaster
tcp 0 0 ::::5432 :::* LISTEN 2625/postmaster
Here is the command I ran to connect to my server from the client:
psql -h my_host_name -d my_database_name -U postgres
And I got the following output:
psql: could not connect to server: Connection timed out
Is the server running on host "my_host_name" (my_ip_address) and accepting
TCP/IP connections on port 5432?
Question:
What else can I do to further troubleshoot this issue?
Turns out there was another firewall on our network that I wasn't taking into account. To anybody else dealing with this issue, make sure that you are absolutely sure that you are not dealing with a firewall.
I've been struggling to fix this solution. I've followed multiple guidelines none of them seem to work for me..
So I open PostGres app from my applications folder
It throws following error in the log
FATAL: could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
LOG: database system is shut down
I tried removing the following folder however it says the PGSQL.5432.lock file does not exist. I've done my research and none of them seem to be working for me!
I also tried running psql
psql: could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Threw me that error.
In psql if you didn't specify the user and run psql all alone, psql will take the current user of your system like :
[root#bdd ~]# psql
psql will take root as user.
So you need to tell psql which user to log with :
[root#bdd ~]# psql -U postgres
as you can see postgres is the default user if you didn't change it during installation.
If the problem maintain you need to find which port postgresql is using (you might change it during installation )
run :
[root#bdd ~]# netstat -tulpn | grep postgres
you will find something like this :
tcp 0 0 0.0.0.0:5533 0.0.0.0:* LISTEN 20856/postgres
tcp6 0 0 :::5533 :::* LISTEN 20856/postgres
In my case the port is 5533 so i need to do this :
[root#bdd ~]# psql -U postgres -p 5533
I was previously running the Docker container for my web application below:
echo Starting postgres container...
docker run -d -p 5432:5432 --name db my_db
echo Postgres container started
echo Starting memcached container...
docker run -d -p 11211:11211 --name mem memcached
echo Memcached container started
echo Starting web container...
docker run -d -p 8000:8080 --name web --link db:postgres --link mem:memcache my_web_app
echo Web container started
echo Waiting for tomcat to initialize...
sleep 5
echo curling logon.jsf
curl http://111.111.11.111:8000/app/logon.jsf #Real URL redacted
echo Application started
Which became the below docker-compose script:
version: '2'
services:
web:
image: tomcat:7.0.69-jre8
build: ./ci
ports:
- "8000:8080"
depends_on:
- db
- mem
db:
image: postgres:9.4.7
build: ./db
ports:
- "5432:5432"
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
mem:
image: memcached
ports:
- "11211:11211"
When I launch the container, it seems like postgres is no longer running (Connection refused, netstat -al | grep postgres doesn't show it), and thus, the app doesn't work. I reviewed the change I have made, and realized that the docker-compose.yml has no analog for the tomcat sleep and curl command I had given in the run script - should it? I couldn't find any information online regarding a proper analog. Is something else potentially afoot here? Please advise if any further details are required.
EDIT: docker ps yields:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a942be02fc22 tomcat:7.0.69-jre8 "catalina.sh run" 5 minutes ago Up About a minute 0.0.0.0:8000->8080/tcp memcachedocker_web_1
fd6074cf8ec9 postgres:9.4.7 "/docker-entrypoint.s" 5 minutes ago Up About a minute 0.0.0.0:5432->5432/tcp memcachedocker_db_1
ce18771fee28 memcached "/entrypoint.sh memca" 5 minutes ago Up About a minute 0.0.0.0:11211->11211/tcp memcachedocker_mem_1
and the logs for the container:
Success. You can now start the database server using:
postgres -D /var/lib/postgresql/data
or
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....LOG: database system was shut down at 2016-06-01 13:09:23 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
done
server started
CREATE DATABASE
CREATE ROLE
/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
CREATE DATABASE
LOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
waiting for server to shut down....LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
LOG: database system was shut down at 2016-06-01 13:09:25 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
and thus inside the container, :
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.11:44095 0.0.0.0:* LISTEN
tcp 0 0 172.18.0.4:38868 132.246.2.23:80 TIME_WAIT
tcp 0 0 172.18.0.4:36424 5.153.231.35:80 TIME_WAIT
tcp6 0 0 127.0.0.1:8005 :::* LISTEN
tcp6 0 0 :::8009 :::* LISTEN
tcp6 0 0 :::8080 :::* LISTEN
tcp6 0 0 172.18.0.4:47522 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47518 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47524 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47520 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47516 172.18.0.2:11211 ESTABLISHED
tcp6 0 0 172.18.0.4:47514 172.18.0.2:11211 ESTABLISHED
udp 0 0 172.18.0.4:48360 10.0.2.3:53 ESTABLISHED
udp 0 0 127.0.0.11:40276 0.0.0.0:*
We can see that the memcached container is up and running, however postgres is absent. The only thing running on the localhost interface is bound to 8005, and it isn't postgres. I should add finally that I am able to telnet memcached on its port from the web container and confirm its operation, however I can't do the same with postgres, and I'm not sure why.
There are a number of things that can probably be removed from your
docker-compose.yml file, assuming that the database and memcached
services are dedicated to your web application (that is, they don't
need to be accessed from anywhere else).
It doesn't make sense to specify both image and build in a service
definition, so I've made a few assumptions about what you actually
want.
I would start with something like this:
version: '2'
services:
web:
build: ./ci
ports:
- '8000:8080'
depends_on:
- db
- mem
db:
image: postgres
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
mem:
image: memcached
You don't need ports directives for either the db or mem
services, because you don't need to expose these services to your host
(or elsewhere). A docker container can access services on another
container on the same network without any special directives.
Within the web container, you can access either the db or mem
container by name, because this is how newer versions of Docker
operate when using a non-default network: Docker creates an internal
DNS service and registers the container names there. So, for example,
from inside the web container I can use the psql command line
postgresql client to connect to the database server like this:
$ docker exec -it myservice_web_1 sh
web_1# psql -h db -U admin
Password for user admin:
psql (9.4.6, server 9.5.1)
WARNING: psql major version 9.4, server major version 9.5.
Some psql features might not work.
admin=#
You would configure your web application to access the database server
at host db, port 5432.
With this environment up and running, you could connect to your web service from your host at http://localhost:8000, or from either your host or another host on the network at http://<your_hostname_or_ip_here>:8000.