Skip to content

Deploying a DbGate App

Introduction

DbGate is a powerful, open-source database management tool that provides a modern, user-friendly interface for managing multiple database systems. Built with simplicity and efficiency in mind, DbGate supports a wide range of database engines including PostgreSQL, MySQL, MariaDB, SQL Server, MongoDB, SQLite, Redis, and many more - all from a single, unified interface.

DbGate stands out for its:

  • Multi-Database Support: Connect to and manage multiple database types from one application
  • Modern Web Interface: Clean, intuitive UI built with modern web technologies
  • Data Export/Import: Flexible options for exporting and importing data in various formats (JSON, CSV, Excel)
  • SQL Editor: Advanced SQL editor with syntax highlighting, code completion, and query history
  • Schema Management: Visual schema designer and migration tools
  • Cross-Platform: Runs on Windows, macOS, Linux, and can be deployed as a web application
  • Data Browser: Intuitive table data viewer with filtering, sorting, and inline editing
  • Database Comparison: Compare schemas and data between databases
  • Open Source: Free to use and modify under MIT license

This comprehensive guide walks you through deploying DbGate on Klutch.sh using Docker, including detailed installation steps, sample configurations, persistent storage setup, and production-ready best practices.

Prerequisites

Before you begin, ensure you have the following:

  • A Klutch.sh account
  • A GitHub account with a repository for your DbGate project
  • Docker installed locally for testing (optional but recommended)
  • Basic understanding of Docker and database management concepts
  • Database connection credentials for the databases you want to manage

Installation and Setup

Step 1: Create Your Project Directory

First, create a new directory for your DbGate deployment project:

Terminal window
mkdir dbgate-klutch
cd dbgate-klutch
git init

Step 2: Create the Dockerfile

Create a Dockerfile in your project root directory. This will define your DbGate container configuration:

FROM dbgate/dbgate:latest
# Set the working directory
WORKDIR /home/dbgate-docker
# Expose the default DbGate web interface port
EXPOSE 3000
# The base image already includes the startup command
# but we can be explicit about it
CMD ["node", "/home/dbgate-docker/dist/bundle.js"]

Note: The DbGate Docker image is actively maintained and includes all necessary dependencies. Using the official image ensures you get the latest features and security updates.

Step 3: (Optional) Create a Custom Configuration

You can create an optional configuration file to customize DbGate’s behavior. Create a file named dbgate-config.json:

{
"allowShellScripting": false,
"allowMultipleDatabases": true,
"maxConnectionPoolSize": 10,
"queryTimeout": 30000,
"allowedDatabaseEngines": [
"postgres",
"mysql",
"mariadb",
"mssql",
"mongodb",
"sqlite",
"redis"
]
}

If you create a configuration file, update your Dockerfile to include it:

FROM dbgate/dbgate:latest
WORKDIR /home/dbgate-docker
# Copy custom configuration
COPY dbgate-config.json /home/dbgate-docker/config.json
EXPOSE 3000
CMD ["node", "/home/dbgate-docker/dist/bundle.js"]

Step 4: Create Environment Configuration

Create a .env.example file to document the environment variables needed:

Terminal window
# DbGate Environment Variables
# Authentication (optional but recommended for production)
BASIC_AUTH=true
LOGIN=admin
PASSWORD=your-secure-password-here
# Database connections (optional - can be configured in UI)
# Connection strings can be added via the web interface after deployment

Security Note: Never commit your actual credentials to version control. The .env.example file serves as documentation only.

Step 5: Test Locally (Optional)

Before deploying to Klutch.sh, you can test your DbGate setup locally:

Terminal window
# Build the Docker image
docker build -t my-dbgate .
# Run the container
docker run -d \
--name dbgate-test \
-p 3000:3000 \
-v dbgate-data:/root/.dbgate \
my-dbgate
# Access DbGate in your browser
# Navigate to http://localhost:3000
# Stop and remove the test container when done
docker stop dbgate-test
docker rm dbgate-test

