2.2 KiB
2.2 KiB
PostgreSQL Setup for Tasko
Prerequisites
- PostgreSQL installed and running on your PC
- psql CLI access
Setup Instructions
1. Run the schema script as postgres superuser:
psql -U postgres -f schema.sql
OR manually in psql:
# Connect as postgres superuser
psql -U postgres
# Then paste the contents of schema.sql
2. Verify the setup:
-- Connect to the database
\c tasko_db
-- List tables
\dt
-- List users
\du
-- Verify tasko_user has correct privileges
\dp
3. Test connection:
psql -U tasko_user -d tasko_db -h localhost
# Password: tasko_password
Configuration
Default credentials (change in production):
- Database:
tasko_db - User:
tasko_user - Password:
tasko_password - Host:
localhost - Port:
5432
Environment Variable (optional):
You can override the connection string by setting:
export DATABASE_URL="postgresql://tasko_user:tasko_password@localhost:5432/tasko_db"
Or on Windows:
set DATABASE_URL=postgresql://tasko_user:tasko_password@localhost:5432/tasko_db
Security Best Practices Applied
✅ Dedicated database user: Created tasko_user instead of using postgres superuser
✅ Limited privileges: Only granted necessary permissions (SELECT, INSERT, UPDATE, DELETE)
✅ No superuser access: tasko_user cannot create/drop databases or modify system tables
✅ Schema isolation: Uses public schema with controlled access
✅ Cascade deletes: Foreign keys properly handle data integrity
Install Python Dependencies
cd backend
pip install -r requirements.txt
This will install:
- psycopg2-binary (PostgreSQL adapter)
- sqlalchemy
- fastapi
- uvicorn
- pydantic
Start the Backend
cd backend
python main.py
The server will start on http://localhost:8001
Troubleshooting
Connection refused:
- Ensure PostgreSQL service is running
- Check if port 5432 is open
- Verify pg_hba.conf allows local connections
Authentication failed:
- Double-check username and password
- Ensure user was created:
\duin psql
Permission denied:
- Re-run the GRANT statements in schema.sql
- Verify with:
\dpin psql