DEV Community

Cover image for Install Postgres on Ubuntu from Source
Arunesh Choudhary
Arunesh Choudhary

Posted on

Install Postgres on Ubuntu from Source

About Postgres

A robust relational database management system (RDBMS) that is open-source and has grown in popularity recently is PostgreSQL. Since its initial release in 1996, a committed development community has continued to develop and support it.

One of PostgreSQL's distinguishing characteristics is its capacity for handling sophisticated SQL features like stored procedures, triggers, and views. Because of this, it is a fantastic option for enterprise-level applications that need complicated data handling.

The scalability of PostgreSQL is a key component. It is appropriate for high-traffic applications since it supports several concurrent connections and can manage huge datasets.

Additionally, PostgreSQL is known for being a trustworthy and safe database management system. To safeguard sensitive data from unauthorized access, it offers strong data encryption and access control features.

Additionally, PostgreSQL places a high priority on extensibility, making it simple to add new functions and data types. As a result, it functions as a versatile database management system that can be modified to suit certain business requirements.

Overall, PostgreSQL is a feature-rich database management system that is adaptable and capable of handling challenging data administration jobs. It's a great option for a variety of applications thanks to its scalability, security, and flexibility.

Install Postgres on Ubuntu

Let's install Postgres on Ubuntu
Here I am going to choose version 14 for Postgres.

Install the dependencies required to build PostgreSQL:

sudo apt update
sudo apt install build-essential libreadline-dev zlib1g-dev libssl-dev libxml2-dev libxslt-dev
Enter fullscreen mode Exit fullscreen mode

Download the source code for PostgreSQL from the official website:

curl -LO https://ftp.postgresql.org/pub/source/v14.7/postgresql-14.7.tar.gz
Enter fullscreen mode Exit fullscreen mode

Extract the source code archive:

tar xvf postgresql-14.7.tar.gz
Enter fullscreen mode Exit fullscreen mode

Change to the directory where the source code was extracted:

cd postgresql-14.7
Enter fullscreen mode Exit fullscreen mode

*Configure the build options by running the following command:
*

./configure
Enter fullscreen mode Exit fullscreen mode

Build the PostgreSQL binaries by running:

make
Enter fullscreen mode Exit fullscreen mode

Install PostgreSQL by running:

sudo make install
Enter fullscreen mode Exit fullscreen mode

Initialize the database cluster by running:

sudo /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
Enter fullscreen mode Exit fullscreen mode

Start the PostgreSQL server by running:

sudo /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
Enter fullscreen mode Exit fullscreen mode

You can then connect to the PostgreSQL server by running:

sudo -u postgres /usr/local/pgsql/bin/psql
Enter fullscreen mode Exit fullscreen mode

That's it! You now have a working installation of PostgreSQL from source on your Ubuntu system.

The default configuration will build the server and utilities, as well as all client applications and interfaces that require only a C compiler. All files will be installed under /usr/local/pgsql by default.

Issues I faced:

configure: error: readline library not found

sudo apt install libreadline-dev
Enter fullscreen mode Exit fullscreen mode

Top comments (0)