Troubleshooting Guide
Troubleshooting Guide
Section titled “Troubleshooting Guide”This comprehensive guide helps you diagnose and resolve common issues with DBCrust. Whether you’re experiencing connection problems, performance issues, or unexpected behavior, this guide provides systematic solutions and debugging techniques.
🚀 Quick Diagnostics
Section titled “🚀 Quick Diagnostics”First Steps for Any Issue
Section titled “First Steps for Any Issue”# Check DBCrust version and environmentdbcrust --versiondbcrust --debug postgres://localhost/test_connection
# Test basic connectivitydbcrust postgres://localhost/postgres -c "SELECT 1;"
# Check configurationdbcrust --show-config
# Enable debug logging for detailed informationexport DBCRUST_DEBUG=1dbcrust your_connection_urlCommon Quick Fixes
Section titled “Common Quick Fixes”# Reset DBCrust configurationrm -rf ~/.config/dbcrust/dbcrust postgres://localhost/db # Will recreate default config
# Clear session data and cachedbcrust postgres://localhost/db\resetview\clrcs\config reset
# Update DBCrust to latest versionpip install --upgrade dbcrust# orcargo install --force dbcrust🔌 Connection Issues
Section titled “🔌 Connection Issues”Database Connection Failures
Section titled “Database Connection Failures”Problem: “Connection refused” or “Connection timeout”
# Debug connection step by stepdbcrust --debug postgres://localhost:5432/mydb
# Test specific connection componentsping localhost # Test network connectivitytelnet localhost 5432 # Test port accessibility (PostgreSQL)telnet localhost 3306 # Test port accessibility (MySQL)telnet localhost 8123 # Test port accessibility (ClickHouse)psql -h localhost -p 5432 -U user -d mydb # Test with native client (PostgreSQL)mysql -h localhost -u user -p database # Test with native client (MySQL)curl http://localhost:8123/ # Test ClickHouse HTTP interfaceCommon solutions:
- Database not running: Start your database service
- Wrong port: Check database port (5432 for PostgreSQL, 3306 for MySQL, 8123 for ClickHouse)
- Firewall issues: Open database port in firewall
- Host binding: Ensure database accepts connections from your IP
- ClickHouse HTTP interface: Ensure ClickHouse HTTP interface is enabled (default port 8123)
Problem: “Authentication failed” or “Access denied”
# Test credentials manuallypsql -h localhost -U username -d database # PostgreSQLmysql -h localhost -u username -p database # MySQLcurl -u user:password http://localhost:8123/ # ClickHouse
# Check credential filescat ~/.pgpass # PostgreSQL passwordscat ~/.my.cnf # MySQL configurationSolutions:
- Verify credentials: Ensure username/password are correct
- Check .pgpass/.my.cnf: Verify credential file format
- Database permissions: Grant user access to specific database
- SSL requirements: Add
?sslmode=requireif needed - ClickHouse authentication:
- Check if
CLICKHOUSE_SKIP_USER_SETUP=1is set (no password needed) - Verify ClickHouse user configuration in
users.xml - Test with default user if no custom users configured
- Check if
SSH Tunnel Connection Issues
Section titled “SSH Tunnel Connection Issues”Problem: SSH tunnel fails to establish
# Test SSH connection manuallyssh -p 2222 user@jumphost.example.comssh -L 5433:db.internal.com:5432 user@jumphost.example.com
# Debug DBCrust SSH tunneldbcrust --debug --ssh-tunnel user@jumphost.example.com postgres://db.internal.com/mydbCommon SSH tunnel issues:
# SSH key authenticationssh-add ~/.ssh/id_rsa # Add SSH key to agentssh-keygen -t rsa -b 4096 # Generate new SSH key if needed
# SSH configurationcat ~/.ssh/config# Host jumphost# HostName jumphost.example.com# User your_user# Port 2222# IdentityFile ~/.ssh/id_rsa
# Test tunnel manuallyssh -L 5433:db.internal.com:5432 user@jumphost.example.com -N -vDocker Container Connection Issues
Section titled “Docker Container Connection Issues”Problem: Cannot connect to database in Docker container
# List running containersdocker ps
# Check container logsdocker logs postgres-container
# Test container connectivitydocker exec -it postgres-container psql -U postgres
# Debug DBCrust Docker connectiondbcrust --debug docker://postgres-container/mydbCommon Docker issues:
- Container not running:
docker start container-name - Wrong container name: Use
docker psto verify names - Network issues: Ensure container is on correct network
- Port mapping: Check if ports are properly exposed
Vault Integration Issues
Section titled “Vault Integration Issues”Problem: Vault authentication failures
# Test Vault connectivityvault statusvault auth -method=userpass username=myuser
# Check Vault configurationecho $VAULT_ADDRecho $VAULT_TOKEN
# Debug DBCrust Vault connectiondbcrust --debug vault://role@mount/databaseVault troubleshooting steps:
# Check Vault policiesvault policy read my-policy
# Verify database secrets enginevault secrets listvault read database/config/my-database
# Test credential generationvault read database/creds/my-roleClickHouse Connection Issues
Section titled “ClickHouse Connection Issues”Problem: ClickHouse connection fails with authentication errors
# Test ClickHouse HTTP interface directlycurl http://localhost:8123/curl -u username:password http://localhost:8123/
# Check ClickHouse server logsdocker logs clickhouse-container# ortail -f /var/log/clickhouse-server/clickhouse-server.log
# Test with ClickHouse native clientclickhouse-client --host localhost --port 9000 --user username --password passwordClickHouse-specific solutions:
- Default user access: Use
defaultuser with empty password ifCLICKHOUSE_SKIP_USER_SETUP=1 - HTTP vs Native ports: DBCrust uses HTTP interface (port 8123), not native client port (9000)
- Database parameter: ClickHouse uses database parameter, not URL path:
clickhouse://localhost:8123/default - Authentication: Check
users.xmlor environment variables for user configuration
Problem: ClickHouse queries return “Query executed successfully” instead of data
# Enable debug logging to see HTTP requests/responsesexport DBCRUST_DEBUG=1dbcrust --debug clickhouse://localhost:8123/default
# Test query format directly with curlcurl -X POST 'http://localhost:8123/' \ -H 'Content-Type: text/plain' \ -d 'SELECT * FROM system.databases FORMAT TabSeparatedWithNames'Solutions:
- Query format: DBCrust automatically adds
FORMAT TabSeparatedWithNamesto SELECT queries - DDL queries: CREATE/DROP statements return success message instead of data
- System tables: Use ClickHouse system tables for metadata:
SELECT * FROM system.tables
Problem: Docker ClickHouse container authentication issues
# Check container environment variablesdocker inspect clickhouse-container | grep -i env
# Common ClickHouse Docker environment variablesdocker run -d --name clickhouse-test \ -e CLICKHOUSE_DB=test_db \ -e CLICKHOUSE_USER=test_user \ -e CLICKHOUSE_PASSWORD=test_pass \ -e CLICKHOUSE_SKIP_USER_SETUP=1 \ clickhouse/clickhouse-server
# Test connection after container setupdbcrust docker://clickhouse-testDocker-specific solutions:
- SKIP_USER_SETUP=1: When set, default user works without password
- Environment variables: Use CLICKHOUSE_* prefix for all config variables
- Port mapping: Ensure HTTP port 8123 is exposed:
-p 8123:8123 - Container logs: Check startup logs for configuration errors
⚡ Performance Issues
Section titled “⚡ Performance Issues”Slow Query Performance
Section titled “Slow Query Performance”Problem: Queries taking too long
-- Enable timing and analysis\timing\e
-- Run your slow query to see execution planSELECT * FROM large_table WHERE complex_condition = true;
-- Check for missing indexes\di table_name
-- Analyze table statistics\analyze table_namePerformance debugging steps:
- Check execution plan: Look for sequential scans, nested loops
- Verify indexes: Ensure appropriate indexes exist
- Update table statistics: Run
ANALYZEon affected tables - Check query patterns: Look for N+1 queries, inefficient joins
Common performance solutions:
-- Add missing indexesCREATE INDEX idx_table_column ON table_name(column_name);
-- Optimize queries-- Before: SELECT * FROM users WHERE status = 'active';-- After: SELECT id, name, email FROM users WHERE status = 'active' LIMIT 100;
-- Use query optimization suggestions\suggest query_optimizationMemory and Resource Issues
Section titled “Memory and Resource Issues”Problem: High memory usage or out-of-memory errors
# Check system resourcesfree -h # Available memoryps aux | grep dbcrust # DBCrust memory usage
# Enable memory monitoringexport DBCRUST_MEMORY_DEBUG=1dbcrust postgres://localhost/dbMemory optimization:
-- Limit result setsSELECT * FROM large_table LIMIT 1000;
-- Use streaming for large datasets\copy (SELECT * FROM huge_table) TO 'output.csv' WITH CSV;
-- Avoid loading large result sets into memory\paging on # Enable result pagingConnection Pool Exhaustion
Section titled “Connection Pool Exhaustion”Problem: “Too many connections” or connection pool errors
-- Check active connections\connections
-- Monitor connection usage\monitor connections
-- Check database connection limitsSHOW max_connections; -- PostgreSQLSHOW VARIABLES LIKE 'max_connections'; -- MySQLConnection management:
# Optimize connection settingsdbcrust --max-connections 10 postgres://localhost/db
# Use connection poolingdbcrust --connection-pool-size 5 postgres://localhost/db
# Close idle connectionsdbcrust postgres://localhost/db\connections close_idle🛠️ Configuration Issues
Section titled “🛠️ Configuration Issues”Configuration File Problems
Section titled “Configuration File Problems”Problem: Settings not applied or configuration errors
# Check configuration locationdbcrust --show-config-path
# Validate configuration syntaxdbcrust --validate-config
# Debug configuration loadingdbcrust --debug-config postgres://localhost/dbConfiguration troubleshooting:
# Reset to default configurationmv ~/.config/dbcrust/config.toml ~/.config/dbcrust/config.toml.backupdbcrust postgres://localhost/db # Creates new default config
# Check configuration syntaxpython -c "import toml; toml.load('~/.config/dbcrust/config.toml')"
# Verify file permissionsls -la ~/.config/dbcrust/chmod 644 ~/.config/dbcrust/config.tomlEnvironment Variables Issues
Section titled “Environment Variables Issues”Problem: Environment variables not recognized
# Check current environmentenv | grep DBCRUSTenv | grep DATABASE_URL
# Test environment variable overrideexport DBCRUST_DEBUG=1export DATABASE_URL=postgres://localhost/testdbcrust
# Debug environment loadingdbcrust --show-env postgres://localhost/dbCommon environment issues:
# Shell profile loadingsource ~/.bashrc # Reload bash profilesource ~/.zshrc # Reload zsh profile
# Variable scopingexport DBCRUST_LOG_LEVEL=debug # Make sure to exportdbcrust postgres://localhost/db
# Configuration precedence# 1. Command line arguments (highest)# 2. Environment variables# 3. Configuration file# 4. Default values (lowest)🔍 Feature-Specific Issues
Section titled “🔍 Feature-Specific Issues”Autocomplete Not Working
Section titled “Autocomplete Not Working”Problem: SQL autocomplete not functioning
-- Test autocomplete functionalitySELECT u. [TAB] -- Should show user table columns\dt [TAB] -- Should show available tables
-- Enable debug for autocomplete\set debug autocomplete onAutocomplete debugging:
# Check database introspection permissionsdbcrust postgres://localhost/db\dt # List tables - should work\d table_name # Describe table - should work
# Clear autocomplete cache\cache clear
# Check logs for autocomplete errorstail -f ~/.config/dbcrust/dbcrust.log | grep autocompleteColumn Selection Issues
Section titled “Column Selection Issues”Problem: Column selection interface not appearing
-- Check column selection settings\config display
-- Manually test column selection\cs -- Toggle column selection modeSELECT * FROM wide_table; -- Should show column selection
-- Check threshold settings\csthreshold 5 -- Lower threshold to trigger more oftenNamed Queries Issues
Section titled “Named Queries Issues”Problem: Named queries not saving or executing
-- Test named query functionality\ns test_query SELECT 1 as test;\n -- Should show 'test_query'test_query -- Should execute
-- Check named query storage\n --verbose -- Show detailed query information
-- Debug named query issues\debug named_queries on\ns another_test SELECT * FROM small_table;External Editor Integration
Section titled “External Editor Integration”Problem: External editor not opening
# Check EDITOR environment variableecho $EDITOR
# Test editor directly$EDITOR test.sql
# Set editor explicitlyexport EDITOR="code --wait" # VS Codeexport EDITOR="vim" # Vimexport EDITOR="nano" # Nano
# Test DBCrust editor integrationdbcrust postgres://localhost/db\ed # Should open editor📁 File and Permission Issues
Section titled “📁 File and Permission Issues”Configuration Directory Problems
Section titled “Configuration Directory Problems”Problem: Cannot write to configuration directory
# Check configuration directory permissionsls -la ~/.config/ls -la ~/.config/dbcrust/
# Fix directory permissionsmkdir -p ~/.config/dbcrust/chmod 755 ~/.config/dbcrust/chmod 644 ~/.config/dbcrust/*.toml
# Check disk spacedf -h ~/.config/dbcrust/Log File Issues
Section titled “Log File Issues”Problem: Cannot write to log files or logs not appearing
# Check log file location and permissionsls -la ~/.config/dbcrust/dbcrust.log
# Fix log file permissionstouch ~/.config/dbcrust/dbcrust.logchmod 644 ~/.config/dbcrust/dbcrust.log
# Test loggingexport DBCRUST_LOG_LEVEL=debugdbcrust --debug postgres://localhost/dbtail -f ~/.config/dbcrust/dbcrust.logSession File Corruption
Section titled “Session File Corruption”Problem: Saved sessions not loading or corrupted
# Check session file integritycat ~/.config/dbcrust/config.toml | grep saved_sessions
# Backup and reset sessionscp ~/.config/dbcrust/config.toml ~/.config/dbcrust/config.toml.backupdbcrust postgres://localhost/db\ss new_session # Save new session to test🌐 Network and Security Issues
Section titled “🌐 Network and Security Issues”SSL/TLS Connection Issues
Section titled “SSL/TLS Connection Issues”Problem: SSL certificate errors or connection encryption issues
# Test SSL connection manuallypsql "sslmode=require host=localhost dbname=test user=postgres"
# Debug SSL in DBCrustdbcrust "postgres://user@localhost/db?sslmode=require" --debug
# Common SSL parameters# sslmode=disable # No SSL# sslmode=allow # SSL if available# sslmode=prefer # Prefer SSL (default)# sslmode=require # Require SSL# sslmode=verify-ca # Verify certificate authority# sslmode=verify-full # Full certificate verificationSSL troubleshooting:
# Check certificate filesls -la ~/.postgresql/ls -la /etc/ssl/certs/
# Test certificate validationopenssl s_client -connect database-host:5432 -starttls postgres
# Common SSL issues and fixes:dbcrust "postgres://user@host/db?sslmode=disable" # Disable SSL temporarilydbcrust "postgres://user@host/db?sslmode=require&sslcert=client.crt&sslkey=client.key"Proxy and Network Issues
Section titled “Proxy and Network Issues”Problem: Connection issues through corporate firewalls or proxies
# Check proxy settingsecho $http_proxyecho $https_proxyecho $no_proxy
# Test direct connection vs proxytelnet database-host 5432 # Direct connectioncurl -v database-host:5432 # Through proxy
# Bypass proxy for database connectionsexport no_proxy="localhost,127.0.0.1,database-host"dbcrust postgres://database-host/db🐛 Advanced Debugging
Section titled “🐛 Advanced Debugging”Enable Comprehensive Debug Logging
Section titled “Enable Comprehensive Debug Logging”# Enable all debug modesexport DBCRUST_DEBUG=1export DBCRUST_TRACE=1export DBCRUST_LOG_LEVEL=trace
# Run with maximum debuggingdbcrust --debug --verbose postgres://localhost/db 2>&1 | tee debug.logDebug Specific Components
Section titled “Debug Specific Components”# Debug specific subsystemsexport DBCRUST_DEBUG_AUTOCOMPLETE=1export DBCRUST_DEBUG_CONNECTIONS=1export DBCRUST_DEBUG_QUERIES=1export DBCRUST_DEBUG_PARSER=1
# Component-specific debuggingdbcrust --debug-connections postgres://localhost/dbdbcrust --debug-autocomplete postgres://localhost/dbPerformance Profiling
Section titled “Performance Profiling”# Profile DBCrust performancetime dbcrust postgres://localhost/db -c "SELECT COUNT(*) FROM large_table;"
# Memory profiling (Linux)valgrind --tool=memcheck dbcrust postgres://localhost/db
# System call tracing (Linux)strace -e trace=network dbcrust postgres://localhost/dbGenerate Debug Reports
Section titled “Generate Debug Reports”-- Generate comprehensive debug report\debug report
-- System information\debug system
-- Connection information\debug connection
-- Configuration dump\debug config
-- Recent query history\debug queries🆘 Getting Help
Section titled “🆘 Getting Help”Information Collection for Bug Reports
Section titled “Information Collection for Bug Reports”When reporting issues, collect this information:
# System informationdbcrust --versionuname -a # System infopsql --version # Database client version
# Configurationdbcrust --show-configcat ~/.config/dbcrust/config.toml
# Debug outputexport DBCRUST_DEBUG=1dbcrust your_connection_url 2>&1 | tee debug_output.txt
# Database informationdbcrust postgres://localhost/db -c "SELECT version();"Minimal Reproduction Case
Section titled “Minimal Reproduction Case”Create a minimal test case:
# Test with minimal setupdbcrust postgres://localhost/postgres -c "SELECT 1;"
# Test with fresh configurationmv ~/.config/dbcrust ~/.config/dbcrust.backupdbcrust postgres://localhost/test_db
# Test with specific versionpip install dbcrust==0.15.1 # Specific versiondbcrust --versionCommon Error Patterns and Solutions
Section titled “Common Error Patterns and Solutions”Error: “command not found: dbcrust”
# Check installationpip list | grep dbcrustwhich dbcrust
# Reinstallpip uninstall dbcrustpip install dbcrust
# Check PATHecho $PATHError: “SSL connection has been closed unexpectedly”
# Common SSL fixesdbcrust "postgres://user@host/db?sslmode=disable"dbcrust "postgres://user@host/db?sslmode=require"Error: “FATAL: remaining connection slots are reserved”
# Reduce connection usagedbcrust --max-connections 1 postgres://host/db# Or increase database max_connectionsError: “permission denied for database/table”
# Check user permissionspsql -h host -U user -d postgres -c "\\du" # List users and rolespsql -h host -U user -d database -c "\\z" # Check permissions📚 See Also
Section titled “📚 See Also”- Performance Analysis - Optimize database performance
- Advanced Features - Session management and tools
- Configuration Reference - Complete configuration options
- Backslash Commands - All interactive commands