The connection to the server was lost. Attempting reset: Failed.
Good afternoon,
I am doing a thesis from the University. My thesis is the modification of
the Gurjeet Index Adviser, to add some features.
At the moment I am modifying one of the .c files and adding a function
called get_columnames that returns the names of the columns of a table,
passing it the numbers of the attributes.
I really thought a lot, but I don't understand why but the function fails
after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""), idxcd->
varattno [i]);
The error appears only to me when entering the cycle:
foreach (cell, candidates) / * foreach cell in candidates * /
more than once, that is, when you have more than one candidate index. If
the cycle is entered only once, the function works correctly.
The error that appears to me is that the connection to the PostgreSQL
server is directly lost. I proved that the error occurs in that statement,
printing some values.
The error that appears to me is the following:
The connection to the server was lost. Attempting reset: Failed.
I attach the source code of the function (function.c) and the log file with
the output of the last executions.
I clarify that the foreach cycle for the c language is defined in #include
"nodes / pg_list.h"
I am using Postgresql 8.3.23.
I clarify that I use that version because it is compatible with the Index
Adviser, which I am modifying for my University thesis.
I was analyzing and researching on the compilation without optimizations,
with symbols and also on the use of gbd. Very interesting everything.
My query is now if all this can be applied the same if a Makefile is used.
Because the Index Adviser comes with a Makefile that runs for compilation.
That is, as I read it is more or less easy to apply all this if I'm going
to compile from the command line but having the Makefile, the truth is that
I don't know how to apply it. I am new with Linux.
The Linux distribution I use is Debian 9.x 64-bit.
And the version of C (gcc) that I use is 6.3.0
I will greatly appreciate an answer please,
I also attach the Index Adviser Makefile.
I would greatly appreciate a help please. I really am not knowing how to
move forward.
As I commented, my function works for the case in which the foreach is
entered only once. But when you enter more than once, it doesn't work. That
is, when you have more than one candidate index, it gives me that error.
This means that, for example, for a simple Select type statement or that
has an AND it works for me. But for the case where the Select statement has
an OR for example, it doesn't work. Because you already have more than one
candidate index and enter the foreach more than once.
I will be very grateful if anyone can help me please.
I already thought a lot why the mistake could happen but I can't really
find a reason.
Best regards,
Yessica Brinkmann
Yessica Brinkmann <yessica.brinkmann@gmail.com> writes:
I really thought a lot, but I don't understand why but the function fails
after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""), idxcd->
varattno [i]);
I think you're probably shooting yourself in the foot here:
/* pfree() the memory allocated for the previous candidate. FIXME: Avoid
* meddling with the internals of a StringInfo, and try to use an API.
*/
if( cols.len > 0 )
{
pfree( cols.data );
cols.data = NULL;
} /*IF col.len>0*/
Don't do that, use resetStringInfo() instead.
regards, tom lane
On 10 Oct 2019, at 17:55, Yessica Brinkmann <yessica.brinkmann@gmail.com> wrote:
I really thought a lot, but I don't understand why but the function fails after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""), idxcd-> varattno [i]);
The error appears only to me when entering the cycle:
foreach (cell, candidates) / * foreach cell in candidates * /
more than once, that is, when you have more than one candidate index. If the cycle is entered only once, the function works correctly.
The error that appears to me is that the connection to the PostgreSQL server is directly lost. I proved that the error occurs in that statement, printing some values.
There is probably an error in the Postgres log-file providing you more info.
That said, at least the below bit in your code is dangerous:
foreach( cell, candidates ) /* foreach cell in candidates */
{
idxcd = (IndexCandidate*)lfirst( cell );
if( !idxcd->idxused )
continue;
if (idxcd!=NULL)
{
You should at least check for NULL before referencing an attribute of that structure. Personally, I would invert the test like so (and then move it before the idxused test:
if (idxcd == NULL) {
elog( INFO, "idxcd IS NULL" );
continue; /* Or is that fatal enough to break instead? */
)
if (!idxcd->idxused)
continue;
Alban Hertroys
--
There is always an exception to always.
Thank you so much for your answer. I will be testing the indicated and then
I give you return.
Best regards,
Yessica Brinkmann
El jue., 10 oct. 2019 a las 13:14, Tom Lane (<tgl@sss.pgh.pa.us>) escribió:
Show quoted text
Yessica Brinkmann <yessica.brinkmann@gmail.com> writes:
I really thought a lot, but I don't understand why but the function fails
after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""), idxcd->
varattno [i]);I think you're probably shooting yourself in the foot here:
/* pfree() the memory allocated for the previous candidate.
FIXME: Avoid
* meddling with the internals of a StringInfo, and try to use
an API.
*/
if( cols.len > 0 )
{
pfree( cols.data );
cols.data = NULL;
} /*IF col.len>0*/Don't do that, use resetStringInfo() instead.
regards, tom lane
Thank you so much for your answer. I will be testing the indicated and then
I give you return.
Best regards,
Yessica Brinkmann
El jue., 10 oct. 2019 a las 13:15, Alban Hertroys (<haramrae@gmail.com>)
escribió:
Show quoted text
On 10 Oct 2019, at 17:55, Yessica Brinkmann <yessica.brinkmann@gmail.com>
wrote:
I really thought a lot, but I don't understand why but the function
fails after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""), idxcd->
varattno [i]);
The error appears only to me when entering the cycle:
foreach (cell, candidates) / * foreach cell in candidates * /
more than once, that is, when you have more than one candidate index. Ifthe cycle is entered only once, the function works correctly.
The error that appears to me is that the connection to the PostgreSQL
server is directly lost. I proved that the error occurs in that statement,
printing some values.There is probably an error in the Postgres log-file providing you more
info.That said, at least the below bit in your code is dangerous:
foreach( cell, candidates ) /* foreach cell in candidates */
{idxcd = (IndexCandidate*)lfirst( cell );
if( !idxcd->idxused )
continue;if (idxcd!=NULL)
{You should at least check for NULL before referencing an attribute of that
structure. Personally, I would invert the test like so (and then move it
before the idxused test:if (idxcd == NULL) {
elog( INFO, "idxcd IS NULL" );
continue; /* Or is that fatal enough to break instead? */
)if (!idxcd->idxused)
continue;Alban Hertroys
--
There is always an exception to always.
Thank you very much for the reply.
Well, really, resetStringInfo () is a function of the StringInfo data
structure.
What I used at the end was initStringInfo, which is a function of the data
structure StringInfoData, which is what I am using, although I don't know
if they are equivalent.
The code remained as follows:
if (cols.len> 0)
{
initStringInfo (& cols);
} / * IF col.len> 0 * /
But it continues giving me the same error.
Best regards,
Yessica Brinkmann
El jue., 10 oct. 2019 a las 13:33, Yessica Brinkmann (<
yessica.brinkmann@gmail.com>) escribió:
Show quoted text
Thank you so much for your answer. I will be testing the indicated and
then I give you return.
Best regards,
Yessica BrinkmannEl jue., 10 oct. 2019 a las 13:14, Tom Lane (<tgl@sss.pgh.pa.us>)
escribió:Yessica Brinkmann <yessica.brinkmann@gmail.com> writes:
I really thought a lot, but I don't understand why but the function
fails
after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""), idxcd->
varattno [i]);I think you're probably shooting yourself in the foot here:
/* pfree() the memory allocated for the previous candidate.
FIXME: Avoid
* meddling with the internals of a StringInfo, and try to use
an API.
*/
if( cols.len > 0 )
{
pfree( cols.data );
cols.data = NULL;
} /*IF col.len>0*/Don't do that, use resetStringInfo() instead.
regards, tom lane
Why don't have a try to gdb ?
https://wiki.postgresql.org/wiki/Developer_FAQ#What_debugging_features_are_available.3F
It might be a extra free memory executions or null pointer accesses .. ,
gdb could help you.
Regards
El jue., 10 oct. 2019 a las 20:01, Yessica Brinkmann (<
yessica.brinkmann@gmail.com>) escribió:
Show quoted text
Thank you very much for the reply.
Well, really, resetStringInfo () is a function of the StringInfo data
structure.
What I used at the end was initStringInfo, which is a function of the data
structure StringInfoData, which is what I am using, although I don't know
if they are equivalent.
The code remained as follows:
if (cols.len> 0)
{
initStringInfo (& cols);
} / * IF col.len> 0 * /
But it continues giving me the same error.
Best regards,
Yessica BrinkmannEl jue., 10 oct. 2019 a las 13:33, Yessica Brinkmann (<
yessica.brinkmann@gmail.com>) escribió:Thank you so much for your answer. I will be testing the indicated and
then I give you return.
Best regards,
Yessica BrinkmannEl jue., 10 oct. 2019 a las 13:14, Tom Lane (<tgl@sss.pgh.pa.us>)
escribió:Yessica Brinkmann <yessica.brinkmann@gmail.com> writes:
I really thought a lot, but I don't understand why but the function
fails
after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""),idxcd->
varattno [i]);
I think you're probably shooting yourself in the foot here:
/* pfree() the memory allocated for the previous candidate.
FIXME: Avoid
* meddling with the internals of a StringInfo, and try to
use an API.
*/
if( cols.len > 0 )
{
pfree( cols.data );
cols.data = NULL;
} /*IF col.len>0*/Don't do that, use resetStringInfo() instead.
regards, tom lane
Thank you so much for your answer. I will be testing the indicated and then
I give you return.
Best regards,
Yessica Brinkmann
El jue., 10 oct. 2019 a las 15:25, Jaime Soler (<jaime.soler@gmail.com>)
escribió:
Show quoted text
Why don't have a try to gdb ?
https://wiki.postgresql.org/wiki/Developer_FAQ#What_debugging_features_are_available.3FIt might be a extra free memory executions or null pointer accesses .. ,
gdb could help you.Regards
El jue., 10 oct. 2019 a las 20:01, Yessica Brinkmann (<
yessica.brinkmann@gmail.com>) escribió:Thank you very much for the reply.
Well, really, resetStringInfo () is a function of the StringInfo data
structure.
What I used at the end was initStringInfo, which is a function of the
data structure StringInfoData, which is what I am using, although I don't
know if they are equivalent.
The code remained as follows:
if (cols.len> 0)
{
initStringInfo (& cols);
} / * IF col.len> 0 * /
But it continues giving me the same error.
Best regards,
Yessica BrinkmannEl jue., 10 oct. 2019 a las 13:33, Yessica Brinkmann (<
yessica.brinkmann@gmail.com>) escribió:Thank you so much for your answer. I will be testing the indicated and
then I give you return.
Best regards,
Yessica BrinkmannEl jue., 10 oct. 2019 a las 13:14, Tom Lane (<tgl@sss.pgh.pa.us>)
escribió:Yessica Brinkmann <yessica.brinkmann@gmail.com> writes:
I really thought a lot, but I don't understand why but the function
fails
after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""),idxcd->
varattno [i]);
I think you're probably shooting yourself in the foot here:
/* pfree() the memory allocated for the previous candidate.
FIXME: Avoid
* meddling with the internals of a StringInfo, and try to
use an API.
*/
if( cols.len > 0 )
{
pfree( cols.data );
cols.data = NULL;
} /*IF col.len>0*/Don't do that, use resetStringInfo() instead.
regards, tom lane
Thank you very much for your answer.
It helped me.
Really now the get_columnnames function is already working and ends cleanly.
I have an error in the following function to be executed that generates the
same error: The connection to the server was lost. Attempting reset:
Failed. I will try to solve it alone and if I cannot write another new mail
thread.
Because this problem of get_columnnames is already solved.
Many thanks,
Best regards,
Yessica Brinkmann
El jue., 10 oct. 2019 a las 13:15, Alban Hertroys (<haramrae@gmail.com>)
escribió:
Show quoted text
On 10 Oct 2019, at 17:55, Yessica Brinkmann <yessica.brinkmann@gmail.com>
wrote:
I really thought a lot, but I don't understand why but the function
fails after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""), idxcd->
varattno [i]);
The error appears only to me when entering the cycle:
foreach (cell, candidates) / * foreach cell in candidates * /
more than once, that is, when you have more than one candidate index. Ifthe cycle is entered only once, the function works correctly.
The error that appears to me is that the connection to the PostgreSQL
server is directly lost. I proved that the error occurs in that statement,
printing some values.There is probably an error in the Postgres log-file providing you more
info.That said, at least the below bit in your code is dangerous:
foreach( cell, candidates ) /* foreach cell in candidates */
{idxcd = (IndexCandidate*)lfirst( cell );
if( !idxcd->idxused )
continue;if (idxcd!=NULL)
{You should at least check for NULL before referencing an attribute of that
structure. Personally, I would invert the test like so (and then move it
before the idxused test:if (idxcd == NULL) {
elog( INFO, "idxcd IS NULL" );
continue; /* Or is that fatal enough to break instead? */
)if (!idxcd->idxused)
continue;Alban Hertroys
--
There is always an exception to always.
That is,
It worked by changing the code to:
if (idxcd == NULL) {
elog( INFO, "idxcd IS NULL" );
continue; /* Or is that fatal enough to break instead? */
}
if (!idxcd->idxused)
continue;
Very thanks,
Yessica Brinkmann
El jue., 10 oct. 2019 a las 16:43, Yessica Brinkmann (<
yessica.brinkmann@gmail.com>) escribió:
Show quoted text
Thank you very much for your answer.
It helped me.
Really now the get_columnnames function is already working and ends
cleanly.
I have an error in the following function to be executed that generates
the same error: The connection to the server was lost. Attempting reset:
Failed. I will try to solve it alone and if I cannot write another new mail
thread.
Because this problem of get_columnnames is already solved.
Many thanks,
Best regards,
Yessica BrinkmannEl jue., 10 oct. 2019 a las 13:15, Alban Hertroys (<haramrae@gmail.com>)
escribió:On 10 Oct 2019, at 17:55, Yessica Brinkmann <
yessica.brinkmann@gmail.com> wrote:
I really thought a lot, but I don't understand why but the function
fails after the expression is executed:
appendStringInfo (& cols, "% s a.attnum =% d", (i> 0? "OR": ""),
idxcd-> varattno [i]);
The error appears only to me when entering the cycle:
foreach (cell, candidates) / * foreach cell in candidates * /
more than once, that is, when you have more than one candidate index.If the cycle is entered only once, the function works correctly.
The error that appears to me is that the connection to the PostgreSQL
server is directly lost. I proved that the error occurs in that statement,
printing some values.There is probably an error in the Postgres log-file providing you more
info.That said, at least the below bit in your code is dangerous:
foreach( cell, candidates ) /* foreach cell in candidates */
{idxcd = (IndexCandidate*)lfirst( cell );
if( !idxcd->idxused )
continue;if (idxcd!=NULL)
{You should at least check for NULL before referencing an attribute of
that structure. Personally, I would invert the test like so (and then move
it before the idxused test:if (idxcd == NULL) {
elog( INFO, "idxcd IS NULL" );
continue; /* Or is that fatal enough to break instead? */
)if (!idxcd->idxused)
continue;Alban Hertroys
--
There is always an exception to always.