Resolution
Slow database performance on a self-hosted Octopus Server is usually caused by fragmented indexes, out-of-date statistics, or large tables that keep growing because retention policies aren't configured or have stopped running. Run the two read-only SQL queries in this article to measure table sizes and index fragmentation, then put a routine SQL Server maintenance plan in place and tighten your retention policies. If performance is still poor after maintenance, send the query results to Octopus Support so we can help you investigate further.
Symptom
You see one or more of the following:
- The Octopus Web Portal, dashboard, or project pages are slow to load. The slowness may affect only specific resources, such as certain projects or library variable sets.
- Pages fail to load with SQL timeout errors.
- Deployments and runbooks take longer than usual.
The Octopus Server logs typically show slow database operations, long-running requests, or connection pool timeouts, similar to:
Reader took 8123ms in transaction '{transaction-name}'
Request took 5123ms: GET {correlation-id}
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
The statement has been terminated. The wait operation timed out.
Scope: when this is the right article
This article applies when:
- You host Octopus Server yourself (on-premises or in your own cloud). On Octopus Cloud, we handle database maintenance for you.
- Octopus feels slow or SQL operations are timing out during normal day-to-day use, not only during an upgrade.
- You, or your database administrator, have access to the Octopus database with SQL Server Management Studio (SSMS) or another SQL client, and permission to view database state (
VIEW DATABASE STATE, orVIEW DATABASE PERFORMANCE STATEon SQL Server 2022 and later).
This isn't the right article if:
- The System Integrity Check fails during an upgrade because of tables or indexes Octopus didn't create. Use Troubleshooting System Integrity Check failures due to non-Octopus tables and indexes instead.
- The slowness is limited to large task logs or package transfers. These are stored on the file system, not in the database. See the file storage and packages sections of the Octopus performance documentation.
Cause
SQL Server is the data persistence backbone of Octopus, so problems with SQL Server make Octopus feel slow across the board. Self-hosted customers are responsible for the routine maintenance of their Octopus database, and the most common causes of slowness are:
- Index fragmentation: As Octopus writes and deletes data, indexes become fragmented and SQL Server has to read more pages to answer each query. Modern versions of Octopus rebuild fragmented indexes during an upgrade, so instances that upgrade infrequently tend to see higher fragmentation.
- Out-of-date statistics: SQL Server uses statistics to plan queries. Stale statistics can lead to inefficient query plans.
-
Large tables: By default, a self-hosted Octopus Server keeps every release and deployment forever. Without retention policies, tables such as
Release,Deployment, andServerTaskkeep growing. TheEventtable holds the audit trail and isn't cleaned up by retention policies, so it's often one of the largest tables in a long-running instance. - Infrastructure: Hosting Octopus Server and SQL Server on the same machine, or an undersized SQL Server, means they compete for CPU, memory, disk, and network.
Diagnosis and fix
-
Check the Octopus Server logs: Open the Octopus Server logs and look for messages such as
Reader took ...ms,Request took ...ms, or connection pool timeouts. Note when they occur and whether they line up with busy periods, scheduled tasks, or other jobs running on the SQL Server. -
Run the table size report: Connect to the Octopus database in SSMS and run the following query. It's read-only and lists every user table with its row count and disk space, largest first.
/*
Table size report
------------------------------------------------------------------
Lists every user table in the current database with its row count
and the disk space it uses (data + indexes + LOB), largest first.
ReservedMB Total space allocated to the table
UsedMB Space actually holding data
UnusedMB Allocated but empty (Reserved - Used)
*/
WITH TableSpace
AS (-- Page counts across every index, partition and allocation unit
SELECT p.object_id,
SUM(a.total_pages) AS ReservedPages,
SUM(a.used_pages) AS UsedPages
FROM sys.partitions AS p
INNER JOIN
sys.allocation_units AS a
ON a.container_id = p.partition_id
GROUP BY p.object_id),
TableRows
AS (-- Heap (0) or clustered index (1) only, so rows aren't double-counted
SELECT p.object_id,
SUM(p.rows) AS TotalRows
FROM sys.partitions AS p
WHERE p.index_id IN (0, 1)
GROUP BY p.object_id)
SELECT s.name AS SchemaName,
t.name AS TableName,
r.TotalRows,
CAST (sp.ReservedPages * 8 / 1024.0 AS DECIMAL (18, 2)) AS ReservedMB,
CAST (sp.UsedPages * 8 / 1024.0 AS DECIMAL (18, 2)) AS UsedMB,
CAST ((sp.ReservedPages - sp.UsedPages) * 8 / 1024.0 AS DECIMAL (18, 2)) AS UnusedMB
FROM sys.tables AS t
INNER JOIN
sys.schemas AS s
ON s.schema_id = t.schema_id
INNER JOIN
TableSpace AS sp
ON sp.object_id = t.object_id
INNER JOIN
TableRows AS r
ON r.object_id = t.object_id
WHERE t.is_ms_shipped = 0
ORDER BY sp.ReservedPages DESC, s.name, t.name;
When you review the results:
- Large
Release,Deployment, orServerTasktables usually mean retention policies are missing or too generous. - A large
Eventtable is expected on instances that have been running for a long time, because the audit trail is kept independently of retention policies. -
Tables you don't recognize may not belong to Octopus. Octopus should have its own database that isn't shared with other applications.
-
Run the index fragmentation report: Run the following query against the Octopus database. It's also read-only, and lists every fragmented index with a suggested action, worst first. On a very large database, it can take a few minutes, so consider running it outside peak hours.
/*
Index fragmentation report
------------------------------------------------------------------
Lists every fragmented index in the current database with a
rule-of-thumb maintenance suggestion for each. Indexes that need
attention are listed first (rebuilds, then reorganizes), worst first.
The thresholds below only affect the SuggestedAction column;
they don't filter any rows out.
*/
DECLARE @MinPageCount AS INT = 1000; -- Smaller indexes rarely benefit from maintenance
DECLARE @MinFragmentation AS DECIMAL (5, 2) = 5.0; -- Below this, no action is needed
DECLARE @RebuildFragmentation AS DECIMAL (5, 2) = 30.0; -- At or above this, suggest a rebuild
SELECT s.name AS SchemaName,
t.name AS TableName,
i.name AS IndexName,
i.type_desc AS IndexType,
ps.partition_number AS PartitionNumber,
CAST (ps.avg_fragmentation_in_percent AS DECIMAL (5, 2)) AS FragmentationPercent,
ps.page_count AS PageCount,
sa.SuggestedAction
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'LIMITED') AS ps
INNER JOIN
sys.indexes AS i
ON i.object_id = ps.object_id
AND i.index_id = ps.index_id
INNER JOIN
sys.tables AS t
ON t.object_id = ps.object_id
INNER JOIN
sys.schemas AS s
ON s.schema_id = t.schema_id
CROSS APPLY (-- Work out the suggested action once, with a priority used for sorting
SELECT CASE WHEN ps.page_count < @MinPageCount THEN 'NONE (too small to matter)' WHEN ps.avg_fragmentation_in_percent < @MinFragmentation THEN 'NONE' WHEN ps.avg_fragmentation_in_percent < @RebuildFragmentation THEN 'REORGANIZE' ELSE 'REBUILD' END AS SuggestedAction,
CASE WHEN ps.page_count < @MinPageCount THEN 4 WHEN ps.avg_fragmentation_in_percent < @MinFragmentation THEN 3 WHEN ps.avg_fragmentation_in_percent < @RebuildFragmentation THEN 2 ELSE 1 END AS ActionPriority) AS sa
WHERE ps.alloc_unit_type_desc = 'IN_ROW_DATA' -- Fragmentation is only reported for in-row data
AND i.index_id > 0 -- Exclude heaps (they have no index to rebuild)
AND ps.avg_fragmentation_in_percent > 0 -- Same as the original: anything fragmented at all
ORDER BY sa.ActionPriority, ps.avg_fragmentation_in_percent DESC, ps.page_count DESC;
Alternatively, you can generate a fragmentation report from inside Octopus with the SQL - Query Octopus Database for Fragmentation community step template. The step asks for a fragmentation threshold; 30% matches the query above. If the step uses Integrated Security, make sure the Tentacle service account on the selected deployment target has access to the Octopus database.
When you review the results:
- Focus on indexes with a
SuggestedActionofREBUILDorREORGANIZEand a highPageCount. Fragmentation on small indexes rarely affects performance. - The query flags indexes for a rebuild at 30% fragmentation, a common SQL Server rule of thumb. Indexes above 50% are the highest priority, because that's the minimum threshold in the Octopus maintenance guidance in step 6.
- Many large indexes marked
REBUILDusually mean no routine index maintenance is running against the Octopus database. -
Index names you don't recognize, such as names starting with
nci_msft_, are often created by automatic tuning features and aren't part of the Octopus schema. They can cause the System Integrity Check to fail during your next upgrade. See Troubleshooting System Integrity Check failures due to non-Octopus tables and indexes. -
Save the results: In SSMS, right-click each results grid, select Save Results As, and save it as a CSV file. Keep these files so you can compare them after maintenance, or share them with Octopus Support.
-
Back up the database: Before running any maintenance, take a full backup of the Octopus database and make sure your Master Key is stored safely.
-
Run index and statistics maintenance: Rebuild or reorganize the fragmented indexes identified by the fragmentation report, then update statistics. As a minimum, the Octopus SQL Server maintenance guidance recommends:
-
Rebuild indexes online with fragmentation above 50% once a day during off-hours.
- Rebuild indexes offline with fragmentation above 50% once a week during off-hours.
- Regenerate statistics once a month.
Ideally, also reorganize or rebuild large indexes between 30% and 50% fragmentation, as flagged by the report.
Online index rebuilds need SQL Server Enterprise edition or Azure SQL Database. On other editions, schedule offline rebuilds during a maintenance window, and consider putting Octopus into maintenance mode first. Don't shrink the database as a performance fix, because shrinking increases index fragmentation.
-
Run the System Integrity Check: In Octopus, run the System Integrity Check. It reports missing or unexpected database indexes and includes a Database Statistics check. If the Database Statistics check reports errors, run the
UPDATEscript shown in the check's output against the Octopus database to refresh the affected statistics. For more background, see the GitHub issue on Database statistics being out of date can affect query performance. If the check reports missing or unexpected indexes, contact Octopus Support. -
Schedule routine maintenance: Make the maintenance from step 6 recurring, using a SQL Server Maintenance Plan, SQL Server Agent jobs, or a community solution like this article on creating an SQL Server Maintenance Solution. A typical plan includes database integrity checks, index reorganize and rebuild tasks, and statistics updates.
-
Tighten retention policies: If the table size report shows large
Release,Deployment, orServerTasktables, configure lifecycle, runbook, and built-in feed retention policies. Retention policies remove releases you no longer need, but the audit trail of those releases and their deployments is kept. Don't delete rows from Octopus tables directly, because this can leave the database in an inconsistent state.
When you first tighten a retention policy on a large instance, the cleanup can create a lot of database load. Consider making the change outside peak hours, and start with a larger policy that you reduce in stages.
-
Check the infrastructure: Make sure Octopus Server and SQL Server run on separate machines, and that SQL Server has enough CPU, memory, and disk throughput for your workload. The minimum requirements section of the Octopus performance documentation has sizing guidance.
-
Escalate to Octopus Support if needed: If performance is still poor after maintenance, contact Octopus Support and include:
-
The CSV results of both queries, ideally from before and after maintenance.
- The results of the System Integrity Check.
- Your Octopus Server version, the number of nodes, and the CPU and memory of each node.
- Your SQL Server version, edition, and hosting details (hardware specs or DTUs).
- The overall database size, and when indexes were last rebuilt and statistics last updated.
- A System Diagnostics Report, or the Octopus Server logs covering a period when the slowness occurred.
- CPU, memory, and disk usage on the Octopus Server and SQL Server during peak and non-peak times.
Support may also ask you to provide database performance metrics.
Verify
- Re-run the index fragmentation report. Large indexes previously marked
REBUILDorREORGANIZEshould now showNONE. - Re-run the System Integrity Check. The Database Statistics check should pass.
- Check the Octopus Server logs. Messages such as
Reader took ...msand connection pool timeouts should be less frequent or gone. - The dashboard, project pages, library variable sets, and deployments load at a normal speed during busy periods, without SQL timeout errors.
- After your retention policies have run, re-run the table size report. Row counts for
Release,Deployment, andServerTaskshould stop growing or start to drop.
Related
- Octopus performance documentation: Sizing, SQL Server maintenance, retention, and troubleshooting guidance for self-hosted Octopus Server.
- Octopus database: Routine maintenance responsibilities and what you can safely change in the Octopus schema.
- Retention policies: How to configure lifecycle, runbook, and built-in feed retention.
- System Integrity Check: What the check covers and how to run it.
- Providing database performance metrics: Extra SQL Server data Octopus Support may ask for.
- Backup and restore: How to back up the Octopus database and Master Key before maintenance.
- Troubleshooting System Integrity Check failures due to non-Octopus tables and indexes: Fixing upgrade-time integrity check failures caused by tables or indexes Octopus didn't create.