Re: Any tutorial or FAQ on building an extension?

Lists: pgsql-hackers
From: Matt Culbreth <mattculbreth(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Any tutorial or FAQ on building an extension?
Date: 2009-08-11 15:26:18
Message-ID: 9c3aae16-9a20-4ac7-9173-7d9b89eb5626@b15g2000yqd.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello Group,

I'd like to build an extension to PostgreSQL. It will intercept
queries and perform some transformations on the query and on the data
returned, given some business rules that the users have specified.

What's the best way to do this? It seems like if I model the pgpool-
II architecture that would be a good start. That way existing clients
don't really know that they are talking to my application instead of a
real PostgreSQL postmaster. My app won't be written in C but I
suppose I could start with this approach.

Is there an easier way of going about this other than replacing the
postmaster / postgres components?

Thanks for any pointers,

Matt


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Matt Culbreth <mattculbreth(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Any tutorial or FAQ on building an extension?
Date: 2009-08-11 17:11:58
Message-ID: 4A81A65E.6010308@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> Is there an easier way of going about this other than replacing the
> postmaster / postgres components?

I'd start with creating my own extended version to psql (the client
library), I suppose. But since I don't really know what kind of
"transformations" you have in mind, any advice is going to be purely
speculative.

--
Josh Berkus
PostgreSQL Experts Inc.
www.pgexperts.com


From: Matt Culbreth <mattculbreth(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Any tutorial or FAQ on building an extension?
Date: 2009-08-11 17:34:36
Message-ID: f70c7783-d1e9-4cb5-ba48-c2b2cbe9c1bb@w6g2000yqw.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Aug 11, 1:11 pm, j(dot)(dot)(dot)(at)agliodbs(dot)com (Josh Berkus) wrote:
> > Is there an easier way of going about this other than replacing the
> > postmaster / postgres components?
>
> I'd start with creating my own extended version to psql (the client
> library), I suppose.  But since I don't really know what kind of
> "transformations" you have in mind, any advice is going to be purely
> speculative.
>

Thanks for the response Josh.

I'm not sure that psql is the right thing for me to do though, since I
want to build a back-end component that takes the place of the
existing postmaster. Very possible I misunderstood you though.

To clarify, essentially what I want to do is this:

Client [ psql | JDBC driver | pgAdmin | etc. ] issues a Query
[ "Select * from sales" ]
|
|
\/
My new component intercepts this, and decides if it wants to do
something
|
|
\/
If it does not, it simply passes this on to the real PostgreSQL server
running somewhere
|
|
\/
If it does, it passes the request over to my new server (via sockets),
does its work, and pass back the results
|
|
\/
The client gets the results back, either from PostgreSQL or from my
new server, and goes about its way.


From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Matt Culbreth" <mattculbreth(at)gmail(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Any tutorial or FAQ on building an extension?
Date: 2009-08-11 20:00:47
Message-ID: 4A81879F02000025000298C2@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Matt Culbreth <mattculbreth(at)gmail(dot)com> wrote:

> My new component intercepts this, and decides if it wants to do
> something

> If it does, it passes the request over to my new server (via
> sockets), does its work, and pass back the results

That's still too vague to allow people to give very specific advice.
For example, I don't have a clue yet whether the query rewrite rules
might satisfy your needs:

http://www.postgresql.org/docs/8.4/interactive/sql-createrule.html

-Kevin


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: Matt Culbreth <mattculbreth(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Any tutorial or FAQ on building an extension?
Date: 2009-08-11 21:32:01
Message-ID: 603c8f070908111432n79abc332kdd496f6e85d5a341@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Aug 11, 2009 at 4:00 PM, Kevin
Grittner<Kevin(dot)Grittner(at)wicourts(dot)gov> wrote:
> Matt Culbreth <mattculbreth(at)gmail(dot)com> wrote:
>
>> My new component intercepts this, and decides if it wants to do
>> something
>
>> If it does, it passes the request over to my new server (via
>> sockets), does its work, and pass back the results
>
> That's still too vague to allow people to give very specific advice.
> For example, I don't have a clue yet whether the query rewrite rules
> might satisfy your needs:
>
> http://www.postgresql.org/docs/8.4/interactive/sql-createrule.html

Yeah. I suspect you are going to better off using some combination of
views, triggers, set-returning functions, and SQL-level permissions to
do whatever it is that you are trying to do here rather than inventing
a whole middleware layer.

...Robert