db-check command tests your PostgreSQL database connection and verifies that the database is accessible and responding to queries.
Usage
With Alias
Output Example
Successful Connection
Connection Failed
How It Works
The command performs the following steps:- Load environment variables from
.envfile - Read
DATABASE_URLenvironment variable - Mask password in connection string for security
- Connect to database using SQLx connection pool
- Execute test query (
SELECT 1) to verify database responds - Close connection cleanly
Configuration
The command reads the database connection from theDATABASE_URL environment variable in your .env file:
Environment Variables
| Variable | Required | Description |
|---|---|---|
DATABASE_URL | Yes | PostgreSQL connection string |
DB_MAX_CONNECTIONS | No | Maximum number of connections in pool (default: 5) |
Security Features
Password Masking
The command automatically masks the password in the connection string when displaying output: Before:postgresql://postgres:mypassword@localhost:5432/rustAfter:
postgresql://postgres:****@localhost:5432/rust
This prevents sensitive credentials from being exposed in logs or screenshots.
Troubleshooting
Error: DATABASE_URL not found
- Create a
.envfile in your project root - Add
DATABASE_URL=postgresql://user:password@host:port/database - Run the command again
Error: Connection refused
Possible causes:- PostgreSQL server is not running
- Wrong host or port in
DATABASE_URL - Firewall blocking the connection
-
Start PostgreSQL:
-
Verify PostgreSQL is listening:
Error: Authentication failed
Solution: Verify your username and password inDATABASE_URL:
Error: Database does not exist
Solution: Create the database:When to Use
Use this command to:- Before starting the server: Verify database is ready
- After configuration changes: Test new database settings
- In CI/CD pipelines: Verify database connectivity before deployment
- During debugging: Isolate database connection issues
- After database updates: Verify database is still accessible
Example Workflows
Pre-deployment Check
Debugging Connection Issues
CI/CD Pipeline
Technical Details
Connection Pool
The command uses SQLx’sPgPool for connection pooling. The pool is created, tested, and then properly closed:
Async Runtime
The command runs in an async context using Tokio:Related Commands
Maintenance Mode
Put application in maintenance before database migrations
CLI Overview
View all available CLI commands