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
1
Create Database and User
2
Configure app.ini
3
Test Connection
Start Gitea and verify it connects successfully:
PostgreSQL Configuration Options
string
default:"127.0.0.1:5432"
PostgreSQL server address. Can be:
hostname:port- TCP connection/var/run/postgresql/- Unix socket
string
required
Database name
string
required
Database user
string
Database password. Use quotes for special characters:
PASSWD = "p@ssw0rd!"string
default:"public"
PostgreSQL schema to use
string
default:"disable"
SSL mode:
disable, require, or verify-fullPostgreSQL with Unix Socket
MySQL/MariaDB
MySQL and MariaDB are widely supported and well-tested.Installation
Database Setup
1
Run MySQL Secure Installation
2
Create Database and User
3
Configure app.ini
MySQL Configuration Options
string
default:"127.0.0.1:3306"
MySQL server address. Can be:
hostname:port- TCP connection/var/run/mysqld/mysqld.sock- Unix socket
string
default:"false"
Enable TLS connection:
false, true, or skip-verifystring
Character 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
string
default:"data/gitea.db"
Path to SQLite database file. Relative paths are resolved from
APP_DATA_PATH.number
default:"500"
Query timeout in milliseconds
string
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
string
default:"127.0.0.1:1433"
MSSQL server address. Format:
hostname:port or hostname,portstring
Character 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:
boolean
default:"false"
Log all SQL queries (useful for debugging, not recommended for production)
number
default:"2"
Maximum number of idle database connections in the pool
number
default:"0"
Maximum number of open database connections (0 = unlimited)
duration
default:"0"
Maximum lifetime of database connections (MySQL: 3s, others: 0)
number
default:"10"
Number of database connection retry attempts on startup
duration
default:"3s"
Time to wait between connection retry attempts
number
default:"50"
Buffer size for iterating database results
boolean
default:"true"
Automatically run database migrations on startup
duration
default:"5s"
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
1
Verify Database is Running
2
Test Connection Manually
3
Check Firewall Rules
Ensure the database port is accessible from the Gitea server
4
Review Gitea Logs
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