Regarding PQputline and PQendcopy
Hello,
We are using PQputline function for copying data to database
Postgres version 7.2.4
Following is the code snapshot:
We are taking data from one database, 100 records at time and storing that
records in string array "strArr"
After filling "strArr", we are passing this string array to PQputline as
follows:
res = PQexec(conn, "COPY <tablename> from STDIN");
PQclear(res);
i = 0;
while(true) {
status = PQputline(conn,strArr[i]); //contains one row of data
if(status != 0) {
cout<<endl<<"Unable to send string: "<< strArr[i] <<endl;
if (status == EOF) {
cout<<endl<<"status is EOF"<<endl;
}
}
i++;
if(i > 100) {
break;
}
}
status = PQputline(conn, "\\.\n"); // terminator line
status = PQendcopy(conn);
Sometime above code works fine but at sometime PQputline returns EOF and
code goes in hang state for PQendcopy function.
How to recognize, why PQputline sends EOF?
Please provide me some help regarding what action must be taken when
PQputline returns EOF or PQputline unable to send the line to server.
Also how to avoid the hang state of postgres server in PQendcopy function
Thanks,
Soni
Any response?
Show quoted text
On 11/29/06, soni de <soni.de@gmail.com> wrote:
Hello,
We are using PQputline function for copying data to database
Postgres version 7.2.4
Following is the code snapshot:
We are taking data from one database, 100 records at time and storing that
records in string array "strArr"After filling "strArr", we are passing this string array to PQputline as
follows:res = PQexec(conn, "COPY <tablename> from STDIN");
PQclear(res);
i = 0;
while(true) {
status = PQputline(conn,strArr[i]); //contains one row of data
if(status != 0) {
cout<<endl<<"Unable to send string: "<< strArr[i] <<endl;
if (status == EOF) {
cout<<endl<<"status is EOF"<<endl;
}
}
i++;
if(i > 100) {
break;
}
}
status = PQputline(conn, "\\.\n"); // terminator line
status = PQendcopy(conn);
Sometime above code works fine but at sometime PQputline returns EOF and
code goes in hang state for PQendcopy function.How to recognize, why PQputline sends EOF?
Please provide me some help regarding what action must be taken when
PQputline returns EOF or PQputline unable to send the line to server.Also how to avoid the hang state of postgres server in PQendcopy function
Thanks,
Soni
soni de wrote:
Any response?
You're going to have to be a little patient I suspect...
We are using PQputline function for copying data to database
Postgres version 7.2.4
Because you're running quite an old version. If nothing else, you should
upgrade to the last in the 7.2 series.
status = PQputline(conn,strArr[i]); //contains one row of data
...
status = PQputline(conn, "\\.\n"); // terminator line
...
status = PQendcopy(conn);
Sometime above code works fine but at sometime PQputline returns EOF and
code goes in hang state for PQendcopy function.How to recognize, why PQputline sends EOF?
Check the connection status and error-message when EOF is returned?
Please provide me some help regarding what action must be taken when
PQputline returns EOF or PQputline unable to send the line to server.
If EOF is returned, does it make sense to send the terminator etc?
--
Richard Huxton
Archonet Ltd
soni de wrote:
Any response?
Yes. First posting this just 6 hours after your original is both
impatient and rude.
Second, you should upgrade to a modern and supported version of
Postgres. Nobody is going to want to support you on a version as out of
date as 7.2.4.
cheers
andrew
Andrew Dunstan <andrew@dunslane.net> writes:
soni de wrote:
Any response?
Yes. First posting this just 6 hours after your original is both
impatient and rude.
Second, you should upgrade to a modern and supported version of
Postgres. Nobody is going to want to support you on a version as out of
date as 7.2.4.
And third, this was not a hacker-grade question.
regards, tom lane
Hello,
I wanted this ASAP so asked for "respone" after 6 hours
Sorry for being rude and impatient.
We are planning to switch to postgres 8.1.x, but for that we want to migrate
our older postgres data to newer database.
And we want our own utility for migrating data, so that we can have full
control over our utility.
So we have written our own program for copying data from older postgres to
newer one
We came to know why PQputline returns EOF, that is because of connection is
not alive or because of some problem in connection.
After refreshing the connection it works fine.
But some time program gets hangs in PQendcopy. Below is pstack trace where
postgres goes in hang state:
ff21dce8 poll (feb05828, 1, ffffffff)
ff1cd6fc select (5, 0, 0, feb05830, feb05964, feb05828) + 348
ff26ab28 select (1, 0, 7bba8, 0, ff357964, ff358640) + 34
ff3593bc PQgetResult (7bba8, 0, 0, ff359360, 81707, 0) + 64
ff359f90 PQendcopy (7bba8, a57d8, 70a1c, 7553e0, 7553e0, 0) + 108
Can anyone please tell me why PQendcopy (PQgetResult) goes in hang state?
Thanks,
Soni
Show quoted text
On 11/29/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
soni de wrote:
Any response?
Yes. First posting this just 6 hours after your original is both
impatient and rude.Second, you should upgrade to a modern and supported version of
Postgres. Nobody is going to want to support you on a version as out of
date as 7.2.4.And third, this was not a hacker-grade question.
regards, tom lane