What is a Database?
A database in Suga is a PostgreSQL database that:- Stores structured data - Tables, relations, indexes
- Provides SQL access - Full PostgreSQL compatibility
- Scales automatically - Managed database service
- Integrates with services - Automatic connection configuration
Basic database
Database Configuration
Access Control and Connection Strings
When you grant a service access to a database, Suga automatically injects the database connection string into that service’s environment variables:Database with environment variable injection
- Full connection string - Including host, port, database name, and credentials
- Environment variable - Specified by
env_var_key - Ready to use - Works immediately with standard PostgreSQL libraries
query- Full read/write SQL access
Multiple Databases
When using multiple databases, each must have a uniqueenv_var_key to avoid conflicts:
Multiple databases with unique env vars
api service receives three separate connection strings:
USERS_DATABASE_URLPRODUCTS_DATABASE_URLORDERS_DATABASE_URL
Using Databases in Code
Access databases using standard PostgreSQL libraries with the automatically injected connection string:- Node.js
- Python
- Go
Install the PostgreSQL client:Then develop like you normally would, using the
env_var_key you defined in your suga.yaml.Connection String Format
The injectedDATABASE_URL contains everything needed to connect:
- Prisma
- TypeORM
- SQLAlchemy
prisma/schema.prisma
Database Migrations
Run migrations as part of your deployment:Database Migrations Guide
Learn how to manage database schema changes
Local Development
Duringsuga dev, PostgreSQL databases run automatically with no manual setup required:
- Suga starts a local PostgreSQL instance for each database
- Connection strings are injected into services via
env_var_key - Data persists in
.suga/databases/between sessions - Use the same PostgreSQL libraries and ORMs as production
DATABASE_URL (or your custom env_var_key) automatically, making the same code work in both local development and production.
Local Development Guide
Learn more about local development with databases