pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedExceeded maximum lock level
4+ messages / 2 participants
[nested] [flat]
* Exceeded maximum lock level
@ 2008-04-23 14:24 alexander lunyov <lan@zato.ru>
0 siblings, 1 reply; 4+ messages in thread
From: alexander lunyov @ 2008-04-23 14:24 UTC (permalink / raw)
To: pgsql-interfaces
Hello.
Freebsd 6.2, Postgresql 8.3 from ports.
I'm trying to add some features to threaded application, like sql logs.
I've changed application according to examples of libpq usage (simple
things - connect, inserts, disconnect), everything works for a little
time (under 1 minute), then i get error:
Fatal error 'Exceeded maximum lock level' at line 519 in file
/usr/src/lib/libpthread/thread/thr_mutex.c (errno = 844913743)
This application compiled with -lpthread, and in #postgresql user
RhodiumToad told me to use -pthread instead, but after changes in
makefiles to use -pthread the same error comes up right after first use
of sql functions (in the beginning some amount of data was actually
inserted to DB before error comes up). For now i told this application
not to use threads (it have command line key switching thread/fork
behavior) and it works, but i think threads would be better under heavy
load (i think in future there will be heavy load).
If i start application with threads but not use sql functions (sql code
is there but not used) i see no errors. Is it a problem of libpq?
Compilation flags looks like this:
CFLAGS=-O2 -fno-strict-aliasing -pipe -DFREEBSD -pthread
-export-dynamic -I/usr/local/include -I . -shared -fPIC
LIBS = -lpthread -L/usr/local/lib -lpq
--
wbr, alexander
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Exceeded maximum lock level
@ 2008-04-23 14:55 Alvaro Herrera <alvherre@commandprompt.com>
parent: alexander lunyov <lan@zato.ru>
0 siblings, 1 reply; 4+ messages in thread
From: Alvaro Herrera @ 2008-04-23 14:55 UTC (permalink / raw)
To: alexander lunyov <lan@zato.ru>; +Cc: pgsql-interfaces
alexander lunyov wrote:
> Hello.
>
> Freebsd 6.2, Postgresql 8.3 from ports.
>
> I'm trying to add some features to threaded application, like sql logs.
> I've changed application according to examples of libpq usage (simple
> things - connect, inserts, disconnect), everything works for a little
> time (under 1 minute), then i get error:
>
> Fatal error 'Exceeded maximum lock level' at line 519 in file
> /usr/src/lib/libpthread/thread/thr_mutex.c (errno = 844913743)
This is clearly not a PG problem -- I'd think there's a bug in your own
code.
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Exceeded maximum lock level
@ 2008-04-24 05:34 alexander lunyov <lan@zato.ru>
parent: Alvaro Herrera <alvherre@commandprompt.com>
0 siblings, 1 reply; 4+ messages in thread
From: alexander lunyov @ 2008-04-24 05:34 UTC (permalink / raw)
To: pgsql-interfaces; +Cc: Alvaro Herrera <alvherre@commandprompt.com>
Alvaro Herrera wrote:
>> Fatal error 'Exceeded maximum lock level' at line 519 in file
>> /usr/src/lib/libpthread/thread/thr_mutex.c (errno = 844913743)
>
> This is clearly not a PG problem -- I'd think there's a bug in your own
> code.
This is very helpful :)
My code is just this:
int SQLLog( PGconn *conn,
struct auth *a,
struct client *c,
struct request *r,
struct data *d )
{
char * str;
char log[256];
char *request;
unsigned char *esc_bytea;
size_t length;
PGresult *res;
if ((esc_bytea = PQescapeByteaConn(conn,d->data,d->len,&length)) ==
NULL)
{
snprintf(log,256, "Error: %s",PQerrorMessage(conn));
logging(log);
return 0;
}
request = malloc ( sizeof(a->user) + sizeof(c->src) +
sizeof(r->dst) + sizeof(esc_bytea) + 110);
sprintf(request, "INSERT INTO raw
(username,from_addr,to_addr,rawdata,direction) VALUES
('%s','%s','%s',E'%s',%d)", a->user,c->src,r->dst,esc_bytea,d->dir);
res = PQexec(conn, request);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
snprintf(log,256,"failed: %s", PQerrorMessage(conn));
logging(log);
}
free(request);
PQfreemem(esc_bytea);
PQclear(res);
return 0;
}
int OpenSQL( PGconn **conn )
{
char log[256];
char *conninfo;
conninfo = "host=localhost dbname=db user=user password=password";
*conn = PQconnectdb(conninfo);
if (PQstatus(*conn) != CONNECTION_OK)
{
snprintf(log,256, "Connection to database failed: %s",
PQerrorMessage(*conn));
logging(log);
return 1;
} else
return 0;
}
int CloseSQL( PGconn *conn )
{
PQfinish(conn);
return 0;
}
I didn't touch any mutex (i don't even sure about what is mutex). While
not calling any of sql functions, application works just fine. In
non-threaded mode it is working with sql functions. Where did i go wrong?
--
wbr, alexander
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Exceeded maximum lock level
@ 2008-04-24 14:12 Alvaro Herrera <alvherre@commandprompt.com>
parent: alexander lunyov <lan@zato.ru>
0 siblings, 0 replies; 4+ messages in thread
From: Alvaro Herrera @ 2008-04-24 14:12 UTC (permalink / raw)
To: alexander lunyov <lan@zato.ru>; +Cc: pgsql-interfaces
alexander lunyov wrote:
> Alvaro Herrera wrote:
>>> Fatal error 'Exceeded maximum lock level' at line 519 in file
>>> /usr/src/lib/libpthread/thread/thr_mutex.c (errno = 844913743)
>>
>> This is clearly not a PG problem -- I'd think there's a bug in your own
>> code.
>
> This is very helpful :)
>
> My code is just this:
> I didn't touch any mutex (i don't even sure about what is mutex). While
> not calling any of sql functions, application works just fine. In
> non-threaded mode it is working with sql functions. Where did i go wrong?
Well, there are still many things left out, like how many times you call
this function before it fails. Even then, I suspect the bug is in the
pthread code that comes with your operating system -- or perhaps on the
patches that the port applies to Postgres.
(For the record, I filled the missing pieces in your program and made
SQLLog loop 100000 times, which it did without a hitch. Next time,
please submit a complete program, not just pieces of it.)
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2008-04-24 14:12 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-04-23 14:24 Exceeded maximum lock level alexander lunyov <lan@zato.ru>
2008-04-23 14:55 ` Alvaro Herrera <alvherre@commandprompt.com>
2008-04-24 05:34 ` alexander lunyov <lan@zato.ru>
2008-04-24 14:12 ` Alvaro Herrera <alvherre@commandprompt.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox