Tuesday, October 22, 2024

How to Install PostgreSQL on Debian 12: A Step-by-Step Guide

PostgreSQL, commonly known as Postgres, is a powerful, open-source relational database management system renowned for its advanced features and reliability. In this comprehensive step-by-step tutorial, we will guide you through the process of installing PostgreSQL on a Debian 12 system

Step 1: Update the System

Start by ensuring your Debian 12 system is up to date.  Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade

This command will update the package list and upgrade existing packages on your system

Step 2: Install PostgreSQL

To install PostgreSQL on Debian 12, use the following command:

sudo apt install postgresql postgresql-contrib

This command will install both the PostgreSQL server and additional contrib packages that provide useful extensions and utilities

Step 3: Start and Enable PostgreSQL

PostgreSQL should start automatically after installation

However, to ensure it starts at boot, use the following command:

sudo systemctl enable postgresql

To check the status of the PostgreSQL service, use:

sudo systemctl status postgresql

Step 4: Create a PostgreSQL User and Database

Let’s create a new PostgreSQL user and database

Replace your_user and your_database with your preferred values:

sudo -u postgres createuser your_user sudo -u postgres createdb -O your_user your_database

To access the PostgreSQL command-line tool, psql, use the following command:

sudo -u postgres psql -d your_database

Once in the psql prompt, execute the following SQL commands to create a basic table:

CREATE TABLE example ( id serial PRIMARY KEY, name VARCHAR (100), age INT );

Step 5: Managing the PostgreSQL Service

To manage the PostgreSQL service on Debian 12, you can use the following commands

  •     Start PostgreSQL service:
sudo systemctl start postgresql
  • Stop PostgreSQL service:
sudo systemctl stop postgresql
  • Restart PostgreSQL service:
sudo systemctl restart postgresql
  • Check PostgreSQL service status:
sudo systemctl status postgresql

Congratulations! You have successfully installed PostgreSQL on your Debian 12 server, created a database, and learned how to perform basic management tasks

PostgreSQL’s extensive feature set makes it a versatile choice for various data storage needs.

How to Install ifconfig on Debian

Do you see ifconfig command not found error in Debian? Here is my quick tutorial on how to install it on Debian.

 

I have made fresh install of Debian 12 server on my VM and  i wanted to check IP of VM and I have encountered the problem:

 The ifconfig package is not included by default in Debian since it is being phased out in favor of the ip command. The ip command now handles tasks such as modifying or displaying routing, network devices, interfaces, and tunnels."

 If we still want to use the good old ifconfig command, you'll have to install it explicitly.

 

Installing ifconfig command in Debian 

The ifconfig is not a package in its own. It is installed with net-tools package that has some additional networking tools. 

So to get ifconfig, you need to install net-tools package like this:

sudo apt install net-tools

After install you can use the command:


However, I strongly advise you should start using the IP command. Sooner or later, net-tools will be completely deprecated and you won't be able to install it.

How to Install PostgreSQL on Debian 12: A Step-by-Step Guide

PostgreSQL, commonly known as Postgres, is a powerful, open-source relational database management system renowned for its advanced features ...