How to Install PostgresML on Ubuntu 22.04

Introduction

Before we discuss how to install PostgresML on Ubuntu 22.04, let's first understand- What is PostgresML?

PostgresML is a machine learning extension for PostgreSQL that allows you to perform advanced analytics and machine learning tasks directly within the PostgreSQL database. With PostgresML, you can train and deploy machine learning models, perform data preprocessing, and execute complex queries.

This tutorial will walk you through the process of installing PostgresML on Ubuntu 22.04.

Advantages

  1. Seamless integration: PostgresML integrates machine learning capabilities seamlessly with your existing PostgreSQL infrastructure, eliminating the need for data movement between databases and machine learning platforms.
  2. Simplified workflow: By installing PostgresML, you can streamline your workflow by performing data preprocessing, model training, and inference tasks within the same database environment. This reduces complexities and increases efficiency.
  3. Scalability: PostgresML leverages the scalability of PostgreSQL, allowing you to handle large datasets and perform complex machine learning operations efficiently.
  4. Data security and privacy: With PostgresML, sensitive data remains within your database, reducing the risks associated with data transfers and external processing.
  5. Ecosystem integration: PostgresML integrates seamlessly with other PostgreSQL extensions, libraries, and tools, leveraging the rich ecosystem of PostgreSQL for data analysis and machine learning tasks.

Pre-requisites

Before installing PostgresML on Ubuntu 22.04, there are a few prerequisites that need to be fulfilled:

  1. Ubuntu 22.04: Ensure that you have a functioning installation of Ubuntu 22.04, as PostgresML will be installed on this operating system.
  2. PostgreSQL: PostgresML is an extension for PostgreSQL, so you need to have PostgreSQL installed and configured on your Ubuntu 22 system. You can install PostgreSQL by running the command sudo apt-get install postgresql.
  3. PostgreSQL Development Libraries: To build and install PostgresML, you need to have PostgreSQL development libraries installed. Install them by running sudo apt-get install libpq-dev.
  4. GCC and Make: You require a C compiler and make utility to compile and install the PostgresML extension. Ensure that GCC (GNU Compiler Collection) and make are installed on your system. You can install them using sudo apt-get install gcc make.
  5. Git: Git is necessary to clone the PostgresML repository from GitHub. Install Git by running sudo apt-get install git.

To install PostgresML, you must have Postgres on your system. We will break the installation process into a few steps.

Step 1-Install PostgreSQL

If you have Postgres installed on your system, you can skip this step. However, if you are new to this, you can install PostgreSQL with the following simple commands:

Start by updating your Ubuntu system package.

sudo apt update

Next, install PostgreSQL.

sudo apt install postgresql postgresql-contrib

Once you installed PostgreSQL, start its service as follows:

sudo systemctl start postgresql.service

Now that you have PostgreSQL installed, you can create a user and a database to get started with it. The next step is to install Docker and start its services before we can install the PostgresML.

2. Install Docker

With Docker, you will get a container to comfortably install and build the PostgresML applications. Here, we will install a Docker desktop and need a 64-bit Ubuntu 22.04.

To install the Docker desktop, you can source it from the Docker repository or the Ubuntu repositories. The first thing is to remove the previous Docker versions with the following command:

sudo apt-get remove docker docker-engine docker.io containerd runc

Once you removed the previous versions, update your system and run the following command to install any required prerequisite packages:

sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y

Press y to confirm the installation of all the packages and wait for the process to complete. If sourcing Docker from its official repository, we must add its GPG key for you to install it on the terminal.

So, add the Docker GPG key by executing the following command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

You should also add the Docker repository that you included with the GPG key to the sources list on your Ubuntu. For that, echo the repository with the following command:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

For the system to notice the added Docker repository, ensure that you update the system repository via the apt command.

sudo apt update

At this point, you can now install Docker using the docker-ce package. Run the following command:

sudo apt install docker-ce

Press y to start the installation.

You can verify that Docker has been installed by checking its version.

3. Install PostgresML

You are all set and can now install PostgresML. As an open-source project, installing PostgresML requires you to access its GitHub code, clone it, and build the project using the docker-compose command.

Let’s start by using git to clone the PostgresML repository with the following command:

sudo git clone https://github.com/postgresml/postgresml.git

The cloning will run up to 100%. Once it completes, you should get an output that is similar to the one in the previous image. You will notice a new directory; postgresml has been created.

Navigate into that folder using the cd command.

The last step is to use the docker run command to run the PostgresML database in the containers. Once you execute the command, it will start running PostgresML.

docker run \
    -it \
    -v postgresml_data:/var/lib/postgresql \
    -p 5433:5432 \
    -p 8000:8000 \
    ghcr.io/postgresml/postgresml:2.7.12 \
    sudo -u postgresml psql -d postgresml

Ensure that you have a stable internet connection and adequate space. Once the process completes, you will successfully manage to install PostgresML on Ubuntu 22.04 and can start using it.

Suppose you don’t want this hassle of having to install Docker and go through the cloning and building of PostgresML. You have the option to access the online version of PostgresML where you can sign up and enjoy a working space with 5 GB of data that you can utilize to create your scalable AI-powered solutions. Check out the PostgresML official page and sign up to get started.

FAQs to Install PostgresML on Ubuntu 22.04

How do I install PostgreSQL on Ubuntu 22.04?

You can install PostgreSQL on Ubuntu 22 by running the command sudo apt-get install postgresql. Ensure that you have the appropriate repositories enabled beforehand.

What machine learning capabilities does PostgresML provide?

PostgresML offers various machine learning capabilities, including data preprocessing, model training and deployment, prediction scoring, and data transformation tasks.

Can I use PostgresML with existing machine learning frameworks?

Yes, you can integrate PostgresML with existing machine learning frameworks like TensorFlow, Scikit-learn, or PyTorch by leveraging PostgresML's ability to execute SQL queries and pass the results to the machine learning frameworks.

Does PostgresML support distributed computing?

PostgresML itself does not provide distributed computing capabilities. However, you can use PostgreSQL's built-in features like parallel query execution for improved performance on distributed systems.

What programming languages can I use with PostgresML?

PostgresML can be used with any programming language that offers PostgreSQL driver support, such as Python, Java, or Ruby.

Is PostgresML suitable for large-scale machine learning tasks?

Yes, PostgresML is designed to handle large-scale machine learning tasks by utilizing the scalability and performance of PostgreSQL.

Is PostgresML open source?

Yes, PostgresML is an open-source project distributed under a permissive license.

Conclusion

Installing PostgresML on Ubuntu 22.04 provides a powerful solution for integrating machine learning capabilities within your PostgreSQL database. With seamless integration, simplified workflows, scalability, and data security, PostgresML offers a comprehensive environment for performing advanced analytics and machine learning tasks.

We hope this tutorial helped you to understand how to install PostgresML on Ubuntu 22.04.

If you have any questions, feel free to ask them in the comments section and, we would be happy to respond to them....