Skip to content

Fix pgAdmin Query Timeout โ€“ Statement Cancelled

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Fix pgAdmin Query Timeout. We cover key concepts, practical examples, and best practices.

You run a heavy analytical query in pgAdmin, wait a few seconds, and get "canceling statement due to statement timeout". Your data never arrives.

Wrong โŒ

-- A long-running query that exceeds the default timeout
SELECT generate_series(1, 10000000) AS numbers,
       md5(random()::text) AS hash;

Error in pgAdmin:

ERROR:  canceling statement due to statement timeout

You try increasing statement_timeout in the session:

SET statement_timeout = '0';
-- but the tool's own timeout still fires

Option A โ€” perโ€‘session (in pgAdmin query tool):

-- Run before your heavy query
SET statement_timeout = '300s';  -- 5 minutes
-- or disable entirely
SET statement_timeout = '0';

SELECT generate_series(1, 10000000) AS numbers,
       md5(random()::text) AS hash;

Option B โ€” pgAdmin tool preference:

  1. File โ†’ Preferences โ†’ Query Tool
  2. Set Statement Timeout to e.g. 300000 (ms)
  3. Tick Autoโ€‘commit if needed
  4. Save

Now your query runs to completion:

 numbers   |               hash
-----------+----------------------------------
         1 | 5d41402abc4b2a76b9719d911017c592
         2 | 7d793037a0760186574b0282f2f435e7
...
(10000000 rows)

Root Cause

pgAdmin sends every query with a statement_timeout (default 30โ€“60 s). The PostgreSQL server enforces this at the database level. Either side can kill the query prematurely.

Prevention

  • Set statement_timeout in <a href="/databases/postgresql/">postgresql</a>.conf to a generous default (e.g. 5min) for reporting workloads.
  • Use pgAdmin's Query Tool preferences to raise the tool-level timeout globally.
  • For oneโ€‘off heavy queries, prepend SET statement_timeout = '0'.
  • Monitor active queries with SELECT * FROM pg_stat_activity WHERE state = 'active' to spot timeouts early.

Common Mistakes with query timeout

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world PGADMIN code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

**Q: Does pgAdmin timeout affect all connections?**

A: No โ€” each query tool tab has its own connection. The preference applies to future tabs.

**Q: Can I see how long a query took?**

A: Yes โ€” pgAdmin's history tab logs duration. Also check log_min_duration_statement in postgresql.conf.

**Q: What if my query is cancelled but I see no error?**

A: Look at pgAdmin โ†’ Tools โ†’ Server Status for cancelled queries. The server log also records them.

**Q: Does `statement_timeout` affect transactions?**

A: Yes โ€” the entire transaction is rolled back if any statement hits the timeout.


Learn more about query tuning in the [DodaTech PostgreSQL Performance course](https://dodatech.com/courses/postgresql-performance).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro