R2R Troubleshooting Guide: Incorrect Database Credentials
Database connectivity issues due to incorrect credentials are a common problem when deploying R2R. This guide will help you identify and resolve these issues.Symptoms
- Error messages containing phrases like “authentication failed”, “access denied”, or “connection refused”
- R2R application fails to start or crashes shortly after starting
- Database-related operations fail while other parts of the application seem to work
Diagnosis Steps
-
Check Error Logs
- Review R2R application logs for specific error messages
- Look for database-related errors, especially those mentioning authentication or connection issues
-
Verify Environment Variables
- Ensure all database-related environment variables are set correctly
- Common variables include:
-
Test Database Connection
- Use a database client tool to test the connection with the same credentials
- For PostgreSQL, you can use the
psql
command-line tool:
-
Check Database Server Status
- Ensure the database server is running and accessible from the R2R container
- Verify network connectivity between R2R and the database server
-
Inspect Docker Compose File
- Review the
docker-compose.yml
file to ensure database service configuration is correct - Check for any discrepancies between the database service and R2R service configurations
- Review the
Resolution Steps
-
Correct Environment Variables
- Update the
.env
file or set environment variables with the correct database credentials - Ensure these variables are properly passed to the R2R container
- Update the
-
Update Docker Compose File
- If using Docker Compose, update the
docker-compose.yml
file with the correct database configuration - Ensure the database service name matches what R2R is expecting (e.g.,
postgres
)
- If using Docker Compose, update the
-
Rebuild and Restart Containers
- After making changes, rebuild and restart your Docker containers:
- After making changes, rebuild and restart your Docker containers:
-
Check Database User Permissions
- Ensure the database user has the necessary permissions
- For PostgreSQL, you might need to grant permissions:
-
Verify Database Existence
- Ensure the specified database exists
- Create it if necessary:
-
Check Network Configuration
- If using Docker, ensure the database and R2R services are on the same network
- Verify firewall rules allow traffic between R2R and the database
-
Use Secrets Management
- Consider using Docker secrets or a secure vault for managing sensitive credentials
- Update your Docker Compose file to use secrets instead of environment variables for passwords
Prevention Tips
- Use a
.env
file for local development and CI/CD pipelines for production to manage environment variables - Implement a health check in your Docker Compose file to ensure the database is ready before starting R2R
- Use database connection pooling to manage connections efficiently
- Regularly audit and rotate database credentials
- Use least privilege principle when setting up database users for R2R
Debugging Commands
Here are some useful commands for debugging database connection issues:-
Check if PostgreSQL is running:
-
View PostgreSQL logs:
-
Check R2R logs:
-
Access PostgreSQL CLI within the container:
Seeking Further Help
If you’ve tried these steps and are still experiencing issues:- Check the R2R documentation for any specific database setup requirements
- Review the R2R GitHub issues for similar problems and solutions
- Reach out to the R2R community on Discord or GitHub for support
- Provide detailed information about your setup, including:
- R2R version
- Database type and version
- Relevant parts of your Docker Compose file
- Specific error messages you’re encountering