Restore PostgreSQL database using java -


im using following code restore postgresql database using java

 runtime r = runtime.getruntime();  process p;  string cmd ="d:/program files/postgresql/9.1/bin/pg_restore.exe --host localhost --port 5432 --username postgres --dbname mytestqq --role postgres --no-password  --verbose d:\sathish\rawdatabase.backup";  p = r.exec(cmd); 

i have 42 tables in rawdatabase.backup file 1 table getting restored why rest of tables not happening whats wrong in code? in advance!!!!

it's surprising command show works @ all, since you're failing quote spaces in command path. try:

string[] cmd = {     "d:\\program files\\postgresql\\9.1\\bin\\pg_restore.exe",     "--host", "localhost",     "--port", "5432",     "--username", "postgres",     "--dbname", "mytestqq",     "--role", "postgres",     "--no-password",     "--verbose",     "d:\\sathish\\rawdatabase.backup" }; p = r.exec(cmd); 

changes:

  • convert single-string form safer arguments array form of exec call;
  • double backslashes in rawdatabase path since original command fails escape backslashes, \r carriage return in string instead of \ char followed r char.
  • switch doubled backslashes instead of forward slashes on program path consistency. change doesn't matter.

also check return status of process. must use process.waitfor() once has exited use process.exitvalue() determine result. should examine stderr , stdout captured process object errors , logging information.

the reason program continues not work because:

  • you have old pg_restore processes hanging around holding locks; and/or
  • you aren't consuming stdout , stderr pg_restore runs out of buffered pipe space , blocks writing on output stream.

this simpler if use processbuilder instead. processbuilder lets provide file streams write output , takes care of lot of you. must still wait process terminate , check return code though.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -