Miscellaneous
Backup
Use pg_dumpall to backup all databases
Use pg_dump to backup a database
| - | - |
|---|---|
-a |
Dump only the data, not the schema |
-s |
Dump only the schema, no data |
-c |
Drop database before recreating |
-C |
Create database before restoring |
-t |
Dump the named table(s) only |
-F |
Format (c: custom, d: directory, t: tar) |
Use pg_dump -? to get the full list of options
Restore
Restore a database with psql
Restore a database with pg_restore
| - | - |
|---|---|
-U |
Specify a database user |
-c |
Drop database before recreating |
-C |
Create database before restoring |
-e |
Exit if an error has encountered |
-F |
Format (c: custom, d: directory, t: tar, p: plain text sql(default)) |
Use pg_restore -? to get the full list of options
Remote access
Get location of postgresql.conf
Append to postgresql.conf
Append to pg_hba.conf (Same location as postgresql.conf)
Restart PostgreSQL server
Import/Export CSV
Export table into CSV file
\copy table TO '<path>' CSV
\copy table(col1,col1) TO '<path>' CSV
\copy (SELECT...) TO '<path>' CSV
Import CSV file into table
See also: Copy