Postgresql – Number of times PostgreSQL database restarted

postgresqlpostgresql-9.1

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?

Best Answer

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