title: How to backup a postgres database using java
body: <p>this is the code I am using to back up my database using pg_dump 9.3 in java.
  The problem I have is that always the result file is empty, and the exit code is 1, any ideas?</p>
  
  <pre><code>public static void backupDb() throws IOException, InterruptedException {
      Runtime rt = Runtime.getRuntime();
      Process p;
      ProcessBuilder pb;
      rt = Runtime.getRuntime();
      pb = new ProcessBuilder(
              "C:\\Program Files\\PostgreSQL\\9.3\\bin\\pg_dumpall.exe",
              "--host", "localhost",
              "--port", "5432",
              "--username", "postgres",
              "--no-password",
              "--format", "custom",
              "--blobs",
              "--verbose", "--file", "D:\\service_station_backup.backup", "service_station");
      p = pb.start();
      p.waitFor();
      System.out.println(p.exitValue());
  }
  </code></pre>