Fixed the psql queries for gathering statistics.