I am trying to create a database backup using the command
pg_dump -U vdc(old db) | psql vdc_bak.sql(backup db);
What's wrong with the syntax here?
It tells "syntax error near 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).
Instead of exporting the database into a single file, pg_dump offers the option to dump it into a directory. In the following example, we are exporting the database dvdrental to the directory dvdrental-backup: If you need to make a complete backup of the PostgreSQL database server, then you can use pg_dumpall.
A root password is setup on your server. You will need to use pg_dump tool to backup a PostgreSQL database. This tool will dump all content of a database into a single file. The basic syntax to backup a PostgreSQL database is shown below: -U : Specify the PostgreSQL username. -W : Force pg_dump command to ask for a password.
Do not dump subscriptions. By default, pg_dump will wait for all files to be written safely to disk. This option causes pg_dump to return without waiting, which is faster, but means that a subsequent operating system crash can leave the dump corrupt.
You still don't show us the big picture, but the "syntax error" seems to indicate that you run that from within a SQL client tool (psql, pgAdmin, ...)
pg_dump
and psql
are commandline programs, not SQL statements.
You need to run them from the command prompt (aka shell)
Additionally the (old db) parameter is completely wrong. The database is not put into brackets for pg_dump, e.g:
pg_dump -U user1 dbname_old_db | psql -U user2 dbname_new_db
Again: you have to run this from the command prompt, not from within a SQL tool
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