Here's How To Create Your First PostgrSQL Extension Part 1

mghrabi

Ahmed Hisham

Posted on July 26, 2023

Here's How To Create Your First PostgrSQL Extension Part 1

The following blogs will target the most basics of creating a PostgreSQl extension, at the end you should become pretty familiar with what's required to create an extension for PostgreSQL. the blog series assumes you are working with a linux system like Ubuntu.

Prerequisites

Obviously you should have your version of PostgreSQL, and won't matter which version of PostgreSQL you will be using since in this tutorial we will create a very simple extension. If you don't already installed PostgreSQL, you can directly install it's package, or install it from a source code following this blog here where I described in details how to do that.

Creating an extension!:

  1. By having PostgreSQL installed on your machine, you should have the binaries (executable files) installed somewhere in your system, for me they are in /usr/local/pgsql-13/bin.

  2. Now create a directory where you will create the extension (you can create it anywhere) and name it add_two_numbers:

mkdir add_two_numbers
Enter fullscreen mode Exit fullscreen mode
  1. Now we need to understand what are the files exactly we need to create to accomplish the mission, there are three necessary files to create:
  • Makefile file: it's used to build the extension, in which you specify the instructions to build the extension.
  • *.control file: This file provides a metadata about the extension like the name, version and author.
  • *.sql file: this will contain the required sql queries to build the extension functionalities
  • *.c file: And this c file will contain the c functions that your extension supports.

In the next blog we will be going through each of them in details and explore the steps to build up the extension!.

💖 💪 🙅 🚩
mghrabi
Ahmed Hisham

Posted on July 26, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related