Step 6: Create a .gitignore File

Create a .gitignore file to exclude sensitive and unnecessary files:

# Environment files
.env
.env.local
# DbGate data
.dbgate/
# Node modules (if extending functionality)
node_modules/
# OS files
.DS_Store
Thumbs.db

Step 7: Push to GitHub

Commit your Dockerfile and configuration files to your GitHub repository:

Terminal window
git add Dockerfile .gitignore .env.example
git commit -m "Add DbGate Dockerfile and configuration"
git remote add origin https://github.com/yourusername/dbgate-klutch.git
git push -u origin main

Deploying to Klutch.sh

Now that your DbGate project is ready and pushed to GitHub, follow these steps to deploy it on Klutch.sh with persistent storage.

Deployment Steps

    1. Log in to Klutch.sh

      Navigate to klutch.sh/app and sign in to your account.

    2. Create a New Project

      Go to Create Project and give your project a meaningful name (e.g., “DbGate Database Manager”).

    3. Create a New App

      Navigate to Create App and configure the following settings:

    4. Select Your Repository

      • Choose GitHub as your Git source
      • Select the repository containing your Dockerfile
      • Choose the branch you want to deploy (usually main or master)
    5. Configure Traffic Type

      • Traffic Type: Select HTTP (DbGate serves a web interface over HTTP/HTTPS)
      • Internal Port: Set to 3000 (the default DbGate web interface port)
    6. Set Environment Variables

      Add the following environment variables for your DbGate configuration:

      Basic Authentication (Recommended for Production):

      • BASIC_AUTH: Set to true to enable basic authentication
      • LOGIN: Your admin username (e.g., admin)
      • PASSWORD: A strong password for accessing DbGate (use a secure password generator)

      Optional Advanced Configuration:

      • WEB_ROOT: Custom web root path if deploying behind a reverse proxy (e.g., /dbgate)
      • CONNECTIONS: Pre-configured database connections (JSON format, though typically configured via UI)

      Security Note: Always use strong, unique passwords for production deployments. Consider implementing additional authentication layers for sensitive environments.

    7. Attach a Persistent Volume

      This is critical for ensuring your database connections, query history, and settings persist across deployments:

      • In the Volumes section, click “Add Volume”
      • Mount Path: Enter /root/.dbgate (this is where DbGate stores its configuration, connections, and query history)
      • Size: Choose an appropriate size based on your expected usage (2-5GB is typically sufficient for configuration data)

      Important: Without persistent storage, you’ll lose all saved connections and settings when the container restarts.

    8. Configure Additional Settings

      • Region: Select the region closest to your users for optimal latency
      • Compute Resources: Choose CPU and memory based on your workload (minimum 512MB RAM recommended, 1GB+ for better performance)
      • Instances: Start with 1 instance (you can scale up if needed)
    9. Deploy Your Application

      Click “Create” to start the deployment. Klutch.sh will:

      • Automatically detect your Dockerfile in the repository root
      • Build the Docker image
      • Attach the persistent volume
      • Start your DbGate container
      • Assign a URL for access
    10. Access Your DbGate Instance

      Once deployment is complete, you’ll receive a URL like example-app.klutch.sh. Access your DbGate instance by navigating to:

      https://example-app.klutch.sh

      If you enabled basic authentication, enter your login credentials when prompted.


Connecting Databases to DbGate

Once DbGate is deployed and accessible, you can start adding database connections through the web interface:

