nothing is impossible!!!!

nothing is impossible!!!!

Monday, August 24, 2009

Postgresql backup and restore.

First method using pg_dump and second one is file system level backup.

Dump level Backup:
pg_dump dbname > outfile

Options available with pg_dump,
-h hostname. Default is localhost or whatever is set in PGHOST variable.
-p which port. PGPORT env.
-U username. default is logged in user name. PGUSER env.
outfile - name of the target file

Note:
pg_dump does not block other operations on the database while it is working. (Exceptions are those operations that need to operate with an exclusive lock, such as VACUUM FULL.)

Restore:
psql dbname < infile
infile - infile is what you used as outfile for the pg_dump command.

It is suggested to run analyze on each db to obtain the useful statistics. Run,
vacuumdb -a -z to VACUUM ANALYZE all databases;

pg_dump and psql can also use to dump a database directly from one server to another;
for example:
pg_dump -h host1 dbname | psql -h host2 dbname

2. File system level backup
tar -cf backup.tar /usr/local/pgsql/data
- Servers must be shutdown before taking backup.
- To restore database, we have to restore full database, can not do partial restore of tables or etc.

1 comment:

Unknown said...

It will definitely ease your work of handling a big project. As a project manager I use scrum in my projects. One of my friends referred me to use the Guide to Scrum Body of Knowledge by scrumstudy.com. I like the concepts of sprints, daily standup meetings, etc. the SBOK Helped me alot in Understanding how Agile Project Management works.