Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: dump and restore

Tags:

postgresql

I use EMS SQL Manager for PostgreSQL and I need to dump difficult database(domains, 300+ stored procedures/functions, triggers, data, etc). This tool cannot do it.

Please advice me good GUI tool for postgres.

like image 999
Dmitry Avatar asked Apr 26 '12 16:04

Dmitry


People also ask

What is dump in PostgreSQL?

pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers). pg_dump only dumps a single database.

How do I restore a PostgreSQL file?

In PostgreSQL, you can restore a database in two ways: Using psql to restore plain SQL script file generated by pg_dump and pg_dumpall tools. Using pg_restore to restore tar file and directory format created by the pg_dump tool.

Where do Postgres dumps go?

sql , which uses the plain or SQL format, the pg_dump command does not store any file anywhere. It just sends the output to STDOUT , which is usually your screen, and it's done. But in your command, you also told your shell (Terminal, Command prompt, whatever) to redirect STDOUT to a file.


3 Answers

You can always just use the command line utility.
Dump the cluster:

pg_dumpall -p 5432 > /path/to/my/dump_file.sql

Dump a single database:

pg_dump -p 5432 mydb > /path/to/my/mydb_dump.sql

Dump the schema only:

pg_dump -p 5432 mydb -s > /path/to/my/mydb_dump_schema.sql

More in the manual.

If you want to restore to an empty database, you might want to run before restoring:

DROP DATABASE IF EXISTS mydb;
CREATE DATABASE mydb;

The --clean option for pg_dump is not needed in this case.

like image 68
Erwin Brandstetter Avatar answered Oct 17 '22 06:10

Erwin Brandstetter


Backup your database no tool needed.we can do with terminal

All commands should be run as the postgres user.

 sudo su - postgres 

Backup a single database

pg_dump db_name > db_backup.sql

Restore a single database

psql db_name < db_backup.sql

Backup an entire postgres database cluster

pg_dumpall > cluster_backup.sql

Restore an entire postgres database cluster

psql -f cluster_backup.sql postgres

Refer this source for more commands backup commands

like image 35
Dinesh Pallapa Avatar answered Oct 17 '22 06:10

Dinesh Pallapa


pgAdmin3 will do the trick, it has pg_dump and pg_restore included in the installer.

like image 20
Frank Heikens Avatar answered Oct 17 '22 08:10

Frank Heikens