Thursday, May 26, 2011

Creation Date of PostgreSQL Database


Currently, Database creation date information is not stored in any one of the catalog tables.

There are two way's to find out::

1. Log the Create Database command to Database server log file

psql=# create database systest_live;

2. Get the time-stamp of the Database creation from Operating system and use the below shell script:

#!/bin/sh
# Identifying the Database Creation Date
# ./DB_Creationdate.sh $databasename

PGDATA=/export/raid/pgsql/data
PGHOME=/usr/local/bin

oid=$($PGHOME/psql -d $1 -t -c "select oid from pg_database where datname='systest_live';"|sed '/^$/d'|sed 's/^ //g') 
cmd="ls -ltr $PGDATA/base/$oid/PG_VERSION"
Date=$($cmd|awk '{print $6" "$7" "$8}')

echo "$1" Database Creation Date is :: $Date

No comments:

Post a Comment