Adding a Database Connection

  1. Access the DbGate Interface

    Navigate to your deployed app URL (e.g., https://example-app.klutch.sh)

  2. Create a New Connection

    • Click on “New Connection” in the left sidebar
    • Select your database type (PostgreSQL, MySQL, MongoDB, etc.)
    • Fill in the connection details

Example Connection Configurations

PostgreSQL Connection:

Display Name: My PostgreSQL Database
Server: postgres-host.example.com
Port: 5432
User: dbuser
Password: ••••••••
Database: mydb
Use SSL: Yes (recommended for production)

MySQL/MariaDB Connection:

Display Name: My MySQL Database
Server: mysql-host.example.com
Port: 3306
User: dbuser
Password: ••••••••
Database: mydb

MongoDB Connection:

Display Name: My MongoDB Database
Connection String: mongodb://user:password@mongo-host.example.com:27017/mydb

Connecting to Databases on Klutch.sh:

If you have databases deployed on Klutch.sh that use TCP traffic (routed through port 8000), use these connection details:

Server: your-database-app.klutch.sh
Port: 8000
User: your-db-user
Password: your-db-password
Database: your-db-name

Getting Started with DbGate

Basic Operations

Viewing Table Data:

  1. Expand your database connection in the left sidebar
  2. Navigate to the table you want to view
  3. Click on the table name to open the data viewer
  4. Use the toolbar to filter, sort, and edit data

Running SQL Queries:

  1. Click the “New Query” button in the toolbar
  2. Write your SQL query in the editor
  3. Press Ctrl+Enter (or Cmd+Enter on Mac) to execute
  4. View results in the output panel below

Example SQL Query:

-- Select users created in the last 30 days
SELECT
id,
username,
email,
created_at
FROM users
WHERE created_at >= NOW() - INTERVAL '30 days'
ORDER BY created_at DESC
LIMIT 100;

Exporting Data:

  1. Open a table or query result
  2. Click the “Export” button in the toolbar
  3. Choose your format (CSV, JSON, Excel, SQL Insert)
  4. Configure export options
  5. Download the exported file

Importing Data:

  1. Right-click on a table in the sidebar
  2. Select “Import Data”
  3. Choose your file format and upload the file
  4. Map columns and configure import settings
  5. Execute the import

Sample Database Queries for Testing

Create a sample table:

-- PostgreSQL example
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
price DECIMAL(10, 2) NOT NULL,
stock_quantity INTEGER DEFAULT 0,
category VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert sample data
INSERT INTO products (name, description, price, stock_quantity, category) VALUES
('Laptop', 'High-performance laptop for developers', 1299.99, 50, 'Electronics'),
('Keyboard', 'Mechanical keyboard with RGB lighting', 149.99, 200, 'Accessories'),
('Mouse', 'Wireless ergonomic mouse', 79.99, 150, 'Accessories'),
('Monitor', '27-inch 4K display', 499.99, 75, 'Electronics');

Complex query with joins:

-- Example query joining orders with customers
SELECT
o.id AS order_id,
o.order_date,
c.name AS customer_name,
c.email,
SUM(oi.quantity * oi.unit_price) AS total_amount
FROM orders o
JOIN customers c ON o.customer_id = c.id
JOIN order_items oi ON o.id = oi.order_id
WHERE o.order_date >= '2024-01-01'
GROUP BY o.id, o.order_date, c.name, c.email
HAVING SUM(oi.quantity * oi.unit_price) > 100
ORDER BY o.order_date DESC;

Production Best Practices

Security Recommendations

  • Enable Authentication: Always enable basic authentication or integrate with SSO for production deployments
  • Use HTTPS: Klutch.sh provides HTTPS automatically, but ensure your database connections also use SSL/TLS when possible
  • Limit Database Access: Configure database user permissions to grant only the necessary access level
  • Regular Updates: Keep your DbGate Docker image updated to get the latest security patches
  • Environment Variables: Store all sensitive credentials as environment variables in Klutch.sh, never in your Dockerfile or configuration files
  • Access Control: Consider implementing IP whitelisting or VPN access for highly sensitive databases
  • Audit Logging: Monitor and log all database operations for security auditing

Performance Optimization

  • Connection Pooling: DbGate manages connection pools automatically, but ensure your databases support concurrent connections
  • Resource Allocation: Monitor your application’s CPU and memory usage and scale resources as needed
  • Query Optimization: Use DbGate’s query analyzer to identify slow queries and optimize them
  • Index Management: Regularly review and optimize database indexes using DbGate’s schema tools
  • Data Pagination: When working with large datasets, use pagination and filtering to reduce load times

Backup and Data Management

  • Persistent Volume Backups: Regularly backup your DbGate configuration volume to preserve connection settings and query history
  • Database Backups: Use DbGate’s export functionality to create regular backups of your database schemas and data
  • Query History: DbGate automatically saves query history to the persistent volume, making it easy to track and repeat operations
  • Version Control: Export and version control important database schemas and migration scripts

Monitoring

Monitor your DbGate deployment for:

  • Application uptime and availability
  • Response times for database queries
  • Memory and CPU utilization
  • Disk space usage on the persistent volume
  • Active database connections
  • Error rates and failed queries

Advanced Features

Schema Comparison and Synchronization

DbGate provides powerful tools for comparing database schemas:

  1. Open the “Tools” menu
  2. Select “Compare Databases”
  3. Choose the source and target databases
  4. Review differences in tables, columns, indexes, and constraints
  5. Generate synchronization scripts

Database Diagrams

Create visual diagrams of your database structure:

  1. Right-click on a database in the sidebar
  2. Select “Generate Diagram”
  3. DbGate will create an interactive ER diagram
  4. Export the diagram as an image or PDF

Custom Queries and Saved Views

Save frequently used queries for quick access:

  1. Write your query in the SQL editor
  2. Click “Save Query” in the toolbar
  3. Give your query a name and optional description
  4. Access saved queries from the “Saved Queries” section

Data Generator

For testing purposes, DbGate can generate sample data:

  1. Right-click on a table
  2. Select “Generate Data”
  3. Configure generation rules for each column
  4. Specify the number of rows to generate
  5. Execute the generation

Troubleshooting

Cannot Access DbGate Interface

  • Verify that you’re using the correct URL provided by Klutch.sh
  • Ensure the internal port is set to 3000 in your app configuration
  • Check that the HTTP traffic type is selected (not TCP)
  • Review application logs in the Klutch.sh dashboard for errors

Database Connection Failures

  • Verify database credentials are correct
  • Ensure the database server is accessible from Klutch.sh
  • For Klutch.sh-hosted databases using TCP, confirm you’re using port 8000
  • Check firewall rules and security groups allow connections
  • Test connection with SSL enabled/disabled based on database requirements

Persistent Data Not Saving

  • Verify that the persistent volume is correctly attached at /root/.dbgate
  • Check that the volume has sufficient space allocated
  • Ensure file permissions allow the DbGate process to write to the volume
  • Review application logs for permission errors

Slow Query Performance

  • Optimize your database queries using appropriate indexes
  • Increase compute resources (CPU/memory) for the DbGate application
  • Consider connection pooling settings in your database
  • Check database server performance and resource availability

Authentication Issues

  • Verify BASIC_AUTH, LOGIN, and PASSWORD environment variables are set correctly
  • Clear browser cache and cookies
  • Try accessing from an incognito/private browsing window
  • Check for typos in environment variable names (they are case-sensitive)

Updating DbGate

To update your DbGate deployment to the latest version:

  1. Update the Docker image tag in your Dockerfile (or pull the latest dbgate/dbgate:latest)
  2. Commit and push changes to GitHub
  3. Klutch.sh will automatically rebuild and redeploy your application
  4. Your persistent volume ensures all connections and settings are preserved

For pinned versions:

FROM dbgate/dbgate:5.2.6
WORKDIR /home/dbgate-docker
EXPOSE 3000
CMD ["node", "/home/dbgate-docker/dist/bundle.js"]

Replace 5.2.6 with your desired version number.


Additional Resources


Conclusion

Deploying DbGate to Klutch.sh provides you with a powerful, centralized database management tool accessible from anywhere. With support for multiple database engines, an intuitive interface, and robust data management features, DbGate simplifies database administration tasks. By following this guide, you’ve set up a production-ready DbGate instance with persistent storage, secure authentication, and the ability to manage all your databases from a single, unified interface. Your database management workflow is now streamlined and accessible through any web browser.