# SQLite database

> The whole database of the Spare Cores Navigator as an SQLite file, to download and query with SQL, with example queries.

Links: [Download the Database](https://cdn.sparecores.net/sc-data/latest/sc-data-all.sql.xz), [GitHub repository of sc-data](https://github.com/SpareCores/sc-data), [sparecores-data on PyPI](https://pypi.org/project/sparecores-data/).

The whole database of the Spare Cores Navigator is available as a single
SQLite file, to download and query with SQL: the servers, managed databases,
storage and traffic of all vendors, with their prices and benchmark scores.
The [Schemas](https://docs.sparecores.com/schemas.md) describe its tables and columns.

## Get the database

### With the command line

The Data Wrapper, the `sparecores-data` Python package, downloads the current
version of the database (about 40 MB to download, 1.3 GB once imported):

```shell
pip install sparecores-data
sc-data download sc-data.db
```

Run `sc-data download` again to get a newer version.

### In Python

In Python, the package keeps a copy of the database up to date in its cache,
checking for a newer version every 10 minutes in a background thread, and
`db.path` gives its path. The [Crawler](https://docs.sparecores.com/crawler.md) (`sparecores-crawler`)
defines the tables as [SQLModel](https://sqlmodel.tiangolo.com/) classes, so
that you can query them with SQLModel or SQLAlchemy, e.g. the cheapest
on-demand prices of server types with at least 8 vCPUs and 32 GiB of memory:

```shell
pip install sparecores-data sparecores-crawler
```

```python repl
from sc_data import db
from sc_crawler.tables import Server, ServerPrice
from sqlmodel import Session, create_engine, func, select

db.updated.wait()  # the first run downloads the database
engine = create_engine(f"sqlite:///{db.path}")

with Session(engine) as session:
    query = (
        select(Server.vendor_id, Server.api_reference, func.min(ServerPrice.price).label("hourly_price"))
        .join(ServerPrice, (ServerPrice.vendor_id == Server.vendor_id) & (ServerPrice.server_id == Server.server_id))
        .where(Server.vcpus >= 8, Server.memory_amount >= 32 * 1024)
        .where(ServerPrice.allocation == "ONDEMAND", ServerPrice.status == "ACTIVE", ServerPrice.currency == "USD")
        .group_by(Server.vendor_id, Server.server_id)
        .order_by("hourly_price")
        .limit(5)
    )
    for row in session.exec(query):
        print(row)
```

Environment variables set where the package caches the file, how often it
checks for updates, or a database path of your own, e.g. `SC_DATA_DB_PATH`;
see its [README](https://github.com/SpareCores/sc-data#configuration) for the
full list.

### In R

In R, the same package keeps the database up to date through
[reticulate](https://rstudio.github.io/reticulate/), with `sparecores-data`
installed in its Python environment (e.g. by
`reticulate::py_install("sparecores-data")`), and
[RSQLite](https://rsqlite.r-dbi.org/) queries it, e.g. the number of active
server types of each vendor:

```r
library(reticulate)
library(DBI)

sc_data <- import("sc_data")
sc_data$db$updated$wait()  # the first run downloads the database

con <- dbConnect(RSQLite::SQLite(), sc_data$db$path)
dbGetQuery(con, "
  SELECT vendor_id, COUNT(*) AS server_types
  FROM server
  WHERE status = 'ACTIVE'
  GROUP BY vendor_id")
dbDisconnect(con)
```

### As a file

The database is also available as an xz-compressed SQL dump, to import with
the `sqlite3` command-line tool:

```shell
curl -L https://cdn.sparecores.net/sc-data/latest/sc-data-all.sql.xz | xz -d | sqlite3 sc-data.db
```

## License

The database is published under the BSL 1.1 license (see
[Licensing](https://docs.sparecores.com/overview.md#licensing)). Each release converts to CC BY-SA 4.0 three
years after its publication. The `_metadata` table records the details of the
release, such as when it was published, its license, the additional use grant
and the date of the change:

```sql repl
SELECT * FROM _metadata;
```

## Get to know the data

A few queries to start with, in the `sqlite3` command-line tool. Run `.mode
table` first for readable results.

The number of server types by their status, e.g. active or retired:

```sql repl
SELECT status, COUNT(*) FROM server GROUP BY status;
```

The smallest and largest active server types, by their vCPUs and memory
(`memory_amount` is in MiB):

```sql repl
SELECT MIN(vcpus), MAX(vcpus),
       MIN(memory_amount / 1024.0) AS min_memory_gib,
       MAX(memory_amount / 1024.0) AS max_memory_gib
FROM server
WHERE status = 'ACTIVE';
```

Where each vendor offers its servers, by continents, countries, regions and
zones:

```sql repl
SELECT z.vendor_id,
       COUNT(DISTINCT continent) AS continents,
       COUNT(DISTINCT country_id) AS countries,
       COUNT(DISTINCT z.region_id) AS regions,
       COUNT(*) AS zones
FROM zone AS z
JOIN region USING (vendor_id, region_id)
JOIN country USING (country_id)
GROUP BY 1;
```

Regions are identified by their vendor and region ID together, as two vendors
can have regions with the same ID, hence the join on both.

How much the price of the same server type varies, e.g. the AWS m8g.2xlarge
across regions, zones and allocations (on-demand and spot):

```sql repl
SELECT COUNT(*), MIN(price), ROUND(AVG(price), 4) AS avg_price, MAX(price)
FROM server_price
WHERE vendor_id = 'aws' AND server_id = 'm8g.2xlarge' AND status = 'ACTIVE';
```

The number of benchmark scores by the category of their benchmark:

```sql repl
SELECT b.category, COUNT(*) AS scores
FROM benchmark_score AS s
JOIN benchmark AS b USING (benchmark_id)
WHERE s.status = 'ACTIVE'
GROUP BY 1
ORDER BY 2 DESC;
```

## Example: the cheapest servers for given specs

The cheapest on-demand prices of server types with at least 8 vCPUs and
32 GiB of memory:

```sql repl
SELECT s.vendor_id, s.api_reference, s.vcpus, s.memory_amount / 1024 AS memory_gib,
       MIN(p.price) AS hourly_price, p.currency
FROM server AS s
JOIN server_price AS p USING (vendor_id, server_id)
WHERE s.vcpus >= 8 AND s.memory_amount >= 32 * 1024
  AND p.allocation = 'ONDEMAND' AND p.status = 'ACTIVE' AND p.currency = 'USD'
GROUP BY s.vendor_id, s.server_id
ORDER BY hourly_price
LIMIT 5;
```

Prices are in the vendor's currency (USD or EUR), hence the filter on
`currency` when comparing them (see
[Prices in other currencies](#prices-in-other-currencies)).

## Example: the fastest single core

The scores of all benchmarks are in the `benchmark_score` table. For example,
the same servers ranked by their single-core speed, with PassMark's
[CPU Single Threaded Test](https://docs.sparecores.com/benchmarks/passmark.md#passmark-cpu_single_threaded_test):

```sql repl
SELECT s.vendor_id, s.api_reference, s.cpu_model, b.score AS single_thread,
       MIN(p.price) AS hourly_price, p.currency
FROM server AS s
JOIN benchmark_score AS b ON b.resource_type = 'SERVER'
  AND b.vendor_id = s.vendor_id AND b.resource_id = s.server_id
JOIN server_price AS p USING (vendor_id, server_id)
WHERE b.benchmark_id = 'passmark:cpu_single_threaded_test' AND b.status = 'ACTIVE'
  AND s.vcpus >= 8 AND s.memory_amount >= 32 * 1024
  AND p.allocation = 'ONDEMAND' AND p.status = 'ACTIVE' AND p.currency = 'USD'
GROUP BY s.vendor_id, s.server_id
ORDER BY single_thread DESC
LIMIT 5;
```

## Example: clock speed and single-core speed

The clock speed of a CPU (`cpu_speed`, the maximum the vendor lists) tells
little about how fast a core is. The server types listed at the same clock
speed, with their slowest and fastest single-core speed, by PassMark's
[CPU Single Threaded Test](https://docs.sparecores.com/benchmarks/passmark.md#passmark-cpu_single_threaded_test):

```sql repl
SELECT s.cpu_speed AS ghz, COUNT(*) AS server_types,
       ROUND(MIN(b.score)) AS slowest, ROUND(MAX(b.score)) AS fastest,
       ROUND(MAX(b.score) / MIN(b.score), 1) AS ratio
FROM server AS s
JOIN benchmark_score AS b ON b.resource_type = 'SERVER'
  AND b.vendor_id = s.vendor_id AND b.resource_id = s.server_id
WHERE b.benchmark_id = 'passmark:cpu_single_threaded_test' AND b.status = 'ACTIVE'
  AND s.status = 'ACTIVE' AND s.cpu_speed IS NOT NULL
GROUP BY s.cpu_speed
HAVING COUNT(*) >= 10
ORDER BY ghz;
```

When we ran it in November 2026, the 16 server types listed at 5.0 GHz were
all about as fast, but the fastest at 3.9 GHz was faster than any of them, and
the fastest listed at 2.0 GHz about as fast. At 4.2 or 4.5 GHz, the fastest
server type was 1.5 times as fast as the slowest, and at 2.2 GHz over 14
times.
To find fast cores, rank by a benchmark
(see [the fastest single core](#example-the-fastest-single-core)), not by the
clock speed.

## Example: prices by continent

How much more the same server type costs on each continent than on its
cheapest one, on average. Comparing a server type with itself, in its own
currency, needs no exchange rates:

```sql repl
WITH prices AS (
  -- the average on-demand price of each server type on each continent
  SELECT p.vendor_id, p.server_id, c.continent, AVG(p.price) AS price
  FROM server_price AS p
  JOIN region AS r USING (vendor_id, region_id)
  JOIN country AS c USING (country_id)
  WHERE p.allocation = 'ONDEMAND' AND p.status = 'ACTIVE'
  GROUP BY p.vendor_id, p.server_id, c.continent
),
cheapest AS (
  SELECT vendor_id, server_id, MIN(price) AS price
  FROM prices
  GROUP BY vendor_id, server_id
)
SELECT p.continent, COUNT(*) AS server_types,
       ROUND(AVG(p.price / c.price - 1) * 100, 1) AS avg_premium_pct
FROM prices AS p
JOIN cheapest AS c USING (vendor_id, server_id)
GROUP BY p.continent
ORDER BY avg_premium_pct;
```

When we ran it in November 2026, a server type cost on average about the same
in North America as on its cheapest continent, 11 to 12% more in Asia and
Europe, 18 to 19% more in Africa and Oceania, and 48% more in South America.
For a deeper analysis of the price differences, e.g. by vendor, see the
[talks](https://sparecores.com/talks) on sparecores.com.

## Example: the cost of LLM inference

Which server generates text with an LLM at the lowest cost? The
`llm_speed:text_generation` benchmark measures how many tokens a server
generates per second with a given model (see
[LLM speed](https://docs.sparecores.com/benchmarks/llm_speed.md)), and the prices tell what an hour of the
server costs, so their ratio is the cost of a million generated tokens:

```sql repl
WITH prices AS (
  -- the cheapest on-demand price of each server type, in USD
  SELECT vendor_id, server_id, MIN(price) AS price
  FROM server_price
  WHERE allocation = 'ONDEMAND' AND status = 'ACTIVE' AND currency = 'USD'
  GROUP BY vendor_id, server_id
),
speed AS (
  -- the tokens generated per second with the model
  SELECT vendor_id, resource_id AS server_id, MAX(score) AS tokens_per_second
  FROM benchmark_score
  WHERE resource_type = 'SERVER' AND status = 'ACTIVE'
    AND benchmark_id = 'llm_speed:text_generation'
    AND json_extract(config, '$.model') = 'Llama-3.3-70B-Instruct-Q4_K_M.gguf'
    AND json_extract(config, '$.tokens') = 128
  GROUP BY vendor_id, resource_id
)
SELECT vendor_id, api_reference, vcpus,
       memory_amount / 1024 AS memory_gib,
       accelerator_count AS gpus, accelerator_model AS gpu_model,
       ROUND(tokens_per_second, 2) AS tokens_per_second,
       price AS hourly_price,
       ROUND(price / (tokens_per_second * 3600 / 1e6), 2) AS usd_per_million_tokens
FROM server
JOIN prices USING (vendor_id, server_id)
JOIN speed USING (vendor_id, server_id)
ORDER BY usd_per_million_tokens
LIMIT 10;
```

Swap the model for another, e.g. `gemma-2b.Q4_K_M.gguf`, to see how the
picture changes. The [LLM speed](https://docs.sparecores.com/benchmarks/llm_speed.md) benchmark lists the
models and token counts measured.

When we ran it in November 2026, the cheapest way to generate text with Llama
3.3 70B was, surprisingly, a CPU-only Azure server
([Standard_F32ams_v6](https://sparecores.com/server/azure/Standard_F32ams_v6)),
at about $30 per million tokens, ahead of GPU servers such as the AWS
[g7e.4xlarge](https://sparecores.com/server/aws/g7e.4xlarge) with an RTX PRO
6000 at about $36. But the Azure server generated only about 3
tokens per second, against 31 of the GPU server, so the cheapest is not always
the right choice. With the small Gemma 2B model, cheap CPU-only servers of
Azure and Vultr led, at well under $1 per million tokens. The data changes
often, so run the query for the current picture.

The ranking also depends on the task: with `llm_speed:prompt_processing`, the
speed of reading the prompt, GPU servers led for Llama 3.3 70B, at under $1.50
per million tokens, as reading the prompt needs more compute than generating
text. And the cost per token leaves out other costs, such as the storage for
the model (over 70 GB for Llama 3.3 70B, see the `storage_price` table) and the
egress of the generated text (`traffic_price`).

### Prices in other currencies

The query compares USD prices only. Some vendors, such as Hetzner Cloud,
OVHcloud and UpCloud, price their servers in EUR, and the database has no
exchange rates to convert them, so they are left out.

The [API](https://docs.sparecores.com/api.md) converts all prices to USD (or the currency of your choice),
so it compares every vendor. For example, the same ranking over the `/servers`
endpoint, by the benchmark's score per price (see the
[API examples](https://docs.sparecores.com/api/examples.md#rank-servers-by-cost-efficiency) for more):

```shell
curl -G https://keeper.sparecores.net/servers \
  -d benchmark_id=llm_speed:text_generation \
  --data-urlencode 'benchmark_config={"model": "Llama-3.3-70B-Instruct-Q4_K_M.gguf", "tokens": 128}' \
  -d best_price_allocation=ONDEMAND_ONLY \
  -d order_by=selected_benchmark_score_per_price \
  -d order_dir=desc \
  -d limit=10
```

With all vendors in, OVHcloud's GPU servers led this ranking for Llama 3.3
70B, and UpCloud's small CPU-only servers for Gemma 2B, when we ran it. The
[server listing](https://sparecores.com/servers) of the [Web UI](https://docs.sparecores.com/web-ui/listings.md) shows the same, without
writing code: select the benchmark and its configuration with
**Select Benchmark**, and sort by **$ EFFICIENCY**.

## Tips

- Filter on `status = 'ACTIVE'` for the current offerings: the database
  also keeps the server types, prices and scores that are no longer
  available.
- The `config` of a benchmark score is JSON: match its fields with
  `json_extract`, as it can have other fields too.
- Benchmark scores refer to servers or managed databases: `resource_type`
  tells which, and `resource_id` is the server or database ID.
- Prices are in the vendor's currency (`currency`), and per the `unit` of
  the price, e.g. per hour for servers.
