Using external databases with Sourcegraph

Sourcegraph by default provides its own PostgreSQL and Redis databases for data storage:

  • PostgreSQL for storing long-term information, such as user information when using Sourcegraph’s built-in authentication provider instead of an external one.
  • Redis for storing short-term information, such as session information and cache data.

Using your own PostgreSQL server

You can use your own PostgreSQL server with Sourcegraph if you wish. For example, you may prefer this if you already have existing backup infrastructure around your own PostgreSQL server.

Simply add the standard PostgreSQL environment variables to your docker run command and Sourcegraph will use that PostgreSQL server instead of its built-in one. For example:

Version requirements

Please refer to our Postgres documentation to learn about version requirements.

docker run [...] -e -e PGUSER=sourcegraph -e PGPASSWORD=secret -e PGDATABASE=sourcegraph -e PGSSLMODE=require sourcegraph/server:3.6.2

Most standard PostgreSQL environment variables may be specified (PGPORT, etc). See for a full list.

Using your own Redis server

Generally, there is no reason to do this as Sourcegraph only stores ephemeral cache and session data in Redis. However, if you want to use an external Redis server with Sourcegraph, you can do the following:

Add the REDIS_ENDPOINT environment variable to your docker run command and Sourcegraph will use that Redis server instead of its built-in one. The string must either have the format $HOST:PORT or follow the IANA specification for Redis URLs (e.g., redis://:[email protected]:6379/2). For example:

docker run [...]   -e   sourcegraph/server:3.6.2