pgsql2shp is a command-line tool that can be used to output PostGIS data into shapefiles. Similarly to outgoing \COPY, it can either export a full table or the result of a query, so this gives us flexibility when we only need a subset of data to be outputted and we do not want to either modify the source tables or create temporary, intermediate ones.