Unix Technical Forum

pg_dump in PostgreSQL version 8.2 not working in Java app

This is a discussion on pg_dump in PostgreSQL version 8.2 not working in Java app within the pgsql Interfaces jdbc forums, part of the PostgreSQL category; --> Folks, I have an eclipse rcp application that includes backup capability by invoking pg_dump via Java ProcessBuilder. This has ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces jdbc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-16-2008, 12:32 AM
Michael Schmidt
 
Posts: n/a
Default pg_dump in PostgreSQL version 8.2 not working in Java app

Folks,
I have an eclipse rcp application that includes backup capability by invoking pg_dump via Java ProcessBuilder. This has been working fine with PostgreSQL 8.1 but quit working when I upgraded to 8.2. Nothing else has changed.

The parameters I pass to the ProcessBuilder via a String Array in my test case are:
[C:\Program Files\PostgreSQL\8.2\bin\pg_dump.exe, --host=localhost, --port=5432, -Upostgres, -W, --verbose, --format=custom, --file=E:\Backup\PostgreSQL\test.bak, npbase]

I've concatenated these parameters into a string and run it from the Command Prompt it works fine except, of course, you have to put "" around C:\Program_Files\...\pg_dump.exe.

The following snippet creates and starts the ProcessBuilder:
ProcessBuilder pb = new ProcessBuilder(cmdParms);
mainProc = pb.start();
// Put a buffered reader on stderr, where the PostgreSQL log is output
procReader = new BufferedReader(new InputStreamReader(mainProc.getErrorStream()));
// Set up a writer to output the password.
procWriter = new PrintWriter(mainProc.getOutputStream());

I then call a method that waits for the password: prompt by reading from the procReader and appending a StringBuffer. When password: is received, it sends the password.
do {
tempInt = procReader.read();
tempSB.append((char) tempInt);
if (-1 != tempSB.indexOf("Password: ")) {
procWriter.println(pwString);
procWriter.flush();
break;
}
} while (procReader.ready());

With 8.2, this job now hangs. I've spent several hours debugging and have found the following. First, pb.start() does not throw an exception, so it appears to be finding pg_dump.exe and trying to start it. It appears that procReader().lready() is always false and that the hang occurs in the do() loop.

Again, all of this worked fine with 8.1. Has something changed with pg_dump?

Michael Schmidt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-16-2008, 12:32 AM
Michael Schmidt
 
Posts: n/a
Default Re: pg_dump in PostgreSQL version 8.2 not working in Java app

Folks,
I've continued working on this problem and the plot thickens. I'm not even able to get output from psql.exe through Java. I ran the following simple test code:

// String[] parms = new String[] {"C:\\Windows\\System32\\ipconfig.exe", ""};
String[] parms = new String[]{"C:\\Program Files\\PostgreSQL\\8.2\\bin\\psql.exe","-Upostgres"};
File f = new File(parms[0]);
if (!f.isFile()) {
System.out.println("Error - this isn't a file");
}
ProcessBuilder pb = new ProcessBuilder(parms);
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("Exit with " + p.exitValue());

The ipconfig utility simply outputs the internet configuration. I used the "" String to simulate a parameter. This code identifies parm[0] as a valid file, outputs the configuration, and returns an exit code of 0, as it should. When I switch the parms (comment out the ipconfig String[] line and remove the comments from the psql.exe String[] line), the process hangs. So, with identical code, ipconfig works and psql hangs. What the hey? And again, this did not happen with 8.1.

Michael Schmidt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:48 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com