Skip to main content

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 in modules/setting/database.go:19:

Database Configuration

All database settings are configured in the [database] section of app.ini. 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

HOST
string
default:"127.0.0.1:5432"
PostgreSQL server address. Can be:
  • hostname:port - TCP connection
  • /var/run/postgresql/ - Unix socket
NAME
string
required
Database name
USER
string
required
Database user
PASSWD
string
Database password. Use quotes for special characters: PASSWD = "p@ssw0rd!"
SCHEMA
string
default:"public"
PostgreSQL schema to use
SSL_MODE
string
default:"disable"
SSL mode: disable, require, or verify-full

PostgreSQL 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

HOST
string
default:"127.0.0.1:3306"
MySQL server address. Can be:
  • hostname:port - TCP connection
  • /var/run/mysqld/mysqld.sock - Unix socket
SSL_MODE
string
default:"false"
Enable TLS connection: false, true, or skip-verify
CHARSET_COLLATION
string
Character set collation. Gitea will auto-detect a case-sensitive collation if empty. Recommended: utf8mb4_unicode_ci or utf8mb4_bin

MySQL with Unix Socket

SQLite

SQLite is simple to set up but not recommended for production or multi-user environments.

Configuration

SQLite Configuration Options

PATH
string
default:"data/gitea.db"
Path to SQLite database file. Relative paths are resolved from APP_DATA_PATH.
SQLITE_TIMEOUT
number
default:"500"
Query timeout in milliseconds
SQLITE_JOURNAL_MODE
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

HOST
string
default:"127.0.0.1:1433"
MSSQL server address. Format: hostname:port or hostname,port
CHARSET_COLLATION
string
Character set collation. Use a case-sensitive collation like Latin1_General_CS_AS

Common Database Settings

These settings apply to all database types and are configured in modules/setting/database.go:27-52:
LOG_SQL
boolean
default:"false"
Log all SQL queries (useful for debugging, not recommended for production)
MAX_IDLE_CONNS
number
default:"2"
Maximum number of idle database connections in the pool
MAX_OPEN_CONNS
number
default:"0"
Maximum number of open database connections (0 = unlimited)
CONN_MAX_LIFETIME
duration
default:"0"
Maximum lifetime of database connections (MySQL: 3s, others: 0)
DB_RETRIES
number
default:"10"
Number of database connection retry attempts on startup
DB_RETRY_BACKOFF
duration
default:"3s"
Time to wait between connection retry attempts
ITERATE_BUFFER_SIZE
number
default:"50"
Buffer size for iterating database results
AUTO_MIGRATION
boolean
default:"true"
Automatically run database migrations on startup
SLOW_QUERY_THRESHOLD
duration
default:"5s"
Log queries that take longer than this threshold

Connection String Format

Gitea builds connection strings based on the configured database type (see modules/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_CONNS and MAX_OPEN_CONNS
  • Monitor Performance - watch for slow queries
  • Use SSL/TLS for database connections
  • Secure Passwords - use strong, unique passwords