Overview
Relaciona uses PostgreSQL as its primary database. This guide covers local installation, configuration, and cloud database setup.Local PostgreSQL Installation
macOS
Linux (Ubuntu/Debian)
Windows
- Download installer from postgresql.org/download/windows
- Run the installer and follow the setup wizard
- Remember the password you set for the
postgresuser
Database Creation
Connection Configuration
Configure your database connection using environment variables. Create or update your.env file:
.env
relaciona/settings.py:
settings.py
Running Migrations
After configuring the database connection, apply Django migrations to create all necessary tables:Common Migration Errors
Common Migration Errors
Error: FATAL: password authentication failed
- Check that
DB_PASSWORDmatches the password you set - Verify
DB_USERis correct
- Create the database:
CREATE DATABASE relaciona; - Check
DB_NAMEmatches your database name
- Create the user:
CREATE USER relaciona_user WITH PASSWORD 'password';
- Ensure PostgreSQL is running:
sudo systemctl status postgresql - Check
DB_HOSTandDB_PORTare correct - For cloud databases, verify security groups allow your IP
Creating a Superuser
Create an admin account to access the Django admin panel:- Username (or email, depending on your custom user model)
- Email address
- Password (entered twice for confirmation)
http://localhost:8000/admin/
Database Verification
Check Connection
Verify Django can connect to your database:View Database Contents
Check that migrations created the expected tables:Loading Fixtures (Optional)
If you have sample data or fixtures to load:Creating Fixtures
Creating Fixtures
Export current database data to fixtures:
Cloud Database Setup
AWS RDS (PostgreSQL)
Create RDS Instance
- Navigate to AWS RDS Console
- Click Create database
- Choose PostgreSQL
- Select Free tier template (if eligible)
- Set DB instance identifier:
relaciona-db - Set Master username:
relaciona_admin - Set Master password: (use a strong password)
Configure Settings
- DB instance class:
db.t3.micro(free tier eligible) - Storage: 20 GB (free tier eligible)
- Public access: Yes (if connecting from outside AWS)
- VPC security group: Create new or use existing
Configure Security Group
Add inbound rule to allow PostgreSQL connections:
- Type: PostgreSQL
- Port: 5432
- Source: Your IP address or
0.0.0.0/0(less secure)
Render PostgreSQL
Render provides managed PostgreSQL databases:Create Database
- In Render dashboard, click New +
- Select PostgreSQL
- Set Name:
relaciona-db - Choose Free plan
- Click Create Database
Get Connection Info
Render provides:
- Internal Database URL (for Render services)
- External Database URL (for external connections)
Vercel + External PostgreSQL
Vercel doesn’t provide databases, but you can connect to external providers:- Create database on:
- Add environment variables in Vercel project settings
- Note: Vercel’s serverless nature may require connection pooling for PostgreSQL
Database Backups
Manual Backup
Restore from Backup
Automated Backups
AWS RDS: Enable automated backups in RDS console (retention: 1-35 days) Render: Automatic daily backups included with paid plans Self-hosted: Set up cron job:Performance Optimization
Connection Pooling
For production, consider using connection pooling:Indexes
Django automatically creates indexes for:- Primary keys
- Foreign keys
- Fields with
db_index=True
Next Steps
Environment Variables
Configure database connection variables
Cloud Deployment
Deploy to AWS, Render, or Vercel
Configuration
Django settings overview