Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL pg_dump [closed]

Tags:

postgresql

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"

like image 297
user1202766 Avatar asked Feb 21 '12 18:02

user1202766


People also ask

What is PG_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).

How to dump a PostgreSQL database to a directory?

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.

How to backup a PostgreSQL database?

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 in PostgreSQL?

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.


1 Answers

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

like image 101
a_horse_with_no_name Avatar answered Sep 30 '22 02:09

a_horse_with_no_name