Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a system running over Tomcat which executes a backup batch job every day, it calls pg_dump.exe from Java and stores its output to an SQL file.

When I'm executing Tomcat from the shell, it works perfectly, but when I start Tomcat as a Windows service the pg_dump.exe process stays there doing nothing, the SQL file is never written and the dump is never performed.

Is there any additional parameter or configuration required for Windows services? because it works without problems on a Unix-box.

Update: I'm using a Java class to call the operation.

Process p = new ProcessBuilder(
          "-U", "myuser",
          "-h" , "localhost",
storeToFile( p.getInputStream() );


  • Tomcat 7.0.23
  • Postgresql 9.1
  • Windows 2008
share|improve this question
How do you call pg_dump.exe? The parameters passed to it and possibly the caller environment would be interesting. From what you described so far, it can be anything (waiting for password is a usual suspect). – dezso Dec 10 '12 at 21:04
I thought that too, but why does it work without problems when I execute Tomcat from a shell? ...strange... – Timoteo Ponce Dec 10 '12 at 21:10
One thing I can think of is running from the application it does not see a variable that is present in the shell. – dezso Dec 10 '12 at 21:21
Aha! I see your point, the PGPASSWORD value might not be assigned. Let me check it. – Timoteo Ponce Dec 10 '12 at 21:24
You were right, the solution is here How to run pg_dump from java – Timoteo Ponce Dec 10 '12 at 21:44

dezso was right, the PGPASSWORD environment variable is present when executing Tomcat from a single shell, but not when it's started as a service. The solution is to put the value in the process environment:

 ProcessBuilder builder = new ProcessBuilder(
      "-U", "myuser",
      "-h" , "localhost",

 Map<String, String> env = builder.environment();
 env.put("PGPASSWORD", "supersecret");

 Process p = builder.start();
 storeToFile( p.getInputStream() );

Solution source is here: How to pg_dump from Java

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.