Skip to main content
PostgreSQL is a powerful, open-source object-relational database system. It is a highly scalable, SQL-compliant database management system that is used to handle large workloads. PostgreSQL is a popular choice for many developers and organizations due to its robust features, extensibility, and reliability. In this tutorial, we will walk you through the process of setting up PostgreSQL on Ubuntu on a VPS.

Install PostgreSQL

Check PostgreSQL is running

Make sure the service is running

Use psql to connect to the database

This will open a CLI where you can run SQL commands. After first launching psql, you may check the details of your connection by typing \conninfo into the interpreter.

List databases

Create a database

List databases

List tables

Setup PostgreSQL server

Open the file /etc/postgresql/<version>/main/postgresql.conf and add the following lines:
This will allow connections from any IP address. This is not recommended for production environments.

Connection Settings

Add the following lines in /etc/postgresql/<version>/main/pg_hba.conf:

Restart the PostgreSQL server:

This server will be accessible at localhost:5432 if your backend server is running on the same machine. If you are running the backend server on a different machine, you will need to configure the host and port settings in the .env file.

Summary

In this tutorial, we have learned how to set up PostgreSQL on Ubuntu on a VPS. We have also learned how to create a database, list tables and configure connection settings.

Next: Advanced Node.js Logging

Continue your journey by learning how to master Winston and Morgan for production logging.