PostgreSQL is one of the most powerful, open-source relational database systems used by developers, database administrators, and large enterprises across the globe. It offers high reliability, robust performance, and extensive features such as support for advanced data types, full ACID compliance, and concurrent transaction handling. If you're working on Ubuntu 24.04 and want to harness the capabilities of PostgreSQL, this guide will walk you through how to install PostgreSQL on Ubuntu 24.04 by using instructions from Vultr’s official documentation.
Why Choose PostgreSQL?
PostgreSQL, often referred to as Postgres, is a free and open-source database system that supports both SQL and JSON for relational and non-relational queries. It's highly extensible and supports custom data types, indexing methods, and procedural languages. This makes it ideal for applications ranging from simple websites to complex, data-heavy enterprise applications.
Some key features include:
Strong data integrity and security
Full support for ACID transactions
Advanced indexing and full-text search
JSON support for hybrid data storage
Extensibility with plugins and custom functions
Why Install PostgreSQL on Ubuntu 24.04?
Ubuntu 24.04 is the latest Long-Term Support (LTS) version, offering enhanced security, stability, and updated packages. Installing PostgreSQL on this OS ensures you're using the latest tools in a secure and efficient Linux environment. With 5 years of official support, Ubuntu 24.04 is ideal for long-term projects, databases, and development environments.
Prerequisites
Before you begin the installation, make sure your system meets the following requirements:
You are using Ubuntu 24.04
You have a sudo-enabled user account
Your system is connected to the internet
Update your system's package list and upgrade existing packages:
sudo apt update && sudo apt upgrade -y
Step 1: Install PostgreSQL on Ubuntu 24.04
Ubuntu’s default repositories already include PostgreSQL, making it easy to install. Run the following command to install PostgreSQL along with additional useful utilities:
sudo apt install postgresql postgresql-contrib -y
postgresql: Installs the core PostgreSQL server
postgresql-contrib: Installs additional modules and tools like tablefunc and adminpack
Step 2: Verify the PostgreSQL Installation
After installation, PostgreSQL starts automatically. You can verify the service status by running:
sudo systemctl status postgresql
If everything is set up correctly, you’ll see the service is active (running). You can also manage the PostgreSQL service with the following commands:
sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql
Step 3: Access the PostgreSQL Shell
PostgreSQL creates a default user named postgres. You’ll need to switch to this user to access the PostgreSQL command-line interface:
sudo -i -u postgres
psql
Now you're in the PostgreSQL shell where you can execute SQL commands. To exit, simply type:
\q
Step 4: Create a New User and Database
You can create a new PostgreSQL user by running:
createuser --interactive
PostgreSQL will prompt you to enter a username and define user privileges.
To create a new database:
createdb mydatabase
You can then connect to it using:
psql mydatabase
Step 5: Enable Remote Access (Optional)
If you want PostgreSQL to accept connections from other machines:
Open the PostgreSQL configuration file:
sudo nano /etc/postgresql/16/main/postgresql.conf
Find and change the listen_addresses line to:
listen_addresses = '*'
Modify the pg_hba.conf file:
sudo nano /etc/postgresql/16/main/pg_hba.conf
Add this line to allow remote connections:
host all all 0.0.0.0/0 md5
Finally, restart the PostgreSQL service:
sudo systemctl restart postgresql
Conclusion
Now you know how to install PostgreSQL on Ubuntu 24.04 using a simple and reliable method. With PostgreSQL running on the latest Ubuntu LTS version, you can build high-performance, scalable applications with confidence. For more detailed instructions and troubleshooting, refer to the official Vultr guide.
Whether you're a beginner or experienced developer, PostgreSQL on Ubuntu 24.04 provides a solid foundation for secure, efficient database management in 2024 and beyond.