How to get how many times my PostgreSQL database restarted and how to get each restart time?
I do not want to get the details from the log file. Is there any other way to get those details?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityHow to get how many times my PostgreSQL database restarted and how to get each restart time?
I do not want to get the details from the log file. Is there any other way to get those details?
Based on the pg_log
or any PG log files, using grep
to match how many times of shutting down the database.
grep -rwn postgresql-2018-04-12.log -e "database system is shut down"
The output looks like as below
postgresql-2018-04-12.log:9:2018-04-12 16:07:25 CEST LOG: database system is shut down postgresql-2018-04-12.log:18:2018-04-12 16:08:18 CEST LOG: database system is shut down
Just head to log director of postgresql on which all restart session are logged in default directoy
cd /var/log/postgresql/
Now grep the log file with the below command to know when database was shutdown
grep "shutdown" postgresql-9.1-main.log
grep the log file with the below command to know when database was started
grep "starting" postgresql-9.1-main.log