Skip site navigation (1) Skip section navigation (2)

Novice! How to run pg_dump from within Java?

From: "Damian C" <jamianb(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Novice! How to run pg_dump from within Java?
Date: 2006-07-26 02:49:30
Message-ID: 2bbc8f530607251949r3dda6d3fudf6d57dd6a1d673a@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hello,

We have a Java project that is developing a small business app and
using Hibernate & Postgres for persistence.  It all works like a dream
until we need to know anything about Postgres!!  It is obviously a
"feather in the cap" of Postgres that "so many (Java developers) can
do so much while knowing so little".

I need to perform the world's simplest task: Create a pg dump from within Java.

Of course we do this easily using pgAdminIII, but I need to automate
it for our Users. I notice that pgAdmin uses a command line like this
...
<snip>
C:\Program Files\PostgreSQL\8.1\bin\pg_dump.exe -i -h localhost -p
5432 -U pgsuperuser -F c -b -v -f "D:\PG_26jul06.backup" devdb
</snip>

We use "ProcessBuilder" to launch the  "pg_dump.exe" program. It takes
an List of Strings in its constructor (including appropriate escape
characters) ...
<snip>
List<String> cmds = new ArrayList<String>();
cmds.add("C:\\Program Files\\PostgreSQL\\8.1\\bin\\pg_dump.exe");
cmds.add("-i");
cmds.add("-h");
cmds.add("localhost");
cmds.add("-p");
cmds.add("5432");
cmds.add("-U");
cmds.add("pgsuperuser");
cmds.add("-F");
cmds.add("c");
cmds.add("-b");
cmds.add("-v");
cmds.add("-f");
cmds.add("\"D:\\PG_26jul06A.backup\"");
cmds.add("devdb");
Process process = new ProcessBuilder(cmds).start();
</snip>

Now this DOES work in that pg_dump.exe is invoked, and a new file is
created at the correct location. However, the file size is zero
(instead of the pgAdminIII version that is 47K)

Any suggestions on what I'm doing wrong,
or any pointers for a better way to do this??

Many thanks,
-Damian

Responses

pgsql-novice by date

Next:From: operationsengineer1Date: 2006-07-26 05:00:22
Subject: Re: Installation "baby" steps (next steps)?
Previous:From: Sean DavisDate: 2006-07-26 02:22:56
Subject: Re: Installation "baby" steps (next steps)?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group