48

what is wrong with this command:

pg_dump -U postgres -W admin --disable-triggers -a -t employees -f D:\ddd.txt postgres

This is giving error of too many command-line arguments

Bhargav Gor
  • 521
  • 2
  • 6
  • 7

9 Answers9

48

Looks like its the -W option. There is no value to go with that option.

-W, --password           force password prompt (should happen automatically)

If you want to run the command without typing is a password, use a .pgpass file. http://www.postgresql.org/docs/9.1/static/libpq-pgpass.html

Jim
  • 761
  • 4
  • 4
26

For posterity, note that pg_dump and pg_restore (and many other commands) cannot process long hyphens that word processors create. If you are cut-pasting command lines from a word processor, be sure it hasn't converted your hyphens to something else in editing. Else you will get command lines that look correct but hopelessly confuse the argument parsers in these tools.

johnkaplantech
  • 351
  • 4
  • 2
20

pg_dump and pg_restore need to ask password on commandline, if you put it command, they always give "too many command-line arguments" error. You can use below for setting related environment variable in commandline or batch file:

"SET PGPASSWORD=<password>"

so that you are not asked to enter password manually in your batch file. They use given environment variable.

Mustafa Kemal
  • 1,292
  • 19
  • 24
10

Instead of passing password with -W flag start with setting temporary variable for postgres:

PGPASSWORD="mypass" pg_dump -U postgres--disable-triggers -a -t employees -f D:\ddd.txt postgres
Bear
  • 1,017
  • 1
  • 10
  • 23
5

-W -> will prompt for a password to take full DB dump use some thing like

pg_dump -h 192.168.44.200 -p 5432 -U postgres -W -c -C -Fc -f C:\MMM\backup10_3.backup DATABASE_NAME
slavoo
  • 5,798
  • 64
  • 37
  • 39
Muthu
  • 51
  • 1
  • 1
5

I got this from copy-pasting, where 1 of the dashes were different.

Was: –-host= (first dash i a "long" dash) Corrected to --host= solved it

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
3

Additionally, if you don't want password prompt, use connection string directly.

pg_dump 'postgresql://<username>:<password>@localhost:5432/<dbname>'

So, combination with options in original question,

pg_dump 'postgresql://postgres:<password>@localhost:5432/postgres' --table='"employees"' --format='t' --file='D:\ddd.txt' --data-only --disable-triggers

Don't forget to use quotes when you have letter-casing issues

reference:

user14082
  • 311
  • 3
  • 10
1

Another option is to add ~/.pgpass file with content like this:

hostname:port:database:username:password

read more here

Szymon Rut
  • 835
  • 1
  • 9
  • 13
0

2021-11-30, pg v12, windows 10

pg_dump -U postgres -W -F t postgres > C:\myfolder\pg.tar

-U "postgres" as username,

-W to prompt for psd,

-F t means format is .tar,

> C:\myfolder\pg.tar is the destination path and filename

Jeb50
  • 6,272
  • 6
  • 49
  • 87