Before anything, please note that I have found several similar questions on Stack Overflow and articles all over the web, but none of those helped me fix my issue:
I often encounter this problem on windows,the way I solved the problem is Service - Click PostgreSQL Database Server 8.3 - Click the second tab "log in" - choose the first line "the local system account".
run postgres -D /usr/local/var/postgres
and you should see something like:
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 379) running in data directory "/usr/local/var/postgres"?
Then run kill -9 PID
in HINT
And you should be good to go.
If you want to restart Postgresql on Linux, then you have to use the following command.
/etc/init.d/postgresql restart
First I tried
lsof -wni tcp:5432 but it doesn't show any PID number.
Second I tried
Postgres -D /usr/local/var/postgres and it showed that server is listening.
So I just restarted my mac to restore all ports back and it worked for me.
I resolved the issue via this command
pg_ctl -D /usr/local/var/postgres start
At times, you might get this error
pg_ctl: another server might be running; trying to start server anyway
So, try running the following command and then run the first command given above.
pg_ctl -D /usr/local/var/postgres stop
For Docker users: In my case it was caused by excessive docker image size. You can remove unused data using prune
command:
docker system prune --all --force --volumes
Warning: as per manual (docker system prune --help
):
This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache