Backup & Restore PostgreSQL databases

pg_dump is used to backup a PostgreSQL database ( data + schema )

The following command will backup the database pgdb0 that belongs to the local PostgreSQL server user pguser0 to a compressed file pgdb0.dump.gz

g0:~$pg_dump -o -U pguser0 -h localhost pgdb0 |gzip > pgdb0.dump.gz

If you are not using foreign keys you can ommit the -o flag
ref:PostgreSQL 8.4.9 Documentation Dump

And to restore pgdb0
n:~$gunzip pgdb0.dump.gz
n:~$psql -U pguser0 -h localhost < pgdb0.dump

Backup and Restore PostgreSQL DBs