Update docs to be clearer about sqlite recommendation. Fix Makefile n… (#119591)

* Update docs to be clearer about sqlite recommendation. Fix Makefile not forwarding LDDFLAGS and be more explicit about CGO_ENABLED

* prettier
This commit is contained in:
Kevin Minehart Tenorio
2026-03-05 12:07:12 +01:00
committed by GitHub
parent bd492e6a2f
commit 7a73baf4fa
4 changed files with 26 additions and 5 deletions

View File

@@ -23,7 +23,8 @@ BUILD_STAMP := $(shell echo $${SOURCE_DATE_EPOCH:-$$(date +%s 2>/dev/null)})
GO_LDFLAGS = -X main.version=$(BUILD_VERSION) \
-X main.commit=$(BUILD_COMMIT) \
-X main.buildBranch=$(BUILD_BRANCH) \
-X main.buildstamp=$(BUILD_STAMP)
-X main.buildstamp=$(BUILD_STAMP) \
$(if $(LDFLAGS),-extldflags \"$(LDFLAGS)\")
GO_TEST_FLAGS += $(if $(GO_BUILD_TAGS),-tags=$(GO_BUILD_TAGS))
GIT_BASE = remotes/origin/main
@@ -285,7 +286,7 @@ update-workspace: gen-go
.PHONY: build-go
build-go: gen-themes ## Build all Go binaries (grafana, grafana-server, grafana-cli).
@echo "build go binaries"
$(if $(GO_BUILD_OS),GOOS=$(GO_BUILD_OS)) $(if $(GO_BUILD_ARCH),GOARCH=$(GO_BUILD_ARCH)) $(GO) build -buildvcs=false -trimpath $(GO_RACE_FLAG) $(if $(GO_BUILD_TAGS),-tags $(GO_BUILD_TAGS)) $(if $(GO_BUILD_GCFLAGS),-gcflags "$(GO_BUILD_GCFLAGS)") -ldflags "$(GO_LDFLAGS)" -o ./bin/grafana ./pkg/cmd/grafana
$(if $(CGO_ENABLED),CGO_ENABLED=$(CGO_ENABLED)) $(if $(GO_BUILD_OS),GOOS=$(GO_BUILD_OS)) $(if $(GO_BUILD_ARCH),GOARCH=$(GO_BUILD_ARCH)) $(GO) build -buildvcs=false -trimpath $(GO_RACE_FLAG) $(if $(GO_BUILD_TAGS),-tags $(GO_BUILD_TAGS)) $(if $(GO_BUILD_GCFLAGS),-gcflags "$(GO_BUILD_GCFLAGS)") -ldflags "$(GO_LDFLAGS)" -o ./bin/grafana ./pkg/cmd/grafana
.PHONY: build-backend
build-backend: build-go

View File

@@ -9,7 +9,7 @@ Make sure you have the following dependencies installed before setting up your d
- [Git](https://git-scm.com/)
- [Go](https://golang.org/dl/) (see [go.mod](../go.mod#L3) for minimum required version)
- [Node.js (Long Term Support)](https://nodejs.org), with [corepack enabled](https://nodejs.org/api/corepack.html#enabling-the-feature). See [.nvmrc](../.nvmrc) for supported version. We recommend that you use a version manager such as [nvm](https://github.com/nvm-sh/nvm), [fnm](https://github.com/Schniz/fnm), or similar.
- [GCC](https://gcc.gnu.org/) (required for Cgo] dependencies)
- [GCC](https://gcc.gnu.org/) (optional, not recommded; enables CGO for smaller, dynamically linked binaries)
### macOS
@@ -154,6 +154,22 @@ Log in using the default credentials:
When you log in for the first time, Grafana asks you to change your password.
#### CGO and static builds
By default, `make build-go` (and `make run`) does **not** set `CGO_ENABLED`. Go's default behavior is to enable CGO when a C compiler (GCC) is detected on the system, and disable it otherwise. For local development this is fine — CGO gives you a working SQLite driver for the embedded database.
In **production**, Grafana is built with `CGO_ENABLED=0` to produce a fully static, pure Go binary. This is important because the build environment and the runtime environment are often different (for example, building on Debian but running on Alpine or a scratch container).
You can control both `CGO_ENABLED` and `LDFLAGS` when invoking Make:
```sh
# Static build without CGO (production-style)
CGO_ENABLED=0 make build-go
# Build with Go defaults
unset CGO_ENABLED && make build-go
```
#### Build on Windows
The Grafana backend includes SQLite, a database which requires GCC to compile. So in order to compile Grafana on Windows you need to install GCC with binutils version 2.37 or later.

View File

@@ -370,6 +370,10 @@ Grafana needs a database to store users and dashboards (and other
things). By default it is configured to use [`sqlite3`](https://www.sqlite.org/index.html) which is an
embedded database (included in the main Grafana binary).
{{< admonition type="caution" >}}
SQLite isn't recommended for production environments; use MySQL or PostgreSQL for production deployments.
{{< /admonition >}}
#### `type`
Either `mysql`, `postgres` or `sqlite3`, it's your choice.

View File

@@ -66,8 +66,8 @@ Grafana supports the following databases:
By default Grafana uses an embedded SQLite database, which is stored in the Grafana installation location. If you need to migrate to a different database later, note that database schema and data migrations are customer-managed operations and fall outside the scope of Grafana Support.
{{< admonition type="note" >}}
SQLite works well if your environment is small, but is not recommended when your environment starts growing. For more information about the limitations of SQLite, refer to [Appropriate Uses For SQLite](https://www.sqlite.org/whentouse.html). If you want [high availability](/docs/grafana/latest/setup-grafana/set-up-for-high-availability), you must use either a MySQL or PostgreSQL database. For information about how to define the database configuration parameters inside the `grafana.ini` file, refer to [[database]](/docs/grafana/latest/setup-grafana/configure-grafana/#database).
{{< admonition type="caution" >}}
SQLite isn't recommended for production environments. It works well for local development and small evaluation instances, but it doesn't scale for production workloads. If you want [high availability](/docs/grafana/latest/setup-grafana/set-up-for-high-availability), you must use either a MySQL or PostgreSQL database. For information about how to define the database configuration parameters inside the `grafana.ini` file, refer to [[database]](/docs/grafana/latest/setup-grafana/configure-grafana/#database).
{{< /admonition >}}
Grafana supports the versions of these databases that are officially supported by the project at the time a version of Grafana is released. When a Grafana version becomes unsupported, Grafana Labs might also drop support for that database version. See the links above for the support policies for each project.