Overview
Med Agenda uses PostgreSQL as its primary database. The application supports both self-hosted PostgreSQL instances and managed database services like Neon.tech.Database Requirements
- PostgreSQL Version: 12 or higher (15+ recommended)
- Extensions: None required (uses standard PostgreSQL features)
- Encoding: UTF-8
- Timezone: UTC recommended
Database Schema
Med Agenda uses JPA/Hibernate for automatic schema management. The application manages the following main entities:Core Tables
Patients
Patient records with medical history and personal information
Doctors
Medical professionals with specialties and consultation rates
Consultations
Appointment scheduling and management
Diagnosis
Medical diagnoses linked to consultations with CID codes
Additional Tables
- Admin: Administrative users
- Payment: Payment transactions
- News: System announcements
- CID: International Classification of Diseases codes
- GuiaDefinicao: Medical guidelines
- HabilidadeMedica: Medical skills and specialties
Installation Methods
- Neon.tech (Recommended)
- Local PostgreSQL
- Cloud Providers
Using Neon.tech Managed PostgreSQL
Neon.tech provides serverless PostgreSQL with automatic scaling and branching.Create a Neon account
Sign up at neon.tech
Create a new project
- Click “New Project”
- Choose a region close to your deployment
- Select PostgreSQL version (15+ recommended)
Neon.tech includes SSL by default. Always use
sslmode=require in the connection string.Connection Configuration
Connection String Format
The JDBC connection string follows this format:Common Connection Parameters
SSL connection mode. Use
require for production.Options: disable, allow, prefer, require, verify-ca, verify-fullDefault schema to use
Connection timeout in seconds
Socket timeout in seconds (0 = infinite)
Example Connection Strings
Schema Management
Med Agenda uses Hibernate for automatic schema management.DDL Auto Modes
Configure schema behavior withJPA_DDL_AUTO environment variable:
- update (Default)
- validate
- create
- none
- Automatically updates schema based on entities
- Adds new tables and columns
- Does not remove columns or tables
- Recommended for development
Connection Pool Configuration
Med Agenda uses HikariCP for connection pooling.Pool Settings
.env
Recommended Pool Sizes
| Environment | Max Pool Size | Notes |
|---|---|---|
| Development | 5-10 | Sufficient for local testing |
| Staging | 10-20 | Moderate concurrent users |
| Production | 20-50 | Based on expected load |
| High Traffic | 50-100 | Monitor and adjust |
Start with smaller pool sizes and increase based on monitoring. Too many connections can overload the database.
Database Initialization
First Time Setup
When running Med Agenda for the first time:Start application
The application will automatically create tables on first run (if
JPA_DDL_AUTO=update)Seed Data (Optional)
To add initial data, connect to your database and run:Backup and Recovery
Backup Database
Restore Database
Automated Backups
Set up automated backups with cron:Monitoring and Maintenance
Check Database Size
Table Sizes
Active Connections
Vacuum and Analyze
Regularly maintain database performance:Troubleshooting
Connection refused
Connection refused
Check if PostgreSQL is running:Verify firewall allows connections on port 5432.
Authentication failed
Authentication failed
Verify credentials are correct:Check
pg_hba.conf authentication settings.Schema validation errors
Schema validation errors
If using
JPA_DDL_AUTO=validate and getting errors:Too many connections
Too many connections
Reduce connection pool size:Or increase PostgreSQL max_connections in
postgresql.conf.Slow queries
Slow queries
Enable query logging:Check and optimize slow queries. Add indexes where needed.
Next Steps
Environment Variables
Configure database connection strings
API Reference
Explore the Med Agenda API