In general, it seems there are roughly five (5) ways to get "file data" (e.g. a GeoTIFF) out of a PostGIS geoprocessing workflow:
- Export just the raster field as an ASCII grid
- Connect to the database using a desktop client (e.g. QGIS) [1]
- Use a procedural language (like PLPGSQL or PLPYthon) [2]
- Use the COPY declaration to get a hex dump out and convert it to a binary file
- Fill a 2D NumPy array with a byte array and serialize it to a binary file using GDAL or psycopg2 [3, 4]
- Use ST_AsTiff() or the more general ST_AsGDALRaster() to get a byte array, which can be written to a binary file