1

I want to use a PostgreSQL db for backup using java. I've tried with the below code but I am getting:

error pg_dump: too many command-line arguments (first is " postgres") Try "pg_dump --help" for more information.

Runtime r = Runtime.getRuntime();
Process p;
ProcessBuilder pb;
r = Runtime.getRuntime();
pb = new ProcessBuilder( 
        "/usr/pgsql-9.3/bin/pg_dump",
        "--host", "localhost",
        "--port", "5432",
        "--username", "postgres",
        "--dbname", "postfixdb",
        "--role", "postgres",
        "--password"," postgres",
        "--verbose",
       "/usr/pg_dump.backup");
pb.redirectErrorStream(true);
p = pb.start();
InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String ll;
while ((ll = br.readLine()) != null) { System.out.println(ll); } 

1 Answer 1

1

Consult the psql documentation for the invocation syntax and a list of allowed options.

Try to run it on the command line first, and only when that succeeds, try to run it from Java.

A list ob obvious mistakes:

  • The option for “user” is -U (capitalized).

  • -p is for the TCP port number.

  • There is no -B option.

  • There is no -r option.

Sign up to request clarification or add additional context in comments.

3 Comments

I tryed this same code in windos for mysql, in their this code is working but here not. these both having different syntax?
Yes, because they are different programs. MySQL is not the same as PostgreSQL.
Bro, I tryed this new code here creating backup file but empty and line reader not executing. only upto "aaaa" printing in console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.