http://www.thegeekstuff.com/2009/04/15-practical-postgresql-database-adminstration-commands/ Similar to the Linux ~/.bash_history file, postgreSQL stores all the sql command that was executed in a history filed called ~/.psql_history as shown below. $ cat ~/.psql_history alter user postgres with password 'tmppassword'; \h alter user select version(); create user ramesh with password 'tmppassword'; \timing select * from pg_catalog.pg_attribute;