Once you connected using psql,

# \o  /tmp/myrecord.txt

Then run any SQL queries you want.  They wont be visible on screen But will be recored to /tmp/myrecord.txt

#  SELECT * FROM my_super_dummy_table;



I knew this before but couldnt recall it when I needed it…. so  I am posting it here……(credit goes to vhikida@inreach.com )

Problem : 

TABLE_A has columns x and y. You want to select duplicate rows from that table

Solution :

 select * from TABLE_A where (x,y) IN (SELECT x, y FROM TABLE_A m2 GROUP BY x,y HAVING COUNT(*) > 1)