471,348 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Copy database with python..

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 ?
Note: The database's size is 200 GB

Nov 2 '07 #1
8 2711
On Fri, 2007-11-02 at 06:51 -0700, 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")
cursor.execute executes SQL queries. pg_dump is not an SQL query, it is
an operating system command. To execute OS commands, use
os.system("...") or the subprocess module.

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net
Nov 2 '07 #2
>>>>"Abandoned" == Abandoned <be*****@gmail.comwrites:
AbandonedI want to copy my database but python give me error when i
Abandoneduse this command. cursor.execute("pg_dump mydata old.dump")
AbandonedWhat is the problem ?

cursor.execute() is for executing SQL commands, and this is not an SQL
command, but rather a shell command.

AbandonedAnd how can i copy the database with python ? Note: The
Abandoneddatabase's size is 200 GB

If you want to do this from Python, run it as a separate process.

Martin
Nov 2 '07 #3
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
Nov 2 '07 #4
On Nov 2, 4:11 pm, Martin Sand Christensen <m...@es.aau.dkwrote:
>>>"Abandoned" == Abandoned <best...@gmail.comwrites:

AbandonedI want to copy my database but python give me error when i
Abandoneduse this command. cursor.execute("pg_dump mydata old.dump")
AbandonedWhat is the problem ?

cursor.execute() is for executing SQL commands, and this is not an SQL
command, but rather a shell command.

AbandonedAnd how can i copy the database with python ? Note: The
Abandoneddatabase's size is 200 GB

If you want to do this from Python, run it as a separate process.

Martin
Yes i understand thank you.
Now i find that maybe help the other users.

import os
os.system("su postgres")
....
...

Nov 2 '07 #5
On Nov 2, 4:19 pm, Paul McNett <p...@ulmcnett.comwrote:
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 :( )

Nov 2 '07 #6
>>>>"Abandoned" == Abandoned <be*****@gmail.comwrites:
AbandonedYes i understand thank you. Now i find that maybe help the
Abandonedother users.

Abandonedimport os
Abandonedos.system("su postgres")
Abandoned...

I get the distinct impression that you're trying to replace simple shell
scripting with Python. While it's possible, you're probably making
things much more complicated than they need to be. Unless you're
actually doing something with all that data of yours, don't use Python
where a simple shell script will be much smaller and cleaner.

Martin
Nov 2 '07 #7
Abandoned wrote:
On Nov 2, 4:19 pm, Paul McNett <p...@ulmcnett.comwrote:
>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
Nov 2 '07 #8
Abandoned a écrit :
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 ?
Could it have to do with the fact that cursor.execute expects a valid
SQL query - not a bash command line ?
And how can i copy the database with python ?
import os
help(os.system)
Nov 4 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael Lang | last post: by
reply views Thread by Joshua Ginsberg | last post: by
2 posts views Thread by Clodoaldo Pinto Neto | last post: by
2 posts views Thread by Tony | last post: by
3 posts views Thread by yoma | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.