postmaster dead but pid file exists - ruby-on-rails

We have a rails 4 application with postgres
Sometimes our server hanged and if we reboot it .
The server gets started but it can not connect to postgres.
status shows postmaster dead but pid file exists
log shows
FATAL: lock file "/tmp/.s.PGSQL.5432.lock" already exists
HINT: Is another postmaster (PID 4696) using socket file "/tmp/.s.PGSQL.5432"?
LOG: could not bind IPv4 socket: Address already in use
and the postgresql could not restarted.
--- After deleting the /tmp/.s.PGSQL.5432 file and restarting the postgres service the service restarted but the postgres can not connect with host we added.
What can we do to fix this issue ?
Thanks in advance

Related

connection to server on socket failed postgres ubuntu

I'm trying to run postgres on ubuntu and it shows the following error
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
I have made research all through the internet yet to no avail. Any help would be highly appreciated

Unable to start postgresql server [could not bind IPv4 socket: Permission denied]

I am trying to start my PostgreSQL 9.4 database server on my local Windows machine via Ubuntu console. I'm running the command sudo service postgresql start, but I'm receiving the following error output:
The PostgreSQL server failed to start. Please check the log output:
2020-02-25 09:57:30.216 CST [497] LOG: could not bind IPv4 socket: Permission denied
2020-02-25 09:57:30.216 CST [497] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2020-02-25 09:57:30.217 CST [497] WARNING: could not create listen socket for "localhost"
2020-02-25 09:57:30.217 CST [497] FATAL: could not create any TCP/IP sockets [fail]
How do I check if another postmaster is already running on port 5432? If there is one, how would I stop it? Thank you!

PG Restore function not working on localhost

I'm trying to restore a backup to my localhost machine to review the data - so that I can actually make sure the backup is working. I'm using Heroku, postgres, and rails.
I clean installed the app, so there is no data in the localhost database. I ran db:reset, and db:migrate.
Here is the string I'm trying to use for pg_restore:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -p 3000 -U ian -d backup_production latest.dump
The error I receive says:
"connection to database "backup_production" failed: server closed the connection unexpectedly"
I've never had to do this before, so any help would be appreciated. I assume that development is what localhost uses (instead of test or production)?
I'm not sure what I'm missing, but I'll answer any question you may have.
Thanks a lot.
edit,. Here is a question, for this database string I assumed that I need to to use all the localhost information, because I created a backup using heroku capture/download. Am I wrong in that assumption? Should I instead be using the database name and port, etc, from the heroku credentials?
Turns out, I shouldn't have added the port. Removing -p 3000 , made this command work.
Try this
Edit the postgre configuration file typing in terminal
sudo gedit /etc/postgresql/POSTGRE_VERSION/main/pg_hba.conf
Then change your configuration to this
# Database administrative login by Unix domain socket
local all all trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
Restart your postgre server
sudo /etc/init.d/postgresql restart
This should be the solution to access without password

stop postgres processes from restarting - mac

I'm trying to run my rails projects but it keeps falling because it depends on postgres to be running. When I try to start postgres it keep saying its already running (or the port is taken). I checked activity monitor and there are ~6 postgres processes running, when I try to terminate/force-quit the processes, they just appear again...
not sure how to get around this issue.
actual error when running postgres -D /usr/local/var/postgres:
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
and when I try to stop postgres with pg_ctl -D /usr/local/var/postgres stop -s -m fast, I get this error:
pg_ctl: PID file "/usr/local/var/postgres/postmaster.pid" does not exist
Is server running?
I ended up starting from scratch:
uninstall postgres through homebrew (brew uninstall postgresql)
uninstall postgres though uninstaller (/Library/Postgresql/version/uninstall)
delete postgres through file system (delete the folder: /Library/Postgresql/)
then just do a homebrew installation:
brew install postgresql
and start postgres manually.
1:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
2:
brew services stop postgresql

host can not recognized in postgres

We have seen a issue in log
FATAL: lock file "/tmp/.s.PGSQL.5432.lock" already exists
HINT: Is another postmaster (PID 4696) using socket file "/tmp/.s.PGSQL.5432"?
LOG: could not bind IPv4 socket: Address already in use
We have deleted /tmp/.s.PGSQL.5432.lock
We restarted the postgres service the service restarted
But the psql -h localhost -d database -U newuser
shows error role 'newuser' does not exists
but if we connect without host
psql -d database -U newuser
It worked, How can We work with host options ?
Is there we ,missing somthing after deleting tmp file?
Same as the last one, you have two instances of PostgreSQL running on the machine.
You delete the socket file rather than shutting down the instance. This allows your second instance to start, but it's only listening on the unix socket. Presumably listen_addresses is unset/empty so it doesn't attempt to bind to a TCP/IP socket, since it'd fail if it tried and port 5432 was already in use.
The other instance is still running and still listening on port 5432 for TCP/IP connections. When you specify -h localhost you get a TCP/IP connection instead of the default unix socket connection, so you are connecting to the other instance of PostgreSQL on your system.
All your problems are caused by going around deleting and killing things rather than identifying the underlying problem - the second PostgreSQL instance - and addressing that.

Resources