error query did explode the postgres database
Limiting is hard, but you can set a timeout on query for a user :

ALTER ROLE &lt;user&gt; SET statement_timeout TO '60s';


As of the disk I'm not aware of any technique to limit disk usage of a query in postgresql.