I am very new to PostGIS. I read that it should work faster than QGIS, so I thought I'd give it a go. I want to completely dissolve a shapefile of 1.2m polygons in the same way as QGIS built in dissolve function works.
This is my current code, which is very basic (filetodissolve is the table):
SELECT ST_Union(geom)
FROM filetodissolve f;
I've been running this for 1h 30m now and is showing no sign of stopping. Is there any method to speed this up.

ST_Buffer(St_Collect(wkb_geometry), 0)in some old comment. That might also be worth trying. UsingSET work_mem=50000;for giving more memory was also suggested. If you test with 10000 or 100000 features you will get preliminary results faster. – user30184 Feb 02 '23 at 15:55