How to exit from query result viewer in psql?

Иван Петров picture Иван Петров · Dec 26, 2015 · Viewed 12.5k times · Source

First query:

database=# select * from table limit 1;
...
 |
(1 row)

(END)

I want to make a second query but I can't. ctrl+Z exits from psql. What can I press to exit only from result viewing?

Answer

andreas-hofmann picture andreas-hofmann · Dec 26, 2015

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.