
a gordeThis is a step-by-step guide for making a private cloud database for your projects for start you just...
This is a step-by-step guide for making a private cloud database for your projects for start you just need a cloud server
usecase:
Im using OVH Cloud as a VM with ubuntu.
# Update the package list to get info on the newest versions of packages
$ sudo apt update
# Install PostgreSQL database server and additional utilities/extensions
$ sudo apt install -y postgresql postgresql-contrib
# Start the PostgreSQL service immediately
$ sudo systemctl start postgresql
# Enable PostgreSQL to start automatically on every system boot
$ sudo systemctl enable postgresql
1- Start PostgreSQL 17
# Start the PostgreSQL cluster (version 17, cluster name "main")
$ sudo pg_ctlcluster 17 main start
# List all PostgreSQL clusters with their version, name, port, status, and data directory
$ sudo pg_lsclusters
2- Create DB and user
# Creating database and setting user
$ sudo -u postgres psql
CREATE DATABASE twohype;
CREATE USER twohype_user WITH PASSWORD 'yourpassword';
GRANT ALL PRIVILEGES ON DATABASE twohype TO twohype_user;
\q
3.1- Allow remote connections
# Open the main PostgreSQL 17 configuration file in the nano text editor
# Find and enable; listen_addresses = '*'
$ sudo nano /etc/postgresql/17/main/postgresql.conf
3.2- Allow remote connections
# Open the host-based configuration file
$ sudo nano /etc/postgresql/17/main/pg_hba.conf
# Add at the bottom:
host all all 0.0.0.0/0 md5
# Restart the PostgreSQL service
$ sudo systemctl restart postgresql@17-main
# Allow incoming TCP traffic on port 5432
$ sudo ufw allow 5432/tcp
Note: if your not with root user you might have to enable rule from your VM console
VoilĂ ! You've just got your personal cloud-based database, which you can use anywhere with
DATABASE_URL="postgresql://twohype_user:yourpassword@YOUR_VM_IP:5432/twohype"