The system does not have a built-in record about the time the PostgreSQL database was created. All approaches based on the creation / modification time of the file system may cause incorrect responses.
For example, if you are a pg_basebackup replica node, then go to it, the creation time will be displayed as the replica creation time. pg_basebackup does not save file creation / modification time, since they are usually not considered relevant for the operation of the database system.
The only reliable way to get the database creation time is to create a table with 1 row with the creation time in it when creating the database, then set permissions / add a trigger so that it rejects updates.
If you are not opposed to the risk of a wrong answer when the creation time is reported as much newer than it actually was, you can look at the timestamp of the base/[dboid]/PG_VERSION . @Bob showed a useful way to do this .
Craig Ringer
source share