Connection URL Format
PostgreSQL connections use the following URL format:All three schemes (
postgres://, postgresql://, psql://) are supported and will be normalized to postgresql:// internally.URL Components
- user - PostgreSQL username
- password - User password (optional)
- host - Database server hostname or IP address
- port - Database port (default: 5432)
- database - Database name
- sslmode - SSL mode (e.g.,
disable,require,verify-ca,verify-full)
Setup
Configuration Examples
- Local Development
- Production
- Docker Compose
Features
Transaction Support
PostgreSQL migrations run in transactions by default. To disable transactions for a specific migration, add a comment at the top of your migration file:Schema Dumping
Geni automatically dumps your PostgreSQL schema after each successful migration without requiring external binaries. The schema dump includes:- Extensions - PostgreSQL extensions installed in the public schema
- Tables - Table definitions with columns and data types
- Views - View definitions
- Constraints - Primary keys, foreign keys, unique constraints, and check constraints
- Indexes - Index definitions
- Sequences - Sequence definitions
- Comments - Table and column comments
postgres.rs:189-446).
PostgreSQL schema dumping works out of the box without requiring
pg_dump or any external tools.Wait Timeout
Geni can wait for PostgreSQL to be ready before running migrations. This is useful in containerized environments where the database might need time to start.postgres.rs:34-54).
Parameterized Queries
PostgreSQL uses numbered parameters ($1, $2, etc.) for prepared statements. Geni handles this automatically when tracking migrations:
Database Operations
Create Database
CREATE DATABASE {database_name}
Drop Database
DROP DATABASE {database_name}
Check Status
schema_migrations table.
Limitations
None. PostgreSQL is fully supported with all Geni features.Examples
Basic Migration
Create a table in20240115120000_create_users.up.sql:
20240115120000_create_users.down.sql:
Advanced Features
Using PostgreSQL-specific features:Troubleshooting
Connection Issues
If you see connection errors, verify:- PostgreSQL is running and accessible
- Hostname and port are correct
- User credentials are valid
- Database exists (or use
geni create) - SSL mode is appropriate for your setup
Migration Table
Geni creates aschema_migrations table to track applied migrations: