1

in my Java Application i start a postgres process to backup my database.

 Thread thread = new Thread(() ->{
 Process p;
 try{
 p = Runtime.getRuntime().exec("cmd /c pg_dump -v -a -d "+database+" -h "+server+" -p "+port+" -U "+user+" -n public > " + file.getPath());
 p.waitFor();
 }catch(Exception e){
 return false;
 }
 });

This works and the backup File was created. But the File size is 0KB while my Application is running. After i close the Java App - the backup file have its normal size.

I dont get it where the Problem is

asked Feb 7, 2018 at 11:21
1
  • Please elaborate more your problem Commented Feb 7, 2018 at 11:25

2 Answers 2

1

I am sorry but its hard to me to explain this right.

in my application i try to create a Database dumpfile using pg_dump from PostgreSQL. If i start the dump process then the file will be create after i close the whole application.

i hope i explain it understandable

i tried to predefine the path to file. but it was the same error. I also used the ProcessBuilder intead.

The Problem was that i used the -v Option in the pg_dump command. Without this Option it works fine and the file will be created immediately.

It is option for verbose output. Here is my final Method which works fine:

 Process process = new ProcessBuilder("pg_dump", "-a", "-d", database, "-h", server, "-p", port, "-U", user, "-f", file.getPath()).start();
 process.waitFor();
answered Feb 13, 2018 at 14:00
Sign up to request clarification or add additional context in comments.

Comments

0

I am guessing that it probably has something to do with the file and the way you handle it (my guess is based on file.getPath() in your code).

However, you haven't posted the whole code ... So, The the only thing I can do is guess.

Try the same code with predefined file name (lets say c:\\myfilename.dmp).

e.g. p = Runtime.getRuntime().exec("cmd /c pg_dump -v -a -d "+database+" -h "+server+" -p "+port+" -U "+user+" -n public > c:\\myfilename.dmp"

How does it behave ?

answered Feb 7, 2018 at 11:57

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.