Connect from background worker thread to database - Mailing list pgsql-hackers

From Олексій Васильєв
Subject Connect from background worker thread to database
Date
Msg-id 1385296026.139424158@f325.i.mail.ru
Whole thread Raw
Responses Re: Connect from background worker thread to database  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Hello everyone.

I am new to writing extensions to PostgreSQL. And I am not familiar with the C language (My professional languages: Ruby, Golang, Java). But still want to write an extension for PostgreSQL.

After articles of Michael Paquier about  background workers in PostgreSQL, I realized what I can create what I always want - web interface for this database. This interface will provide some info about database (like in couchbase: http://docs.couchbase.com/couchbase-manual-2.0/images/web-console-cluster-overview.png) and can be used as REST API.

Right now this server should work as JSON API and I will build on top of this API web interface on some JS framework. My initiative right now is working as web server just with some hello string. But I don't understand how should I connect to database from threads in web server. All source you can find here: https://github.com/le0pard/pg_web

This is part where I try to connect to database: https://github.com/le0pard/pg_web/blob/master/src/pg_web.c#L92-L132, but SPI functions give error in log (it is commented):

2013-11-24 02:57:43 UTC ERROR:  stack depth limit exceeded

2013-11-24 02:57:43 UTC HINT:  Increase the configuration parameter "max_stack_depth" (currently 2048kB), after ensuring the platform's stack depth limit is adequate.

2013-11-24 02:57:43 UTC CONTEXT:  SQL statement "SELECT COUNT(*) FROM pg_class;"

Because I doing something in wrong way. I will appreciate for any help: where I doing wrong, link to the article how to do it, just a tip, pull request - anything. Google search and PostgreSQL sources reading  so far helped me to this point.


Thanks in advance, Alexey




pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: review - pg_stat_statements
Next
From: Andres Freund
Date:
Subject: Re: Connect from background worker thread to database