Re: running pg_dump from python

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: running pg_dump from python
Date: 2009-06-20 12:06:03
Message-ID: h1ijbb$hl5$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2009-06-18, Erik Jones <ejones(at)engineyard(dot)com> wrote:
>
> On Jun 15, 2009, at 5:17 AM, Jasen Betts wrote:
>
>> On 2009-06-14, Garry Saddington <garry(at)schoolteachers(dot)co(dot)uk> wrote:
>>> I ahve the following python file that I am running as an external
>>> method
>>> in Zope.
>>>
>>> def backup():
>>> import os
>>> os.popen("c:/scholarpack/postgres/bin/pg_dump scholarpack >
>>> c:/scholarpack/ancillary/scholarpack.sql")
>>
>> are you sure you're using os.popen correctly?
>> you don't appear to be waiting for the pg_dump process to finish.
>
> Right, the popen stuff should be something like:
>
> p = os.popen("c:/scholarpack/postgres/bin/pg_dump scholarpack > c:/
> scholarpack/ancillary/scholarpack.sql 2> c:/scholarpack/ancillary/
> dump.err")
>
> status = p.close()

I suspect you should also read from the handle until it returns a blocking EOF
or take some other action to ensure the process has finished before
closing the pipe.

> Then check status to see if the command was successful or not.

I suspect Garry really wanted to use os.system instead as the command
he's running is not likely to produce any data on stdout.

or perhaps he wanted to runs the command and grab stdout in the pipe...

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2009-06-20 12:35:56 Re: looping over a small record set over and over in a function
Previous Message Madison Kelly 2009-06-20 11:47:59 Re: Disaster recovery (server died)