Exporting data to a text-file

You want to export your database, its definitions or a single table to a text-file.

Solution

Use pg_dump with the relevant parameters. Use man pg_dump to find out what they are ref.

Discussion

Although you can use the \copy command to export a table, the pg_dump command-line tool is much more flexible. The man page gives full details, but some of the useful options are:

--data-only

--inserts (dumps as insert statements not tab-separated)

--schema-only