Skip to main content
List all models currently loaded and running on your Ollama server. This function shows active models, when they will expire from memory, and how much VRAM they are using.

Samples

List running models

See which models are currently loaded:
SELECT * FROM ai.ollama_ps();
Returns:
    name     |    model     |    size    | expires_at          | size_vram
-------------+--------------+------------+---------------------+-----------
 llama2      | llama2:latest| 3825819519 | 2024-01-15 14:30:00 | 4096000000

Monitor model expiration

Check when models will unload from memory:
SELECT
    name,
    expires_at,
    expires_at - now() AS time_until_unload
FROM ai.ollama_ps()
WHERE expires_at IS NOT NULL
ORDER BY expires_at;

Check VRAM usage

See how much video memory models are consuming:
SELECT
    name,
    pg_size_pretty(size_vram) AS vram_usage,
    pg_size_pretty(size) AS total_size
FROM ai.ollama_ps()
ORDER BY size_vram DESC;

Connect to specific host

Monitor models on a remote Ollama server:
SELECT * FROM ai.ollama_ps(
    host => 'http://ollama-server:11434'
);

Total resource usage

Calculate total VRAM used by all running models:
SELECT
    count(*) AS running_models,
    pg_size_pretty(sum(size_vram)) AS total_vram
FROM ai.ollama_ps();

Arguments

NameTypeDefaultRequiredDescription
hostTEXTNULLOllama server URL (defaults to http://localhost:11434)
verboseBOOLEANFALSEEnable verbose logging for debugging

Returns

TABLE: A table with the following columns:
ColumnTypeDescription
nameTEXTModel name (e.g., llama2, mistral:7b)
modelTEXTFull model identifier
sizeBIGINTModel size in bytes
digestTEXTSHA256 digest of the model
parent_modelTEXTParent model if this is a derivative
formatTEXTModel format (typically gguf)
familyTEXTModel family (e.g., llama, mistral)
familiesJSONBArray of model families
parameter_sizeTEXTNumber of parameters (e.g., 7B, 13B)
quantization_levelTEXTQuantization level (e.g., Q4_0, Q5_K_M)
expires_atTIMESTAMPTZWhen the model will unload from memory
size_vramBIGINTVRAM usage in bytes