Previously:
>psql ids -c 'select src,dst,count(*) from brick* where src_port=135
>group by src,dst' > /tmp/135.dat
This is just a guess, increasing the parameters shared_buffers and sort_mem
might help.
For example if your table is about 1Gb in size then try shared_buffers=10000
and sort_mem=20000 ( you need an extra 100Mb ram for this )
Cheers
Mark