How to find the database creation date in PostgreSQL

In this article, we will see how to find the database creation date in PostgreSQL in windows and Linux.

There are two ways to check the database creation date in PostgreSQL. One is by running query against pg_database view and other is by checking PG_VERSION in base directory of specific database.

1. Find the database creation date in PostgreSQL running query against pg_database:

SELECT (pg_stat_file('base/'||oid ||'/PG_VERSION')).modification, datname FROM pg_database;

How to find the database creation date in PostgreSQL

2. Get the oid of the database by running below command.

SELECT oid,datname FROM pg_database;

Then navigate to base directory which is there in data directory. Then go to oid directory. There we can find the PG_VERSION file.

Then run ls -ltrh PG_VERSION. PG_VERSION file date is the date of Database creation date.