>> Maybe this is an obviously dumb thing to do, but it looked reasonable to
>> me.
>
> Looks reasonable here too - except I'm not sure what I'd do with 2
> million rows of sorted table in my console. I'm guessing you're piping
> the output into something.
Probably it's psql that is choking from buffering the rows.
If you want to fetch that huge amount of data into a user application, a
CURSOR is the best way to do so.