Beginner’s Tutorial: How to Install PostgreSQL on Debian 12 Using Vultr Docs

HemanJone

New member
Jun 29, 2025
4
0
1
PostgreSQL is a powerful, open-source relational database system known for its robustness, performance, and full compliance with SQL standards. If you’re using Debian 12 and looking for a reliable way to set up PostgreSQL, this beginner-friendly guide—based on the comprehensive instructions from Vultr Docs—will walk you through the process step-by-step.

Whether you're a student, developer, or small business owner, learning how to install PostgreSQL on Debian 12 is essential if you're working with data-driven applications.


Step 1: Update Your Debian System​

Before installing anything, always make sure your system is up to date. Open the terminal and run:

sudo apt update && sudo apt upgrade -y


This ensures all existing packages are current, minimizing the risk of dependency conflicts during PostgreSQL installation.

Step 2: Install PostgreSQL on Debian 12​

Debian 12 includes PostgreSQL in its default APT repositories. To install it, simply run:

sudo apt install postgresql postgresql-contrib -y


This command installs the core PostgreSQL server and additional useful utilities (postgresql-contrib), such as pg_stat_statements and other handy extensions.






Step 3: Check PostgreSQL Status​

After installation, the PostgreSQL service starts automatically. You can verify this with:

sudo systemctl status postgresql


If it’s running, you’ll see a green “active (running)” message. This means your database server is ready.


Step 4: Switch to the PostgreSQL User​

PostgreSQL creates a default user named postgres. To access the PostgreSQL shell:

sudo -i -u postgres

psql


Inside the psql shell, you can now create databases, users, and run SQL queries.

Step 5: Create a New User and Database​

To create a new PostgreSQL user and database, execute:

CREATE USER yourusername WITH PASSWORD 'yourpassword';

CREATE DATABASE yourdatabase OWNER yourusername;


Once done, type \q to exit the PostgreSQL prompt.


Step 6: Enable Remote Access (Optional)​

By default, PostgreSQL only allows local connections. To enable external access:

Edit the configuration file:

sudo nano /etc/postgresql/15/main/postgresql.conf


Change the line:

listen_addresses = '*'

  • Then, edit the pg_hba.conf file to allow remote users.
Restart PostgreSQL to apply changes:

sudo systemctl restart postgresql



Final Thoughts​

The Vultr Docs guide on how to install PostgreSQL on Debian 12 offers a reliable foundation for beginners and professionals alike. By following these steps, you can set up a secure, efficient PostgreSQL environment ready for development or production use.

For ongoing configuration, performance tuning, and backups, refer to the official PostgreSQL documentation or additional Vultr tutorials.

Got questions or hit a snag? Reply below or share your setup tips!
 
Last edited: