By the end of this guide, you will have installed PostgreSQL and integrated it with Apache AGE on your Windows system. This guide is intended to be a no-brain installation guide that holds your hand every step of the way and one I wished I had. There is also an excellent video Youtube, but I encountered slight issues while following it.
Before we proceed, allow me to save you the time of Googling and tell you that Apache AGE does not support windows currently and therefore we have to use Linux. Also, to install WSL2 you need minimum:-
Windows 10 May 2020 (2004), Windows 10 May 2019 (1903), or Windows 10 November 2019 (1909)
A computer with Hyper-V Virtualization support
You can check your version by typing "winver" in the search bar.
I’d be mighty surprised if anyone who’s reading this guide doesn’t meet those requirements, but if you don’t, you can use WSL 1 and follow another guide.
The approaches that you can use are:-
- Run PostgreSQL and AGE using Docker.
- Dual-Boot and use the Linux environment.
- Use WSL2 to run a Linux environment directly on Windows.
- Problem with approach 1 is that you have to enable WSL2 anyways(WSL1 does not work with Docker) and install Docker Windows which takes up almost the same size as Ubuntu. In addition, it is very resource intensive compared to simply running Ubuntu and makes my PC lag.
- Approach 2 is doable but you need to allocate space for a dual-partition and frankly, is just a pain. Unless you actually want to use Linux and have the space for a dual-boot 😀.
The approach we will use is to use the Windows Subsystem for Linux version 2 that allows to run a Linux environment on Windows.
Good News! While writing this guide I learnt that if you have Windows 10 May 2020 (2004) update or late then you can simply open cmd and type
wsl.exe --install and that should take care of setting up everything and installs ubuntu as the default distro as well. A restart would be required after this.
Bad News! If you're like me and didn't know 😅 or simply don't have the proper version then we need to do the old method and implement the following steps:-
Enable WSL: Open PowerShell as Administrator and run the command
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart.
Enable the Virtual Machine Platform: If you have Windows 10 (2004) and above, run the command
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartelse run the command
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart.
Restart the system.
Set WSL2 as default with the command
wsl --set-default-version 2
Now by now you should have WSL2 enabled. Now you should install Ubuntu if you followed this old method. Go to the Microsoft Store and search for "Ubuntu" and hit the "Get" button.
Now we're set! You can open Ubuntu and start up your Linux terminal by clicking on the shortcut added to the Start Menu.
Installing Windows terminal from the windows store will give you a proper Linux terminal alongside a host of other options.
Currently, according to the documentation version 11,12 and 13 are supported and can be installed on ubuntu by the command
sudo apt install postgresql-11 postgresql-server-dev-11 for example for version 11. Note: I ran into issues doing this and therefore I had to manually download the source code and install it. Therefore, I will expand on that here. Download the source code from PostgreSQL, my recommendation is version 11.18. The tar.gz file needs to be downloaded.
Now, you need to access the tar.gz file from your Linux terminal and copy it to the home directory of your Linux environment. I downloaded the tar.gz file to my downloads folder, therefore, I entered
cp -R cd../../mnt/c/Users/Hassam/Downloads/postgresql-11.18.tar.gz ~/
Now navigate back to the home directory by typing
cd and unzip the tar file by the command
tar -xzf postgresql-11.18.tar.gz.
Before proceeding download these dependencies by the command
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison else you'll have to repeat the process and make/install PostgreSQL again.
Navigate inside the unzipped folder and run the command
./configure --prefix=$(pwd) --enable-cassert --enable-debug CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer". After this, you will have a makefile in your folder, now run the command
make install to install.
Congrats, you've installed PostgreSQL! 👍
You can check it by navigating to the bin folder inside your PostgreSQL installation and typing the command
(OPTIONAL) If you want to enable global access then navigate to the home directory and type
nano ~/.bashrc and type, in my case it was,
export PATH="$PATH:/home/hassoo/postgresql-11.18/bin" at the end of the file and save
Note: the PATH is absolute and should be directed to the bin folder. Now you can run the psql command globally.
The hard part is over. Now clone the Apache AGE repository into the home directory by typing the command
git clone https://github.com/apache/age.git. Now cd into the cloned folder and run the command
sudo make PG_CONFIG=~/postgresql-11.18/bin/pg_config install. Note the argument to PG_CONFIG here is the location of the pg_config file of your PostgreSQL installation. Since, I unzipped the PostgreSQL source code directly into the home folder this was the command executed.
Congratulations!🎉🎉🎉. Now you can start using the PostgreSQL database with the power of Apache AGE and its magical graph powers. Stay tuned for tutorials on using Apache AGE.