Re: Detailed documentation for external calls (threading, shared resources etc)

Lists: pgsql-hackers
From: Seref Arikan <serefarikan(at)kurumsalteknoloji(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Detailed documentation for external calls (threading, shared resources etc)
Date: 2011-06-12 17:26:17
Message-ID: BANLkTimEDff2Wn_M1ZLAcWNHVb5hxR_pJg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,
This is actually a request for documentation guidance. I intend to
develop an extension to postgresql. Basically I'd like to place calls
to network using ZeroMQ, and I need to have detailed information about
a lot of things, especially threading issues. I need to have some
global resources which will be presumably used by multiple threads.
I can see that there is a lot of documentation, but I'd really
appreciate pointers towards the books, or key documents that'd help me
move forward faster (docs/books about inner workings of key
functionality) I'll be using C (most likely the best option) to
develop code, so which books/documents would you recommend?

Cheers
Seref


From: Florian Pflug <fgp(at)phlo(dot)org>
To: Seref Arikan <serefarikan(at)kurumsalteknoloji(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Detailed documentation for external calls (threading, shared resources etc)
Date: 2011-06-12 19:36:46
Message-ID: 6C787B25-493C-4347-95DB-1C57A11B4475@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Jun12, 2011, at 19:26 , Seref Arikan wrote:
> This is actually a request for documentation guidance. I intend to
> develop an extension to postgresql. Basically I'd like to place calls
> to network using ZeroMQ, and I need to have detailed information about
> a lot of things, especially threading issues. I need to have some
> global resources which will be presumably used by multiple threads.
> I can see that there is a lot of documentation, but I'd really
> appreciate pointers towards the books, or key documents that'd help me
> move forward faster (docs/books about inner workings of key
> functionality) I'll be using C (most likely the best option) to
> develop code, so which books/documents would you recommend?

There are no threading issues in postgres, because postgres doesn't
use threads. Each client connection is serviced by one backend process,
launched by the postmaster when a new client connects. Communication
between backend processes takes places via a shared memory segment
and at times also via signals.

The documentation contains extensive information about how to interface
3rd-party code with postgres. To see how to interface C functions with
the SQL layer, read http://www.postgresql.org/docs/9.0/interactive/xfunc-c.html.
If you need to also access the database from your C-language functions,
also read http://www.postgresql.org/docs/9.0/interactive/spi.html.

More exhaustive documentation is spread around the source tree in
the form of README files. I suggest you read the ones concerned with
the postgres subsystems you're dealing with. At the very least, you
should read .//src/backend/utils/mmgr/README which explains how
postgres manages memory.

The various contrib modules, found in contrib/ in the source tree,
are also a good reference.

best regards,
Florian Pflug


From: Greg Stark <stark(at)mit(dot)edu>
To: Florian Pflug <fgp(at)phlo(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org, Seref Arikan <serefarikan(at)kurumsalteknoloji(dot)com>
Subject: Re: Detailed documentation for external calls (threading, shared resources etc)
Date: 2011-06-12 20:56:54
Message-ID: BANLkTimhB9D7LbxvHqokwzwDkQGmkb2quQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Well process or thread, the issues are the same.

Check out the existing modules and how they use spinlocks and lwlocks to
protect shared memory data structures.

One thing to beware of is that there's no shared memory manager so all
shared data structures need to be fixed size allocated on startup. Anything
where that isn't good enough usually ends up as an on disk data structure.
On Jun 12, 2011 8:37 PM, "Florian Pflug" <fgp(at)phlo(dot)org> wrote:
> On Jun12, 2011, at 19:26 , Seref Arikan wrote:
>> This is actually a request for documentation guidance. I intend to
>> develop an extension to postgresql. Basically I'd like to place calls
>> to network using ZeroMQ, and I need to have detailed information about
>> a lot of things, especially threading issues. I need to have some
>> global resources which will be presumably used by multiple threads.
>> I can see that there is a lot of documentation, but I'd really
>> appreciate pointers towards the books, or key documents that'd help me
>> move forward faster (docs/books about inner workings of key
>> functionality) I'll be using C (most likely the best option) to
>> develop code, so which books/documents would you recommend?
>
>
> There are no threading issues in postgres, because postgres doesn't
> use threads. Each client connection is serviced by one backend process,
> launched by the postmaster when a new client connects. Communication
> between backend processes takes places via a shared memory segment
> and at times also via signals.
>
> The documentation contains extensive information about how to interface
> 3rd-party code with postgres. To see how to interface C functions with
> the SQL layer, read
http://www.postgresql.org/docs/9.0/interactive/xfunc-c.html.
> If you need to also access the database from your C-language functions,
> also read http://www.postgresql.org/docs/9.0/interactive/spi.html.
>
> More exhaustive documentation is spread around the source tree in
> the form of README files. I suggest you read the ones concerned with
> the postgres subsystems you're dealing with. At the very least, you
> should read .//src/backend/utils/mmgr/README which explains how
> postgres manages memory.
>
> The various contrib modules, found in contrib/ in the source tree,
> are also a good reference.
>
> best regards,
> Florian Pflug
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers


From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: Seref Arikan <serefarikan(at)kurumsalteknoloji(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Detailed documentation for external calls (threading, shared resources etc)
Date: 2011-06-14 20:00:31
Message-ID: m28vt4qj34.fsf@2ndQuadrant.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Seref Arikan <serefarikan(at)kurumsalteknoloji(dot)com> writes:
> This is actually a request for documentation guidance. I intend to
> develop an extension to postgresql. Basically I'd like to place calls
> to network using ZeroMQ, and I need to have detailed information about

You didn't tell us about what you want to achieve, only how. It could
be that your problem could be solved with a custom PGQ consumer, that
leaves well outside the database server. PGQ is the generic queue layer
on which the replication system Londiste is built.

http://wiki.postgresql.org/wiki/Skytools
http://wiki.postgresql.org/wiki/PGQ_Tutorial
http://wiki.postgresql.org/wiki/Londiste_Tutorial

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support