5

For Postgres is there any sort of command line utilities that allow a database to be "dumped to a file" and that allow that same database dump to be imported?

I know this can be done through PGAdmin, but I need to be able to do this on the cmd line.

sth
  • 222,467
  • 53
  • 283
  • 367
mainstringargs
  • 13,563
  • 35
  • 109
  • 174
  • Did you try the `psql` tool which ships with the server? – Dirk Feb 22 '10 at 20:47
  • If anyone want Export/Import for whole DB then look at [Export and Import of PostgresSQL using pgAdmin III](http://stackoverflow.com/a/39167526/1045444) – Somnath Muluk Aug 26 '16 at 13:32

2 Answers2

6

Yeah, take a look into pg_dump and pg_restore

http://www.postgresql.org/docs/current/static/app-pgdump.html

http://www.postgresql.org/docs/current/static/app-pgrestore.html

Kenaniah
  • 5,171
  • 24
  • 27
  • 2
    Thanks but you could have given a simple example (one line of code for `pg_dump` and another for `pg_restore`), that would have been much more helpful – ericn Aug 19 '15 at 08:59
  • 1
    `pg_restore -U postgres -W -d dvdrental /tmp/dvdrental.tar` -U is username -W is password (not put password in this line, it will appear a promt) -d is database and finally specify path of file – Pentux Nov 25 '15 at 10:30
1

Correct, the way to do this is the pg_dump, pg_dumpall and pg_restore commands. In fact, I think pg_admin actually calls those commands itself. It doesn't actually have backup/restore built in but is just a wrapper.

Joshua D. Drake
  • 1,026
  • 5
  • 6