> For the complete documentation index, see [llms.txt](https://help.qtech.co.nz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.qtech.co.nz/datran/datran-vi-scada/datran-vi/persistent-queues.md).

# Persistent queues

How DATRAN VI V6.78 saves incoming data to disk before SQL Server, what unrecoverable files are, and which statistics to alarm on.

Traditionally, the DATRAN logging services, ADO for base-logging to SQL Server and HDI for RTU logged data, used a recovery file system to store data locally if the connection to the SQL Server database was unavailable. This system has been overhauled in DATRAN V6.78 and replaced with a new persistent queueing system which serves a similar but enhanced function. The persistent queue system ensures that inbound data is saved to disk as quickly as possible with minimal latency.

{% hint style="info" %}
**Applies to:** DATRAN VI V6.78, ADO and HDI services, from QTech's Persistent Queues application note (rev 01, August 2025). For experienced DATRAN operators who have familiarity with configuring the DATRAN Real Time Database (the TBD).
{% endhint %}

## How it works

* A persistent queue creates small "queue files" (\*.PQF) continuously on the DATRAN Server hard drive instead of "recovery files" solely in the event of a SQL server fault. The persistent queue system stores data across many small files organized into folders. These files each have a maximum size of 4KB. Each record in the queue is encoded with a 16-bit checksum to protect against importing corrupted data.
* The files are produced then consumed dynamically as the data in them is pulled from the front of the queue and sent to the SQL server. The queue system supports simultaneous read/write, so the arrival of new data is not impeded while processing a large backlog. Speeds exceeding 10,000 records/second are expected on a modern system with a good database connection.
* In the unlikely event of a file corruption, the impact can be contained to a single file.
* Each service has its own set of persistent queues, and operates independently. Each service owns its own connection to the database.

| Queue               | Holds                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Log\_analog         | Analogue points                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| Log\_event          | Digital points                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| execute\_non\_query | Data that must be persisted but doesn't fall into the first two queues. Used by ADO but not by HDI at all. Usually SQL commands containing information that may end up in other tables in the SQL Database: ADO internally generated commands to manage the database (creating tables, stored procedures, purging the audit log, etc.), log SMS messages, and commands that arrive to the ADO via a UDP connection (used by SAC and EPL services). |

Other SQL commands can come from other sources in the TBD, for example in scripts or from an `_ADO_Execute_` node. These are usually not persisted and will generally return an error (to the calling procedure) if they fail. One exception is if the `_ADO_Execute_` node is calling one of the logging stored procedures e.g. sp\_LogAnalogue, these are persisted.

### Throughput

|                                     | Before V6.78                       | V6.78                              |
| ----------------------------------- | ---------------------------------- | ---------------------------------- |
| ADO                                 | 20 telemetry log points per second | Up to about 1000 points per second |
| HDI                                 |                                    | Up to 10,000 points per second     |
| With one SQL connection per service |                                    | About 20% of maximum throughput    |

## Recoverable and unrecoverable errors

* **Recoverable Error:** An attempt to execute a SQL command failed due to an external condition unrelated to the content of the command itself. Most often this because of a connection error or degradation to the SQL server. The command will be able to be completed at a later time once a stable connection to the SQL server has been re-established. When a Recoverable Error is encountered, the Persistent Queue system enters a re-connect procedure, and no further commands are attempted until the connection has been re-established. The last attempted command (or batch of commands) remains at the front of the queue.
* **Unrecoverable Error:** An attempt to execute a SQL command failed due to an inherent problem with the command. The error is not caused by a connection problem, and will not be resolved by simply re-attempting the command at a later time. When an Unrecoverable Error is encountered, the failing command (or batch of commands) are removed from the front of the queue and placed in a subfolder called "unrecoverable", along with a text file containing any related error messages. Persistent queue Unrecoverable Errors do not impede other commands/queries from executing.

The unrecoverable folders are periodically flushed. When flushed, these failed commands are re-attempted. If successful, they are deleted. If not, they remain in the unrecoverable folder. Files older than a specified purge period (default period is infinite) are permanently deleted. This is typically changed to one week if the system is running well. Note that when unrecoverable commands are re-attempted and executed successfully, any related error message text files are not deleted immediately. These are retained for the specified purge period regardless, for diagnostic purposes.

In general, the unrecoverable folders should be empty. It is not a cause for concern if occasional log files or empty folders appear, these are scanned every hour and cleaned up (removed).

## Settings and statistics

Four key nodes are found under the ADO Database Connectivity Application in Datran Browser, under **\<computer>\Applications\ADO Database Connectivity\Databases\\\<database>\Properties**: **ADO Persistent Queue Management**, **ADO Statistics**, **HDI Persistent Queue Management** and **HDI Statistics**. The **Active Connection** node is retained to show if Datran is connected to the SQL server or not. In previous versions of Datran the Active Connection might show a "connected" state but was not able to sense a highly degraded connection, connected but in practical terms not processing data at all quickly due to very high latency.

![The ADO Persistent Queue Management node with its settings and queue sizes](https://3621580088-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5hMAUl7E1cWeN5Rghg0%2Fuploads%2FzVPojDlrueKOdKzywjdc%2Fado-persistent-queue-management.png?alt=media)

| Setting                         | Default  | What it does                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Auto Flush Unrecoverable        | 1        | Controls whether or not the unrecoverable folders should be automatically flushed periodically. Can be 0 or 1. Automatic flushing is recommended.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| Auto Flush Unrecoverable Period | 1 hour   | Controls how often to automatically flush the unrecoverable folders. Min 1 hour, max 1 week.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| Force Flush Unrecoverable       | 0        | Setting this node to 1 manually triggers an immediate flush of the unrecoverable folders. Automatically resets to 0.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| Purge Unrecoverable Older Than  | Infinite | Controls how long files may remain in the unrecoverable folders before they are permanently deleted. Min 1 week, max infinite. Automatic purging deletes everything older than this, including the error logs. Once the system is bedded in then it is normal to set the purge frequency to around a week so that folders/file artifacts are removed.                                                                                                                                                                                                                                                                                                             |
| Unrecoverable Last Flushed      |          | The time when the unrecoverable folders were last flushed, either automatically or manually. This time also determines when the next automatic flush will occur (i.e., the next auto flush will be at Unrecoverable Last Flushed + Auto Flush Unrecoverable Period).                                                                                                                                                                                                                                                                                                                                                                                              |
| Size On Disk (KB)               |          | Reports the current size on disk of the data stored in the persistent queue. This node can be used for alarming, to detect when the queue has grown to an overlarge size, which would typically indicate an error condition. Under it, for each queue: **Queue File Count** (number of .pqf files in the specific queue), **Queue Size On Disk** (cumulative size of the .pqf files in the specific queue), **Unrec File Count** (number of files in the unrecoverable folder of the specific queue, including .pqf files and error .txt files) and **Unrec File Size On Disk** (cumulative size of the files in the unrecoverable folder of the specific queue). |

### Statistics

The statistics are aggregated over four data windows: the last minute, last hour, last 24 hours and current day.

![The ADO Statistics node for the current day](https://3621580088-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5hMAUl7E1cWeN5Rghg0%2Fuploads%2FMP33aVsPlHLI1qew0Ilv%2Fado-statistics.png?alt=media)

| Statistic                                     | Means                                                                                                                                                                                                                                                                                                                                                     |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Analog Records Logged, Digital Records Logged | Total number of unique analogue (or digital) records logged in the specified time period. Only counts records that are successfully logged to SQL. Does not count records still in the persistent queue, or records that were processed from the persistent queue but were already in the database (i.e., failed to upload due to primary key exception). |
| Average SQL Server Latency (ms)               | Estimate of the response time of SQL Server to probes of the connection. Probes occur every 15 seconds. See [Upgrade to DATRAN VI V6.78](https://help.qtech.co.nz/datran/datran-vi-scada/datran-vi/install/upgrade-to-v6-78.md#average-sql-latency-isnt-always-accurate).                                                                                 |
| Connected %                                   | Percentage of connection probes that are successful.                                                                                                                                                                                                                                                                                                      |
| Disconnection Event Count                     | Count of how many times the SQL Server connection was lost.                                                                                                                                                                                                                                                                                               |
| Error Count                                   | Count of how many unrecoverable errors were encountered (errors that are not simple disconnect events).                                                                                                                                                                                                                                                   |
| Other Commands Executed                       | Count of non-query commands executed other than logging analogues or digitals. These are further subdivided into specific types, which are self-explanatory. These may be executed via `_ADO_Execute_` nodes, or generated by other DATRAN services such as the Alarm Service, Paging, SMS Direct, and Security Access Controller.                        |
| Other Queries Executed                        | Count of queries executed via `_ADO_Query_` nodes.                                                                                                                                                                                                                                                                                                        |

DATRAN already provides statistics for communications channel queues and performance which can be used in conjunction with these new statistics to evaluate throughput of data from the telemetry network. The latency of the round trip of a probe and results is calculated to provide a figure of merit as to the reliability of the connection and acts as an early warning of a degraded connection. For example, these statistics can be used to detect not just link latency but that a SQL server database itself is struggling as it runs out of disk space if the disk is thrashing or unable to process transactions quickly. The number of disconnections is also an indicator of a communications problem.

## Alarms to set up

Most of the time the Persistent Queue system should not require any oversight. Generally the Administrator will be looking for a buildup of unrecoverable files or queues that are not clearing quickly. The suggested policy is to create alarms for the following. Monitor the Unrec File Count node under each queue for both the ADO and HDI Persistent Queue Management nodes in the ADO and HDI applications.

| Alarm when                  | Suggested threshold                                                                                                                                                                                                                                                                                                                                                                                    | Points to                                                                                                                          |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| Log Analog Unrec File Count | More than 0 (though this may occur when the service starts) so greater than 2 might be a threshold. However if it is a systemic error the count could rise above 100, this may be a good value when bedding the system in but reduce to 1 or 2 when the Scada system has been working well for a while. Verification testing was done with a Datran alarm set to activate if the file count exceeds 5. | A buildup of unrecoverable files                                                                                                   |
| Current Day Error Count     | More than 1 (ought to be 0 normally)                                                                                                                                                                                                                                                                                                                                                                   | Unrecoverable errors                                                                                                               |
| Connected %                 | Below 99%                                                                                                                                                                                                                                                                                                                                                                                              | This will drop as more disconnection events or latency causing retries then failures occurs                                        |
| Disconnection Event Count   | More than 1                                                                                                                                                                                                                                                                                                                                                                                            | Lots of dropouts indicates a comms/connection problem to SQL server or possibly incorrect credentials or refusal by the SQL server |
| Queue File Count            | More than 5                                                                                                                                                                                                                                                                                                                                                                                            | Possibly high latency on link to SQL server                                                                                        |

Unrecoverable files are not expected to be generated during normal operation. Occasionally one or two might be generated due to an unexpected fault, but should be consumed next time the unrecoverable files are flushed. If you have unrecoverable files that are not clearing after multiple flushes, contact QTech. See [Unrecoverable files are building up](https://help.qtech.co.nz/datran/datran-vi-scada/datran-vi/troubleshooting/unrecoverable-files.md).

## Don't touch the queue files

Operators should not manually interfere with the generated files and folders in the Persistent Queue system. This includes opening the files. This is particularly true of the main queue folders. If the queue system is unable to find or open one of these .PQF files (possibly because you have a file open in a text editor or other program) then it will lose track of the file and the data it contains. In this case, the situation can only be resolved by restarting the service owning the queue (either the ADO or Historical Data Interface).

## Move the queue folders

Outside of the Persistent Queue Management node, the Recovery Path nodes are used to configure where the persistent queue data is stored. The **ADO Recovery Path** is the directory on disk where the persistent queue files owned by the ADO service are stored. Default is `<Program Data Folder>\QTech\DATRAN\ADORecovery\`. The **HDI Recovery Path** is the directory on disk where the persistent queue files owned by the HDI service are stored. Default is `<Program Data Folder>\QTech\DATRAN\HDIRecovery\`. Note that `<Program Data Folder>` is a standard Windows system folder, typically C:\Program Data.

Ideally these pathnames should not be configured under a user account in %APPDATA% but preferably under %PROGRAMDATA% which is accessible by the Datran Server Account (e.g. DatranService) which is used to install Datran and must have ACL privileges (read/write) to access the folder and subfolders. Here is a procedure if Operators wish to move the location of the recovery folders (IT administrators only):

1. Create the directory you want to use for the new location(s) - if changing both ADO and HDI recovery paths, make sure you create a different directory for each, they can't share a directory.
2. Stop the service (ADO or HDI, or both).
3. Navigate to the current recovery path(s) - copy and paste whatever you find there to the new directory(s). If nothing there, that's fine.
4. Change the path(s) in the TBD to the new directory(s).
5. Restart the service(s).

## SQL connections

DATRAN V6.78 will work best if multiple connections to SQL server are allowed. However, this is controlled by the SQL administrator (SYSADMIN) and on some installations the SQL server may have been configured to place limits on the number of connections to the server. The persistent queue system can be configured to operate with just one connection:

1. A node may be created at **\<computer>\Applications\ADO Database Connectivity\Properties\Allow Concurrent Connections**.
2. Allow Concurrent Connections controls whether or not the Persistent Queue system may open multiple simultaneous connections to the SQL server. May be 0 or 1. Default is 1. Setting it to 0 will sacrifice performance and throughput but constrain operation to that consistent with older versions of Datran.
