Обсуждение: Regarding PQputline and PQendcopy
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Hello,</span></font><pclass="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">We are using PQputline function for copying data todatabase</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial">Postgres version 7.2.4</span></font><p class="MsoNormal" style="MARGIN: 0in 0in0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Followingis the code snapshot:</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><spanstyle="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">We are taking data from one database, 100records at time and storing that records in string array "strArr" </span></font><p class="MsoNormal" style="MARGIN: 0in0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">After filling "strArr", we arepassing this string array to PQputline as follows:</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-tab-count:1"> </span>res = PQexec(conn, "COPY <tablename> from STDIN"); </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt;FONT-FAMILY: Arial">PQclear(res);</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">i = 0; </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial">while(true) {</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><spanstyle="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>status = PQputline(conn,strArr[i]);//contains one row of data </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>if(status!= 0) {</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><spanstyle="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>cout<<endl<<"Unableto send string: "<< strArr[i] <<endl; </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial"><span style="mso-spacerun: yes"> </span>if (status == EOF) {</span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-tab-count:1"> </span>cout<<endl<<"status is EOF"<<endl; </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial"><span style="mso-spacerun: yes"> </span>}</span></font><p class="MsoNormal" style="MARGIN: 0in 0in0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>}</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>i++;</span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial"><span style="mso-spacerun: yes"> </span>if(i > 100) {</span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun:yes"> </span>break;</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>}</span></font><pclass="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial">} </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">status = PQputline(conn,</span></font><font face="TimesNew Roman"> </font><font face="Arial" size="2"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">"\\.\n"); //terminator line</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"><font face="Arial" size="2"><spanstyle="FONT-SIZE: 10pt; FONT-FAMILY: Arial">status = PQendcopy(conn);<span style="mso-spacerun: yes"> </span></span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Sometime above codeworks fine but at sometime PQputline returns EOF and code goes in hang state for PQendcopy function. </span></font><pclass="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial">How to recognize, why PQputline sends EOF?</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Please provide me some help regarding whataction must be taken when PQputline returns EOF or PQputline unable to send the line to server. </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Alsohow to avoid the hang state of postgres server in PQendcopy function</span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><pclass="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Thanks,</span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Soni</span></font>
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
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
soni de wrote: > > Can anyone please tell me why PQendcopy (PQgetResult) goes in hang state? Presumably because you are calling it on a failed connection. -- Richard Huxton Archonet Ltd