473,287 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 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 2864
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Lang | last post by:
Hi to all, can some one point me to the correct way, how to use PostgreSQLs "COPY" feature from within python ? What i want to do is: connect start transaction drop current tablecontens
0
by: Joshua Ginsberg | last post by:
Howdy -- I have a class that has an attribute that is a dictionary that contains an object that has a kword argument that is a lambda. Confused yet? Simplified example: import copy class...
2
by: Alex | last post by:
Entering the following in the Python shell yields >>> help(dict.copy) Help on method_descriptor: copy(...) D.copy() -> a shallow copy of D >>>
2
by: Clodoaldo Pinto Neto | last post by:
Hi all, I'm trying to copy a table with a text field column containing a new line char to a file: ksDesenv=# create table page(line text) without oids; CREATE TABLE ksDesenv=# insert into...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
4
by: jiang.haiyun | last post by:
Hello all, when i import SOAPpy, the python crashed and print out 'usage:copy source destination'. As follows: ############################ haiyun# python Python 2.4.1 (#2, Mar 28 2006,...
5
by: Steve | last post by:
Hi; I thought I would rephrase a question I asked in another post to more quickly get to the heart of the matter. My apologies for anyone who is offended by what appears to be a repetition. ...
2
by: Tony | last post by:
I'm new at this and would like to know how set up a script to copy a database from a local computer to a network at a certain time everyday. Should be simple enough, but, as of now I am unfamiliar...
3
by: yoma | last post by:
python version 2.5 in module copy we all know that copy have two method: copy() and deepcopy(). and the explain is - A shallow copy constructs a new compound object and then (to the extent...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.