Postgres adapter backport

* From ActiveRecord 4.0
* Has path to allow hash of variables
* Allows increase in work_mem - vital for HashAggregate to be used instead of slower GroupAggregate