Databases
How to Install and Secure PostgreSQL & Redis on Ubuntu 24.04
PostgreSQL is an advanced, enterprise-grade relational database, while Redis provides ultra-fast in-memory caching and message queuing. This guide covers installing and securing both on Ubuntu 22.04 / 24.04.
1. Install PostgreSQL
bash
sudo apt update
sudo apt install -y postgresql postgresql-contribEnable and verify PostgreSQL service:
bash
sudo systemctl enable --now postgresql
sudo systemctl status postgresql2. Create PostgreSQL Database & User
Switch to the postgres user and enter the interactive SQL shell:
bash
sudo -u postgres psqlRun the following SQL commands:
sql
CREATE USER appuser WITH ENCRYPTED PASSWORD 'SuperSecretPassword123!';
CREATE DATABASE appdb OWNER appuser;
GRANT ALL PRIVILEGES ON DATABASE appdb TO appuser;
\q3. Install & Configure Redis
Install Redis server:
bash
sudo apt install -y redis-serverConfigure Redis memory limits and password authentication:
bash
sudo nano /etc/redis/redis.confSet or uncomment the following lines:
ini
supervised systemd
maxmemory 256mb
maxmemory-policy allkeys-lru
requirepass YourStrongRedisPasswordHere!Restart Redis to apply changes:
bash
sudo systemctl restart redis-server4. Test Connections
Test PostgreSQL:
bash
psql -U appuser -d appdb -h 127.0.0.1 -WTest Redis:
bash
redis-cli -a "YourStrongRedisPasswordHere!" ping
# Returns: PONGKVM Linux VPS
Looking for the right Linux VPS?
Put your project into practice right away: Our KVM VPS provide full root access, lightning-fast NVMe storage, and reliable KVM isolation. Flexible prepaid billing with no subscription and personal Discord support.
Full Root Access (SSH)
Datacenter NVMe SSD
4+ Tbps DDoS Protection
100% Prepaid (No Subscription)