Overview
Gitea supports multiple database backends:- PostgreSQL (Recommended)
- MySQL/MariaDB
- MSSQL (Microsoft SQL Server)
- SQLite3 (Not recommended for production)
Supported Database Types
The supported database types are defined inmodules/setting/database.go:19:
Database Configuration
All database settings are configured in the[database] section of app.ini.
PostgreSQL (Recommended)
PostgreSQL offers the best performance and features for production deployments.Installation
Database Setup
PostgreSQL Configuration Options
PostgreSQL server address. Can be:
hostname:port- TCP connection/var/run/postgresql/- Unix socket
Database name
Database user
Database password. Use quotes for special characters:
PASSWD = "p@ssw0rd!"PostgreSQL schema to use
SSL mode:
disable, require, or verify-fullPostgreSQL with Unix Socket
MySQL/MariaDB
MySQL and MariaDB are widely supported and well-tested.Installation
Database Setup
MySQL Configuration Options
MySQL server address. Can be:
hostname:port- TCP connection/var/run/mysqld/mysqld.sock- Unix socket
Enable TLS connection:
false, true, or skip-verifyCharacter set collation. Gitea will auto-detect a case-sensitive collation if empty.
Recommended:
utf8mb4_unicode_ci or utf8mb4_binMySQL with Unix Socket
SQLite
SQLite is simple to set up but not recommended for production or multi-user environments.Configuration
SQLite Configuration Options
Path to SQLite database file. Relative paths are resolved from
APP_DATA_PATH.Query timeout in milliseconds
Journal mode:
DELETE, TRUNCATE, PERSIST, MEMORY, or WAL (recommended)SQLite Limitations
- Limited concurrent write performance
- No built-in replication
- Single file can become large
- Not suitable for high-traffic sites
Microsoft SQL Server (MSSQL)
Database Setup
Configuration
MSSQL Configuration Options
MSSQL server address. Format:
hostname:port or hostname,portCharacter set collation. Use a case-sensitive collation like
Latin1_General_CS_ASCommon Database Settings
These settings apply to all database types and are configured inmodules/setting/database.go:27-52:
Log all SQL queries (useful for debugging, not recommended for production)
Maximum number of idle database connections in the pool
Maximum number of open database connections (0 = unlimited)
Maximum lifetime of database connections (MySQL: 3s, others: 0)
Number of database connection retry attempts on startup
Time to wait between connection retry attempts
Buffer size for iterating database results
Automatically run database migrations on startup
Log queries that take longer than this threshold
Connection String Format
Gitea builds connection strings based on the configured database type (seemodules/setting/database.go:95-136):
Database Maintenance
Backup Database
See Backup and Restore for complete backup procedures.Check Database Connection
View Database Statistics
Performance Tuning
PostgreSQL
MySQL
Troubleshooting
Connection Issues
Migration Issues
Best Practices
- Use PostgreSQL for production deployments
- Separate Database Server for large installations
- Regular Backups - automate database backups
- Connection Pooling - tune
MAX_IDLE_CONNSandMAX_OPEN_CONNS - Monitor Performance - watch for slow queries
- Use SSL/TLS for database connections
- Secure Passwords - use strong, unique passwords