Importing and exporting data
Before actually diving into backup and recovery, it is useful to take a general look at importing and exporting data from, and into, PostgreSQL. Understanding imports and exports is quite essential to get the overall idea of backups on a technical level.
Using the COPY command
When talking about imports and exports, there is really no way to do it without discussing the COPY
command. The COPY
command is the backbone of all the operations—it makes importing and exporting to the database very easy and offers a great deal of flexibility. Here is the syntax of this wonderful command:
test=# \h COPY Command: COPY Description: copy data between a file and a table Syntax: COPY table_name [ ( column_name [, ...] ) ] FROM { 'filename' | PROGRAM 'command' | STDIN } [ [ WITH ] ( option [, ...] ) ] COPY { table_name [ ( column_name [, ...] ) ] | ( query ) } TO { 'filename' | PROGRAM 'command' | STDOUT } [...