Skip to content

Database Configuration

The database section configures the database connection. Code Search supports both PostgreSQL and MySQL.

database:
driver: "postgres" # Optional - auto-detected from URL
url: "postgres://user:password@localhost:5432/codesearch?sslmode=disable"
max_open_conns: 25
max_idle_conns: 5
conn_max_lifetime: "5m"

Database driver type. If not specified, it’s auto-detected from the URL.

PropertyValue
Typestring
RequiredNo (auto-detected)
Valuespostgres, mysql
EnvironmentCS_DATABASE_DRIVER

Database connection string.

PropertyValue
Typestring
RequiredYes
EnvironmentCS_DATABASE_URL

Format:

postgres://[user[:password]@]host[:port]/database[?param=value]

Examples:

# Local development
url: "postgres://codesearch:secret@localhost:5432/codesearch?sslmode=disable"
# Docker Compose
url: "postgres://codesearch:secret@postgres:5432/codesearch?sslmode=disable"
# Cloud (with SSL)
url: "postgres://user:[email protected]:5432/codesearch?sslmode=require"
# With connection options
url: "postgres://user:pass@host:5432/db?sslmode=verify-full&sslrootcert=/path/to/ca.pem"

Maximum number of open connections to the database.

PropertyValue
Typeinteger
Default25
EnvironmentCS_DATABASE_MAX_OPEN_CONNS

Set this based on your PostgreSQL max_connections setting and number of Code Search instances.

Maximum number of idle connections to keep in the pool.

PropertyValue
Typeinteger
Default5
EnvironmentCS_DATABASE_MAX_IDLE_CONNS

Maximum lifetime of a connection before it’s closed and recreated.

PropertyValue
Typeduration
Default"5m"
EnvironmentCS_DATABASE_CONN_MAX_LIFETIME

PostgreSQL supports several SSL modes:

ModeDescription
disableNo SSL
allowUse SSL if available
preferPrefer SSL, but connect without if unavailable
requireRequire SSL connection
verify-caRequire SSL and verify server certificate
verify-fullRequire SSL, verify certificate and hostname

Production recommendation: Use require or verify-full.

Terminal window
# Driver (optional - auto-detected from URL)
CS_DATABASE_DRIVER="postgres" # or "mysql"
# Connection string
CS_DATABASE_URL="postgres://user:pass@host:5432/codesearch?sslmode=require"
# or for MySQL:
# CS_DATABASE_URL="mysql://user:pass@host:3306/codesearch?parseTime=true"
# Connection pool settings
CS_DATABASE_MAX_OPEN_CONNS="25"
CS_DATABASE_MAX_IDLE_CONNS="5"
CS_DATABASE_CONN_MAX_LIFETIME="5m"

Code Search requires PostgreSQL 14 or later.

No additional extensions are required. All functionality uses standard PostgreSQL features.

For production PostgreSQL servers:

# postgresql.conf
max_connections = 100 # Adjust based on number of Code Search instances
shared_buffers = 256MB # 25% of available RAM (up to 8GB)
effective_cache_size = 768MB # 75% of available RAM
work_mem = 64MB
maintenance_work_mem = 128MB

For high-traffic deployments, consider using a connection pooler:

database:
# Connect to PgBouncer instead of PostgreSQL directly
url: "postgres://user:pass@pgbouncer:6432/codesearch"
max_open_conns: 100 # Can be higher with connection pooling

Code Search manages its own database schema using migrations. Migrations run automatically on startup.

Tables created:

  • repos - Repository metadata
  • connections - Code host connections
  • jobs - Background job queue
  • schema_migrations - Migration tracking
failed to connect to database: connection refused
  • Verify the database server is running
  • Check host and port are correct
  • Ensure the database is listening on the correct interface
password authentication failed for user
  • Verify username and password
  • Check PostgreSQL pg_hba.conf allows connections from Code Search
SSL is required

Add sslmode=require or sslmode=disable to your connection string.

Code Search automatically detects the database driver from the URL:

URL PatternDetected Driver
postgres://...PostgreSQL
postgresql://...PostgreSQL
mysql://...MySQL
...@tcp(...)...MySQL (DSN format)

If auto-detection fails, explicitly set driver: postgres or driver: mysql.