I am trying to backup a db of postgresql and I want to use pg_dump
command.
I tried :
psql -U postgres postgres-# pg_dump test > backup.sql
But I don't know where the output file goes.
Any help will be appreciated
You can export a PostgreSQL database to a file by using the pg_dump command line program, or you can use phpPgAdmin.
Google Cloud may be a good option to store your PostgreSQL backups and it offers different products to make this. It's not, however, necessary to have your PostgreSQL databases running there as you can use it only as a storage location.
The pg_dump command extracts a PostgreSQL database into a script file or another archive file. This utility is for backing up databases. The utility makes consistent backups even if the database is being used concurrently. Readers, writers, and other users won't be blocked from using the database while using pg_dump .
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).
I'm late to this party, but I feel that none of the answers are really correct. Most seem to imply that pg_dump
writes a file somewhere. It doesn't. You are sending the output to a file, and you told the shell where to write that file.
In your example pg_dump test > backup.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. This has nothing to do with pg_dump
but is a standard feature of shells like Bash or cmd.exe.
You used >
to redirect STDOUT to a file instead of the screen. And you gave the file name: "backup.sql". Since you didn't specify any path, the file will be in your current directory. This is probably your home directory, unless you have done a cd ...
into some other directory.
In the particular case of pg_dump
, you could also have used an alternative to the > /path/to/some_file
shell redirection, by using the -f some_file
option:
-f file
--file=fileSend output to the specified file. This parameter can be omitted for file based output formats, in which case the standard output is used.
So your command could have been pg_dump test -f backup.sql
, asking pg_dump to write directly to that file.
But in any case, you give the file name, and if you don't specify a path, the file is created in your current directory. If your prompt doesn't already display your current directory, you can have it shown with the pwd
command on Unix, and cd
in Windows.
Go to command prompt and directory postgresql\9.3\bin.
Example
.
.. c:\Program files\postgresql\9.3\bin> pg_dump -h localhost -p 5432 -U postgres test > D:\backup.sql ...
After above command enter User "postgres" password and check D:\
drive for backup.sql
file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With