Copy database with python..

Diez B. Roggisch deets at nospam.web.de
Fri Nov 2 17:49:52 CET 2007


Abandoned wrote:

> On Nov 2, 4:19 pm, Paul McNett <p... at ulmcnett.com> wrote:
>> Abandoned wrote:
>> > Hi.
>> > I want to copy my database but python give me error when i use this
>> > command.
>> > cursor.execute("pg_dump mydata > old.dump")
>> > What is the problem ? And how can i copy the database with python ?
>>
>> You are just going to have to give us more to go on. Please post the
>> entire traceback of the error that you see (copy/paste it from your
>> terminal).
>>
>> You can't issue system commands using the cursor's execute() method and
>> expect that to work. execute() is for executing SQL, DML, or DDL, not
>> for doing shell stuff.
>>
>> Try:
>>
>> import os
>> os.system("pg_dump mydata > /tmp/old.dump")
>>
>> but I'm not versed in postgressql, so this probably won't work exactly
>> as written. You'd need to run that code from the server hosting the
>> postgresql database.
>>
>> > Note: The database's size is 200 GB
>>
>> Well, then you may want to make sure you have enough room on the target
>> volume before trying to dump the file! Note that the dump file could
>> conceivably be much larger (or much smaller) than the database itself.
>>
>> --
>> pkm ~http://paulmcnett.com
> 
> Are there any way to copy database without dump or any temp files ?
> (If there is a temp my harddisk not enough for this operation :( )

You can invoke the pg_dump on the remote machine.

Diez



More information about the Python-list mailing list