CSV logging

Another way to avoid multiline query issues is to use CSV logging, added to PostgreSQL in version 8.3. This logs every statement in a delimited fashion that clearly marks line breaks so that multiline queries can be imported without a problem into tools. You can even import these logs files into the database for analysis; the documentation at http://www.postgresql.org/docs/current/static/runtime-config-logging.html shows a sample table for that purpose in the Using CSV-Format Log Output section.

Note that format of the CSV output fields and therefore the sample table changed in 9.0 (application_name was added) compared with 8.3/8.4. Make sure you're using the right table definition for your version, or COPY will complain that ...

Get PostgreSQL 10 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.