Re: Extension development

From: Jeevan Ladhe <jeevan(dot)ladhe(at)enterprisedb(dot)com>
To: Yonatan Misgan <yonamis(at)dtu(dot)edu(dot)et>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Extension development
Date: 2019-11-12 10:30:37
Message-ID: CAOgcT0M=eDVPHe8_6fLSbcR6APau=_8aSaCsTH7XXrpQ6WyeGg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Yonatan,

Here is an attempt to explain the components of the extension:

Makefile:
Makefile provides a way to compile your C code. Postgres provides an
infrastructure called PGXS for building the extensions against installed
Postgres server. More of this can be found in official documentation[1].

Control file:
It specifies some properties/metadata about the extension, like version,
comments, directory etc. Official documentation[2]

SQL Script:
This file should be of format extension—version.sql which will have the
functions that are either pure SQL functions, or interfaces for your C
functions and other SQL objects to assist your functions etc. This will be
executed internally by “CREATE EXTENSION” command.

C code:
Your C code is real implementation of your extension. Here you can have C
implementations of SQL interface functions your declared in your .sql
script file, register callbacks e.g. things you want to do post parse,
before execution of a query etc. The filename can be anything but you
should have PG_MODULE_MAGIC included in your C file.

Using this infrastructure one can simply do make, make install and then
“CREATE EXTENSION” command to create objects. This helps keeping track of
all the extension objects together, create them at once, and drop once with
“DROP EXTENSION” command. Here[3] is complete documentation for extension.

Regards,
Jeevan Ladhe

[1] https://www.postgresql.org/docs/current/extend-pgxs.html
[2]
https://www.postgresql.org/docs/current/extend-extensions.html#id-1.8.3.20.12
[3] https://www.postgresql.org/docs/current/extend-extensions.html

On Tue, Nov 12, 2019 at 12:24 PM Yonatan Misgan <yonamis(at)dtu(dot)edu(dot)et> wrote:

> I am developed my own PostgreSQL extension for learning purpose and it is
> working correctly but I want to know to which components of the database is
> my own extension components communicate. For example I have c code, make
> file sql script, and control file after compiling the make file to which
> components of the database are each of my extension components to
> communicate. Thanks for your response.
>
>
>
> Regards,
>
> ____________________________________
>
> *Yonathan Misgan *
>
> *Assistant Lecturer, @ Debre Tabor University*
>
> *Faculty of Technology*
>
> *Department of Computer Science*
>
> *Studying MSc in **Computer Science** (in Data and Web Engineering) *
>
> *@ Addis Ababa University*
>
> *E-mail: yonamis(at)dtu(dot)edu(dot)et <yonamis(at)dtu(dot)edu(dot)et>*
>
> * yonathanmisgan(dot)4(at)gmail(dot)com <yonathanmisgan(dot)4(at)gmail(dot)com>*
>
> *Tel: **(+251)-911180185 (mob)*
>
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2019-11-12 10:34:12 Re: [HACKERS] Block level parallel vacuum
Previous Message Masahiko Sawada 2019-11-12 10:08:46 Re: [HACKERS] Block level parallel vacuum