Configuration
Source Graph is configured in four layers, each with a different owner and lifetime:
| Layer | Where | Changed by | Takes effect |
|---|---|---|---|
| Environment variables | Process environment, for example Fly.io secrets or a container env file | Operator | On restart |
| Deployment settings | config/deployment.json, embedded at build time | Whoever builds the image | On the next build |
| Site settings | Database, edited on the Settings page | Administrators | Immediately, with revision checks |
| Repository policy | Database, set per repository at registration or later | Administrators and the repository's managers | On the next synchronization or preparation |
Code sources combine deployment defaults, the website's custom Git settings and an optional startup file; see Code sources.
Secrets — GitHub and custom Git tokens, OAuth client secrets, the service token, the credential key and database URLs with passwords — belong only in environment variables or the database, never in the deployment file, the startup file or the image. For deployment steps see Self-hosting.
Environment variables
| Variable | Default | Purpose |
|---|---|---|
SOURCEGRAPH_LISTEN | 0.0.0.0:8080 | Listen address |
SOURCEGRAPH_ORIGIN | http://localhost:8080 | Public origin, used for sign-in callbacks and links |
SOURCEGRAPH_DATA_ROOT | /data | Data directory for Git mirrors, indexes and manifests; must be absolute |
SOURCEGRAPH_DATABASE | sqlite | sqlite, postgres or mongodb |
DATABASE_URL | <data root>/sourcegraph.db for SQLite | Database location or connection string |
SOURCEGRAPH_MIN_FREE_BYTES | 1073741824 (1 GiB) | Free-space floor below which fetching and indexing stop with INSUFFICIENT_STORAGE |
SOURCEGRAPH_API_TOKEN | Generated if absent | Seeds the service credential on first start (at least 32 characters); after that the value saved in the database is used. A matching bearer token gets full HTTP API access, except site settings, which require a browser session. The CLI reads the same variable |
SOURCEGRAPH_CREDENTIAL_KEY | Unset | Base64 of 32 bytes, read once when upgrading an instance whose code tokens were encrypted with it; otherwise an existing code-credentials.key is imported, and a fresh database generates its own key. The key then lives in the database |
SOURCEGRAPH_GITHUB_TOKEN | Unset | GitHub token used only while no global GitHub token has been saved; the earlier SOURCEGRAPH_GIT_TOKEN is still read while this is unset |
SOURCEGRAPH_CUSTOM_GIT_TOKEN | Unset | Custom Git token used only while no global custom Git token has been saved |
SOURCEGRAPH_CONFIG_FILE | Unset | Path of a JSON startup file that overrides code sources; see Code sources |
GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET | Unset | Google sign-in, imported together into the database on first configuration |
GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET | Unset | GitHub sign-in, imported together into the database on first configuration |
SOURCEGRAPH_SEED_DEMO | Unset | true registers context4ai/context and context4ai/sourcegraph at startup if they are missing |
The database is authoritative for these secrets: once a value is saved, changing its environment variable does not rotate it, and a replacement host needs only the database and non-secret configuration. Back up the whole database, secrets included. See Self-Hosting for upgrades. With PostgreSQL or MongoDB, several instances can share one database while each keeps its own data directory.
Deployment settings
config/deployment.json is compiled into the binaries and describes what this deployment is, not how it is secured:
| Field | Community default | Meaning |
|---|---|---|
code_sources | GitHub, then a custom Git source with no host | The code sources this build offers, in display order, each with id, name, host, username, token_env, anonymous and editable |
example_repo | context4ai/context | Repository used in interface examples |
public_url | https://context4ai.org/sourcegraph | Public address shown in links and connection snippets |
source_repository | https://github.com/context4ai/sourcegraph | Source link shown in the interface |
sso | Google issuer and endpoints, empty client ID | Sign-in provider metadata, plus registration_url, the provider console where an operator creates the OAuth client; no secrets |
A fork that deploys under its own name or address edits this file and rebuilds; sign-in client IDs and secrets still come from the environment.
Code sources
Each instance offers exactly two code sources: GitHub, then a custom Git host such as a self-hosted Gitea or GitLab. Their fields combine three layers, later non-empty values winning:
- Deployment defaults —
code_sourcesinconfig/deployment.jsondecides which sources exist and their order. The custom source has no host by default. - Website — administrators edit the custom source's name, host and HTTPS username on its card under System settings › Code sources, the same card that holds its global token. Changes apply immediately.
- Startup file — the JSON file named by
SOURCEGRAPH_CONFIG_FILEoverrides fields by source id when the service starts.
{"code_sources": {"git": {"name": "Gitea", "host": "https://git.example.com", "username": "oauth2", "token_env": "SOURCEGRAPH_CUSTOM_GIT_TOKEN"}}}| Field | Rules |
|---|---|
name | Display name |
host | HTTPS origin without path, user, query or fragment; stored in lowercase |
username | Git username sent with the token, 1–64 of letters, digits, ., _, @ and -; default oauth2 |
token_env | Name of the environment variable holding the default token, uppercase letters, digits and _; the website cannot set it. The GitHub default is SOURCEGRAPH_GITHUB_TOKEN, with legacy_token_env SOURCEGRAPH_GIT_TOKEN read while it is unset; a startup file that sets token_env stops reading the earlier name |
- The startup file can only override existing ids; an unknown id or invalid value stops startup. Tokens never go in the file.
- Fields set in the startup file are read-only on the website; changing them there returns
409 CODE_SOURCE_LOCKED. - Repositories keep the host recorded at registration (
code_host). On startup, records without one get the current host; a recorded host is never rewritten, and a mismatch with the current configuration is only logged. - While any repository record, including deleted ones, uses the custom source, changing its host returns
409 CODE_SOURCE_IN_USE. The name and username can still change. GET /sourcegraph/v1/code-sourcesreturns the effective sources in order, withlockedlisting fields set by the startup file; it never returns tokens or variable names.
Site settings
Administrators edit three sections on the Settings page or through /api/admin/settings. Each save carries the section's current revision; a stale revision is rejected so two administrators cannot silently overwrite each other.
| Section | Field | Default | Meaning |
|---|---|---|---|
repository_defaults | git_timeout_minutes | 15 | Default Git fetch and hydration timeout: 15, 30, 45 or 60 minutes. A repository inherits it unless it sets its own; new tasks take the value current when they start |
retention_mode | days | Default retention for new registrations: days or count | |
retention_days | 30 | Days since first observation that ordinary snapshots are kept, 1–365 | |
retention_count | 20 | Most recently observed ordinary snapshots kept, 1–4,096 | |
access | public_read | true | Whether anonymous visitors can search and read public repositories; private repositories are never anonymous |
allow_registration | false | Whether a first-time sign-in creates an account | |
registration_notice_zh, registration_notice_en | A built-in notice | Text shown to people who cannot register | |
allow_user_repositories | false | Whether signed-in users can register repositories; each registrant becomes the repository's manager | |
code_source | name, host, username | Empty, so the deployment values apply | The custom Git source; see Code sources |
Requests to /api/admin/settings must use a browser session; requests carrying an Authorization header are refused. Global code tokens are saved separately on the same page. The Storage page separately moves where Git mirrors are kept; see Operations.
Repository policy
Each registration has its own policy, initialized from the repository defaults:
| Setting | Range | Default |
|---|---|---|
| Monitored branches | 1–8 | The default branch |
| Retention | Days since first observation 1–365 or the 1–4,096 most recently observed snapshots, not both | Site default |
| Sync interval (minutes) | 1, 3, 5, 10, 30, 60, 180, 360, 720 or 1440 | 180 for new registrations; repositories saved without an interval keep 5 |
| Index mode | Whole repository, or registered path groups for a monorepo | Whole repository |
Git timeout (git_timeout_minutes) | 0 to inherit the site default, or 15, 30, 45 or 60 | Inherit |
| Managers | Up to 50 signed-in users who can manage the repository besides administrators | The registrant |
Public repository (public_read) | Public or private | Public |
Pinned snapshots (pinned_commits) | Full SHAs, up to 4,096, that neither retention nor capacity release ever removes; added only here, never by preparing a commit | None |
Storage budget (max_storage_bytes) | 1 GiB to 10 TiB, covering Git objects, index shards and active preparation files; when reached, the oldest unprotected snapshots are released | 100 GiB |
Code source (code_provider) | github or git, fixed at registration; the registrant's own token for that source is tried first, then the global one | github |
Code host (code_host) | The source's host at registration, kept for every later fetch | — |
A private repository is visible only to its creator, its managers, administrators signed in on the website and the service token; see Authentication and Access Control.
Pinned snapshots, current branch heads and the commits of queued or running jobs are protected and never released. Every other snapshot is ordinary, including a commit prepared by its full SHA: preparation fetches it on demand but does not pin it. Ordinary snapshots leave in two ways:
- Retention applies the days or count rule after each successful sync and again as soon as a preparation publishes its index.
- Capacity releases the oldest unprotected snapshots, by first observation, instead of refusing work: when a path group reaches 4,096 snapshots, and when the storage budget is reached at a safe point — before the Git fetch of a sync or a SHA preparation, before an index build (reserving 1.2 times the group's previous index) and after a preparation or index task. Budget eviction works in batches of at most 64 and measures usage again after each batch.
A released version answers REVISION_NOT_ELIGIBLE until it is prepared again. SNAPSHOT_LIMIT and REPOSITORY_STORAGE_LIMIT appear only when protected snapshots alone fill the 4,096 versions or the budget, or when a running build exceeds 120% of the budget; remove pins you no longer need or raise the budget. Released space is collected by Git in the job that released it and, if that is interrupted, by a background pass every minute that finishes Git collection repository by repository. See Registering repositories for how branches, retention and pins decide which commits are searchable.
Plugin limits
Wasm evidence plugins run inside the service under resource guards set by SOURCEGRAPH_PLUGINS_* variables. Invalid values stop startup rather than removing a guard.
| Variable suffix | Default | Limits |
|---|---|---|
DISABLED | Unset | 1 disables plugins |
TIMEOUT | 10s | Wall time per run (Go duration) |
MEMORY_MIB | 256 | Memory per instance, at most 4,096 |
ARTIFACT_BYTES | 32 MiB | Plugin module size |
METADATA_BYTES | 256 KiB | Plugin metadata size |
FILE_BYTES | 32 MiB | Size of one file the plugin reads |
READ_BYTES | 128 MiB | Total bytes read per run |
READ_CALLS | 1,024 | File reads per run |
OUTPUT_BYTES | 2 MiB | Output size |
CONCURRENCY | 8 | Concurrent runs |
CACHE_ENTRIES | 16 | Compiled modules kept |
IDLE_INSTANCES | 8 | Warm instances kept |
Built-in limits
Some limits are fixed in code and cannot be configured: request bodies up to 64 KiB, a 30-second request deadline, HTTP server timeouts of 5 seconds for headers, 120 seconds for reading and 125 seconds for writing, and the search, read, list and diff page sizes described in HTTP and MCP. The search engine runs as a local helper on 127.0.0.1:6070 and is never exposed.
Snapshot capacity is fixed at 4,096 snapshots per path group and 4,096 pinned snapshots per repository; budget eviction releases at most 64 snapshots per batch.
Branch and tag discovery for refs and resolve keeps its catalogs in memory and uses fixed limits:
| Limit | Value |
|---|---|
| Catalog size | 200,000 branches and 200,000 tags with commit details; beyond that, names only and marked truncated |
| Catalogs in memory | 1,000,000 refs across repositories; the least recently used catalogs are dropped beyond that |
| Catalog freshness | 5 minutes or three times the last refresh duration, whichever is longer |
| Catalog refreshes | One per repository and 4 per instance at a time |
| First listing wait | The request's remaining deadline less 2 seconds, then REFS_CATALOG_PREPARING with Retry-After |
| Scratch downloads | 256 MiB per catalog refresh, 16 MiB per resolve lookup and 4 GiB across all downloads, checked every second and always within the free-space reserve set by SOURCEGRAPH_MIN_FREE_BYTES |
| Remote lookups | 2 per repository and 8 per instance at a time, at most 64 running or waiting |
| Lookup cache | 30 seconds, including "not found", at most 10,000 entries |
| Failure backoff | Per repository, from 10 seconds up to 5 minutes |
Data directory
| Path under the data root | Contents | Rebuildable |
|---|---|---|
sourcegraph.db | SQLite database: users, keys, settings, registrations, credentials and the application secrets with their encryption key | No |
code-credentials.key | Present only on instances upgraded from versions that kept the credential key on disk; imported into the database on first start, then kept only to restore backups taken before the upgrade. Fresh databases create no key file | No, until the upgrade is verified |
storage.json | Where Git mirrors are stored on this machine | No |
space/ | Bare Git mirrors, unless moved on the Storage page | Yes, from the remotes |
index/, manifests/ | Search index shards and the manifests that describe them | Yes, by indexing again |
refcache/tmp/ | Scratch downloads of branch and tag objects, without file trees, for refs and resolve; each is deleted once parsed, and leftovers are removed at startup | Temporary; nothing to back up |
The container runs as an unprivileged user (uid 10001) and needs write access to the whole data root.
配置
Source Graph 的配置分为四层,每层的负责人和生效周期各不相同:
| 层级 | 位置 | 修改者 | 生效时机 |
|---|---|---|---|
| 环境变量 | 进程环境,例如 Fly.io secrets 或容器 env 文件 | 运维人员 | 重启后 |
| 部署设置 | config/deployment.json,构建时嵌入 | 构建镜像的人 | 下次构建后 |
| 站点设置 | 数据库,在 Settings(设置)页面编辑 | 管理员 | 立即生效,带版本校验 |
| 仓库策略 | 数据库,按仓库在登记时或之后设置 | 站点管理员和仓库管理员 | 下次同步或准备时 |
代码源由部署默认值、网站上的自定义 Git 设置和可选的启动文件合并而成,见 代码源。
机密信息,包括 GitHub 和自定义 Git 令牌、OAuth 客户端密钥、服务令牌、凭据加密密钥以及带密码的数据库 URL,只能放在环境变量或数据库中,绝不能放进部署文件、启动文件或镜像。部署步骤见 自部署与数据库选择。
环境变量
| 变量 | 默认值 | 用途 |
|---|---|---|
SOURCEGRAPH_LISTEN | 0.0.0.0:8080 | 监听地址 |
SOURCEGRAPH_ORIGIN | http://localhost:8080 | 公开源地址,用于登录回调和链接 |
SOURCEGRAPH_DATA_ROOT | /data | 存放 Git 镜像、索引和清单的数据目录;必须是绝对路径 |
SOURCEGRAPH_DATABASE | sqlite | sqlite、postgres 或 mongodb |
DATABASE_URL | SQLite 为 <data root>/sourcegraph.db | 数据库位置或连接字符串 |
SOURCEGRAPH_MIN_FREE_BYTES | 1073741824(1 GiB) | 剩余空间下限,低于该值时拉取和建索引会停止,并返回 INSUFFICIENT_STORAGE |
SOURCEGRAPH_API_TOKEN | 缺省时自动生成 | 首次启动时作为服务凭据的初始值(至少 32 个字符);之后使用保存在数据库中的值。匹配的 Bearer 令牌拥有完整的 HTTP API 访问权限,但站点设置除外,站点设置需要浏览器会话。CLI 也读取同一变量 |
SOURCEGRAPH_CREDENTIAL_KEY | 未设置 | 32 字节的 Base64,在升级一个用它加密过代码令牌的实例时读取一次;否则导入已有的 code-credentials.key,全新数据库则生成自己的密钥。此后密钥保存在数据库中 |
SOURCEGRAPH_GITHUB_TOKEN | 未设置 | GitHub 令牌,仅在尚未保存全局 GitHub 令牌时使用;未设置时仍读取旧变量 SOURCEGRAPH_GIT_TOKEN |
SOURCEGRAPH_CUSTOM_GIT_TOKEN | 未设置 | 自定义 Git 令牌,仅在尚未保存全局自定义 Git 令牌时使用 |
SOURCEGRAPH_CONFIG_FILE | 未设置 | 覆盖代码源的 JSON 启动文件路径,见 代码源 |
GOOGLE_CLIENT_ID、GOOGLE_CLIENT_SECRET | 未设置 | Google 登录,首次配置时一并导入数据库 |
GITHUB_CLIENT_ID、GITHUB_CLIENT_SECRET | 未设置 | GitHub 登录,首次配置时一并导入数据库 |
SOURCEGRAPH_SEED_DEMO | 未设置 | 设为 true 时,若 context4ai/context 和 context4ai/sourcegraph 尚未登记,会在启动时登记它们 |
这些密钥以数据库为准:一旦保存,修改对应的环境变量不会轮换它,替换主机时只需要数据库和非机密配置。请完整备份数据库,包括其中的密钥。升级方法见 自部署与数据库选择。使用 PostgreSQL 或 MongoDB 时,多个实例可以共享同一个数据库,同时各自保留自己的数据目录。
部署设置
config/deployment.json 会被编译进二进制文件,描述的是这个部署是什么,而不是如何保障其安全:
| 字段 | 社区版默认值 | 含义 |
|---|---|---|
code_sources | GitHub,然后是一个没有托管地址的自定义 Git 代码源 | 本构建提供的代码源,按显示顺序排列,每项包含 id、name、host、username、token_env、anonymous 和 editable |
example_repo | context4ai/context | 界面示例中使用的仓库 |
public_url | https://context4ai.org/sourcegraph | 在链接和连接代码片段中显示的公开地址 |
source_repository | https://github.com/context4ai/sourcegraph | 界面中显示的源码链接 |
sso | Google 签发方和端点,客户端 ID 为空 | 登录提供方元数据,另含 registration_url,即运维人员创建 OAuth 客户端的提供方控制台;不含任何机密 |
以自己的名称或地址部署的 fork 需要修改此文件并重新构建;登录所用的客户端 ID 和密钥仍来自环境变量。
代码源
每个实例恰好提供两个代码源:先是 GitHub,然后是一个自定义 Git 托管地址,例如自建的 Gitea 或 GitLab。它们的字段由三层合并而成,后面的非空值优先:
- 部署默认值:
config/deployment.json中的code_sources决定有哪些代码源及其顺序。自定义代码源默认没有托管地址。 - 网站:管理员在 System settings › Code sources(系统设置 › 代码源)的自定义 Git 卡片上编辑该代码源的名称、托管地址和 HTTPS 用户名,全局令牌也在同一张卡片上,修改立即生效。
- 启动文件:服务启动时,
SOURCEGRAPH_CONFIG_FILE指定的 JSON 文件按代码源 id 覆盖字段。
{"code_sources": {"git": {"name": "Gitea", "host": "https://git.example.com", "username": "oauth2", "token_env": "SOURCEGRAPH_CUSTOM_GIT_TOKEN"}}}| 字段 | 规则 |
|---|---|
name | 显示名称 |
host | HTTPS 源地址,不含路径、用户、查询参数或片段;以小写存储 |
username | 随令牌发送的 Git 用户名,1–64 个字母、数字、.、_、@ 和 -;默认 oauth2 |
token_env | 存放默认令牌的环境变量名,只能是大写字母、数字和 _;网站上不能设置。GitHub 默认为 SOURCEGRAPH_GITHUB_TOKEN,未设置时读取 legacy_token_env 中的旧变量 SOURCEGRAPH_GIT_TOKEN;启动文件设置 token_env 后不再读取旧变量 |
- 启动文件只能覆盖已有的 id;未知 id 或无效值会导致启动失败。令牌绝不能写进该文件。
- 启动文件设置的字段在网站上只读;在网站上修改会返回
409 CODE_SOURCE_LOCKED。 - 仓库保留登记时记录的托管地址(
code_host)。启动时,没有该字段的记录会补上当前托管地址;已记录的地址从不改写,与当前配置不一致时只记日志。 - 只要有任何仓库记录(包括已删除的)使用自定义代码源,修改其托管地址就会返回
409 CODE_SOURCE_IN_USE;名称和用户名仍可修改。 GET /sourcegraph/v1/code-sources按顺序返回生效的代码源,locked列出由启动文件设置的字段;它从不返回令牌或变量名。
站点设置
管理员可以在 Settings 页面或通过 /api/admin/settings 编辑三个分区。每次保存都会携带该分区的当前版本;过期的版本会被拒绝,避免两位管理员在不知情的情况下互相覆盖。
| 分区 | 字段 | 默认值 | 含义 |
|---|---|---|---|
repository_defaults | git_timeout_minutes | 15 | 默认的 Git 拉取与对象补全超时:15、30、45 或 60 分钟。仓库默认继承它,也可以单独设置;新任务使用开始时的当前值 |
retention_mode | days | 新登记仓库的默认保留策略:days 或 count | |
retention_days | 30 | 普通快照自首次观察到之后保留的天数,1–365 | |
retention_count | 20 | 保留最近观察到的普通快照的数量,1–4,096 | |
access | public_read | true | 匿名访客能否搜索和阅读公开仓库;私有仓库永远不对匿名访客开放 |
allow_registration | false | 首次登录时是否创建账号 | |
registration_notice_zh、registration_notice_en | 内置提示 | 向无法注册的人显示的文本 | |
allow_user_repositories | false | 是否允许已登录用户登记仓库;登记者成为该仓库的管理者 | |
code_source | name、host、username | 空,即沿用部署中的值 | 自定义 Git 代码源,见 代码源 |
对 /api/admin/settings 的请求必须使用浏览器会话;携带 Authorization 请求头的请求会被拒绝。全局代码令牌在同一页面单独保存。Storage(存储)页面另外负责迁移 Git 镜像的存放位置;见 运维。
仓库策略
每份登记信息都有自己的策略,初始值取自仓库默认值:
| 设置 | 范围 | 默认值 |
|---|---|---|
| 监控分支 | 1–8 个 | 默认分支 |
| 保留策略 | 自首次观察到之后的天数 1–365,或最近观察到的 1–4,096 个快照,二者不可同时设置 | 站点默认值 |
| 同步间隔(分钟) | 1、3、5、10、30、60、180、360、720 或 1440 | 新登记仓库为 180;保存时未设置间隔的仓库保持 5 |
| 索引模式 | 整个仓库,或 Monorepo 中已登记的路径组 | 整个仓库 |
Git 超时(git_timeout_minutes) | 0 表示继承站点默认值,或 15、30、45、60 | 继承 |
| 管理者 | 除管理员外,最多 50 位可以管理该仓库的已登录用户 | 登记者 |
公开仓库(public_read) | 公开或私有 | 公开 |
固定快照(pinned_commits) | 完整 SHA,最多 4,096 个,保留策略和容量释放都不会移除它们;只能在此处添加,准备提交不会添加固定 | 无 |
存储预算(max_storage_bytes) | 1 GiB 到 10 TiB,涵盖 Git 对象、索引分片和进行中的准备文件;用满时释放最旧的未受保护快照 | 100 GiB |
代码源(code_provider) | github 或 git,登记时确定;先尝试登记人自己为该代码源保存的令牌,再尝试全局令牌 | github |
托管地址(code_host) | 登记时代码源的托管地址,之后每次拉取都使用它 | — |
私有仓库只对其创建者、管理者、在网站上登录的管理员和服务令牌可见;见 登录与准入。
被固定的快照、当前的分支最新提交,以及排队中或运行中任务所用的提交都受保护,永远不会被释放。其他所有快照都是普通快照,包括通过完整 SHA 准备的提交:准备会按需拉取它,但不会固定它。普通快照通过两种方式移除:
- 保留策略在每次同步成功后应用天数或数量规则,并在某次准备发布其索引后立即再应用一次。
- 容量限制会按首次观察时间释放最旧的未受保护快照,而不是拒绝工作:当某个路径组达到 4,096 个快照时,以及在安全时机达到存储预算时触发。安全时机包括:同步或 SHA 准备执行 Git 拉取之前、建索引之前(预留该路径组上一份索引大小的 1.2 倍),以及准备或索引任务完成之后。按预算驱逐时每批最多释放 64 个,每批之后重新测量用量。
已释放的版本会返回 REVISION_NOT_ELIGIBLE,直到再次准备。只有当受保护的快照本身就占满 4,096 个版本或存储预算,或者正在进行的构建超出预算的 120% 时,才会出现 SNAPSHOT_LIMIT 和 REPOSITORY_STORAGE_LIMIT;此时请移除不再需要的固定,或提高存储预算。释放的空间由释放它的任务通过 Git 回收;如果该任务中断,则由每分钟运行一次的后台流程逐个仓库完成 Git 回收。分支、保留策略和固定如何决定哪些提交可被搜索,见 登记仓库。
插件限制
Wasm 证据插件在服务内部运行,受 SOURCEGRAPH_PLUGINS_* 变量设置的资源防护约束。无效值会导致启动失败,而不是移除对应的防护。
| 变量后缀 | 默认值 | 限制内容 |
|---|---|---|
DISABLED | 未设置 | 设为 1 时禁用插件 |
TIMEOUT | 10s | 每次运行的墙钟时间(Go duration 格式) |
MEMORY_MIB | 256 | 每个实例的内存,最多 4,096 |
ARTIFACT_BYTES | 32 MiB | 插件模块大小 |
METADATA_BYTES | 256 KiB | 插件元数据大小 |
FILE_BYTES | 32 MiB | 插件读取的单个文件大小 |
READ_BYTES | 128 MiB | 每次运行读取的总字节数 |
READ_CALLS | 1,024 | 每次运行的文件读取次数 |
OUTPUT_BYTES | 2 MiB | 输出大小 |
CONCURRENCY | 8 | 并发运行数 |
CACHE_ENTRIES | 16 | 保留的已编译模块数 |
IDLE_INSTANCES | 8 | 保留的预热实例数 |
内置限制
有些限制在代码中写死,无法配置:请求体最大 64 KiB,请求截止时间 30 秒,HTTP 服务器超时分别为请求头 5 秒、读取 120 秒、写入 125 秒,以及 HTTP 与 MCP 接口 中描述的搜索、读取、列目录和差异分页大小。搜索引擎作为本地辅助进程运行在 127.0.0.1:6070 上,从不对外暴露。
快照容量固定为每个路径组 4,096 个快照、每个仓库 4,096 个固定快照;按预算驱逐时每批最多释放 64 个快照。
refs 和 resolve 的分支与标签发现把目录保存在内存中,并使用以下固定限制:
| 限制 | 取值 |
|---|---|
| 目录大小 | 200,000 个分支和 200,000 个标签(含提交详情);超出部分只保留名称,并标记为截断 |
| 内存中的目录 | 所有仓库合计 1,000,000 个引用;超出时丢弃最近最少使用的目录 |
| 目录新鲜度 | 5 分钟与上次刷新耗时的三倍,取较长者 |
| 目录刷新 | 每个仓库同时 1 个,每个实例同时 4 个 |
| 首次列出的等待时间 | 请求剩余截止时间减去 2 秒,之后返回 REFS_CATALOG_PREPARING 并带 Retry-After |
| 临时下载 | 每次目录刷新 256 MiB,每次 resolve 查询 16 MiB,所有下载合计 4 GiB;每秒检查一次,并始终遵守 SOURCEGRAPH_MIN_FREE_BYTES 设定的空闲空间预留 |
| 远端查询 | 每个仓库同时 2 个,每个实例同时 8 个,运行中与等待中合计最多 64 个 |
| 查询缓存 | 30 秒(包括“未找到”结果),最多 10,000 条 |
| 失败退避 | 按仓库计,从 10 秒逐步增加到 5 分钟 |
数据目录
| 数据根目录下的路径 | 内容 | 可否重建 |
|---|---|---|
sourcegraph.db | SQLite 数据库:用户、Key、设置、登记信息、凭据,以及应用密钥及其加密密钥 | 否 |
code-credentials.key | 仅存在于从旧版本(凭据密钥保存在磁盘上)升级而来的实例;首次启动时导入数据库,之后只为恢复升级前的备份而保留。全新数据库不会创建密钥文件 | 升级验证完成前不可 |
storage.json | 本机上 Git 镜像的存放位置 | 否 |
space/ | 裸 Git 镜像,除非已在 Storage 页面迁移 | 可以,从远端重新拉取 |
index/、manifests/ | 搜索索引分片及描述它们的清单 | 可以,重新建索引即可 |
refcache/tmp/ | 为 refs 和 resolve 临时下载的分支和标签对象(不含文件树);每份解析后即删除,残留文件在启动时清除 | 临时文件,无需备份 |
容器以非特权用户(uid 10001)运行,需要对整个数据根目录拥有写权限。