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
Gather diagnostics
-
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. -
Check table sizes: Ask your database administrator (DBA) to check the size of each table in the Octopus database. In SQL Server Management Studio (SSMS), right-click the database and select Reports > Standard Reports > Disk Usage by Top Tables.
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.
-
Check index fragmentation: Ask your DBA to check index fragmentation in the Octopus database, for example with the Index Physical Statistics standard report in SSMS. On a very large database, it can take a few minutes, so consider running it outside peak hours. You can also generate a fragmentation report from inside Octopus with the SQL - Query Octopus Database for Fragmentation community step template.
When you review the results:
- Focus on large indexes. Fragmentation on small indexes rarely affects performance.
- Indexes above 50% fragmentation are the highest priority, because that's the minimum threshold in the Octopus maintenance guidance under Run database maintenance. Large indexes between 30% and 50% are also worth maintaining.
- Many large, heavily fragmented indexes usually 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.
If you'd like the exact diagnostic queries Octopus Support uses, contact Octopus Support and we'll send them to you.
- Save the results: Export each report, for example to Excel or PDF from the report viewer in SSMS. Keep these files so you can compare them after maintenance, or share them with Octopus Support.
Run database maintenance
-
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 you found earlier, 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.
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 Out-of-date database statistics can affect query performance (GitHub issue #9795). If the check reports missing or unexpected indexes, contact Octopus Support. -
Schedule routine maintenance: Make the maintenance above 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.
Reduce database load
-
Tighten retention policies: If the table sizes show 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 performance is still poor after maintenance, contact Octopus Support and include:
- The table size and index fragmentation reports, 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
- Check index fragmentation again. Large indexes that were heavily fragmented should now be below 30%.
- 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, check table sizes again. 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.