How to exit from query result viewer in psql?
Hit q. This closes many vim-like views, not only in psql, but also e.g. in 'less', 'git log', 'mutt', and many more.
Just FYI: Hitting Ctrl + Z does not exit psql, it just suspends it and sends it to background. The program continues to run, and you can resume it by entering 'fg'. In Unix environments, Ctrl + C is usually the way to forcibly stop a program.