Compiling PostgreSQL source code
Compiling srouces
Introduction
All results are expected to be acquired under Ubuntu Desktop 16 LTS x64 version. You can try to do everything on any other operating system, but in rare cases numeric results may vary.
Also, we recommend using virtual machine. C programming language is a sharp tool and in some very infrequent cases you may damage your operating system. Use of dedicated virtual machine will prevent you from harming any of your data and software.
For example, you can use:
1. On Windows 8+ you have Hyper-V virtualization technology.
2. On Linux we recommend to use KVM, Xen or any other familiar instruments
3. On MacOS you can get Oracle Virtual Box and some VMware software.
Most of these software is free. You do not need paid virtualization technology to complete this course.
You can download Ubuntu distributive at https://www.ubuntu.com/download/desktop
Make sure you use 64-bit version (a.k.a. amd64).
Installing Ubuntu over Windows Hyper-V
Prepare Ubuntu ISO. Here we use ubuntu-16.04.1-desktop-amd64.iso
Right click on the Windows button and select ‘Programs and Features’.
Select Turn Windows Features on or off.
Select Hyper-V and click OK.
When the installation has completed you are prompted to restart your computer.
Start Hyper-V manager.
Create a new machine on you host.
Make sure you have Hyper-V network configured: you will need a virtual switch, to be able to download PostgreSQL source code.
Finish and start your VM.
Install Ubuntu
Do not worry: this is a VM disk, nothing is there.
Some straightforward setting will follow.
Here I assume that you are not keeping something personal or important on you VM.
In some cases you will need to restart VM manually, if it hangs on a screen “Remove an installation media and press Enter” and won’t respond on pressing Enter.
Now you have brand new Ubuntu desktop.
Make a checkpoint, just in case.
Let’s proceed to PostgreSQL source code download.
Compiling PostgreSQL source code
You need git. Call the terminal (Ctrl+Alt+T)
Install it via apt-get by typing
sudo apt-get install git
Go to GitHub and make a fork of the PostgreSQL repository to your account
Open new terminal and type:
mkdir project cd project git clone https://github.com/[your name on github]/postgres mv postgres pgsql
The process will take some minutes to complete. You can open one more terminal and prepare PostgreSQL preprequisites:
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev
https://wiki.postgresql.org/wiki/Compile_and_Install_from_source_code
Both processes are quite time consuming.
When All is done you can take a snapshot of VM.
Checkout branch REL9_6_STABLE
cd pgsql
git checkout REL9_6_STABLE
This is not necessary when you do a real development, usually you apply your patches over master branch.
Make your dev branch
git checkout -b temp1
and send your branch to github
git push origin -u temp1
Now you are ready to configure your code.
./configure --prefix=$HOME/project --enable-depend --enable-cassert --enable-debug
Now you are ready to compile your sources, type
make
It will take quite a big amount of time.
After compilation is done you can make install everything.
make install
Now all your binaries reside in ~/project/bin
To let the system search your commands here type
export PATH=$HOME/project/bin:$PATHTo let your default DB be here too
export PGDATA==$HOME/project/DemoDbAnd now you can initialize your database by typing
initdbChange directory to DemoDb and run
nano PG_VERSIO
It will display your version. What version do you have now?
9.6
Nano is the simplest tool to edit files. Now quit nano.
Start the server by
./postgres -D ~/project/DemoDb
Now it is running and it’s output is connected to your terminal
Run other terminal (Ctrl+Alt+T)
Connect to database by running
psql postgres
Execute a query
Select count(*) from information_schema.tables;
Enter a number of how much tables are there 177
Quit psql by entering \q
Finally, run a regression tests:
cd ~/project/pgsql/
make check
How many tests passed? 167
All these utilities we will discuss in a video next week.
The code is in pgsql folder. You can edit it with your favorite text editor or integrated development environment.
Also, you can setup Eclipse, much of the work is already done.
You can use a manual here https://wiki.postgresql.org/wiki/Working_with_Eclipse
Using a community wiki is an important exercise.