If I set some positive value for this variable, psql runs smoothly with any size of data. But unset that variable, and it gets killed. But it's nowhere written explicitly that psql can run out of memory while collecting the result set. Either the documentation or the behaviour should be modified.
Maybe somewhere in the future we should consider single row mode for psql, see