0

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?

1
  • 1
    A restart doesn't generate a new log file. You'll have to read them all. Commented Apr 12, 2018 at 9:34

2 Answers 2

1

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

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.