Joyent

Translations of this page:

Backing up and restoring a PostgreSQL database

There are mainly two ways of backing up a PostgreSQL database: one is as a SQL script, and the other is in a binary format. If you don't need to tweak any record by hand for the migration, it is highly recommended (by the author of this entry, no less) to use the binary format, as it will speed things up and doesn't give encoding problems, and is necessary if you store blobs in the database. According to the docs, the restore procedure in virtualmin accepts either.

Backing up a PostgreSQL database

As far as I know, it is not possible to use virtualmin from the old FreeBSD shared servers to back up a PG database, so we must use the command line:

pg_dump --disable-triggers -Fc -b -v -U username database_name > database.dmp

The command will ask us for our database password and will dump the tables over the standard output, so we redirect it to a file.

Restoring a PostgreSQL database

This can be done from virtualmin in the shared accelerators. Just input the path to your file in the form field, or upload it from your desktop. Then adjust the couple of options that allow you to delete previous content and to just restore the schema, and you're done.

If you prefer to do it on the command line, here's the command:

pg_restore --disable-triggers -Fc -v -d database_name -U username -h localhost database.dmp

I'm not sure why, but I had to pass the -h switch or else it would try to connect to some unknown server. Remember that in the shared accelerators, your database name will be prefixed with your main domain username.

Also, if the username differs from the original, use the -O switch to ignore the warnings about objects' ownership.

 
shared/kb/backing-up-pg-databases.txt · Last modified: 2007/10/24 11:33 by victor
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki