qos

QoS resource governor extension for PostgreSQL sessions and queries

Overview

PackageVersionCategoryLicenseLanguage
pg_qos1.0ADMINGPL-3.0C
IDExtensionBinLibLoadCreateTrustRelocSchema
5240qosNoYesYesYesNoNo-
Relatedprioritize pg_permissions pg_readonly pg_crash pg_cooldown pg_rewrite pg_repack pgfincore

requires shared_preload_libraries = ‘qos’; official support PG15+

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.01817161514pg_qos-
RPMPIGSTY1.0.01817161514pg_qos_$v-
DEBPIGSTY1.0.01817161514postgresql-$v-qos-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PIGSTY MISS
el8.aarch64PIGSTY MISS
el9.x86_64PIGSTY MISS
el9.aarch64PIGSTY MISS
el10.x86_64PIGSTY MISS
el10.aarch64PIGSTY MISS
d12.x86_64PIGSTY MISS
d12.aarch64PIGSTY MISS
d13.x86_64PIGSTY MISS
d13.aarch64PIGSTY MISS
u22.x86_64PIGSTY MISS
u22.aarch64PIGSTY MISS
u24.x86_64PIGSTY MISS
u24.aarch64PIGSTY MISS

Build

You can build the RPM / DEB packages for pg_qos using pig build:

pig build pkg pg_qos         # build RPM / DEB packages

Install

You can install pg_qos directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_qos;          # Install for current active PG version
pig ext install -y pg_qos -v 18  # PG 18
pig ext install -y pg_qos -v 17  # PG 17
pig ext install -y pg_qos -v 16  # PG 16
pig ext install -y pg_qos -v 15  # PG 15
dnf install -y pg_qos_18       # PG 18
dnf install -y pg_qos_17       # PG 17
dnf install -y pg_qos_16       # PG 16
dnf install -y pg_qos_15       # PG 15
apt install -y postgresql-18-qos   # PG 18
apt install -y postgresql-17-qos   # PG 17
apt install -y postgresql-16-qos   # PG 16
apt install -y postgresql-15-qos   # PG 15

Preload:

shared_preload_libraries = 'qos';

Create Extension:

CREATE EXTENSION qos;

Usage

qos: QoS resource governor extension for PostgreSQL sessions and queries

The qos extension provides Quality of Service resource governance for PostgreSQL, allowing administrators to set per-role and per-database limits on memory usage, CPU cores, and concurrent transactions/statements.

Configuration Parameters

ParameterTypeDescription
qos.work_mem_limitbytesMaximum effective work_mem per session
qos.cpu_core_limitintegerMaximum CPU cores available to a session
qos.max_concurrent_txintegerMaximum concurrent transactions
qos.max_concurrent_selectintegerMaximum concurrent SELECT statements
qos.max_concurrent_updateintegerMaximum concurrent UPDATE statements
qos.max_concurrent_deleteintegerMaximum concurrent DELETE statements
qos.max_concurrent_insertintegerMaximum concurrent INSERT statements

Per-Role Limits

ALTER ROLE app_user SET qos.work_mem_limit = '32MB';
ALTER ROLE app_user SET qos.cpu_core_limit = '2';
ALTER ROLE app_user SET qos.max_concurrent_select = '100';

Per-Database Limits

ALTER DATABASE appdb SET qos.max_concurrent_tx = '200';

Combined Role + Database Limits

ALTER ROLE app_user IN DATABASE appdb SET qos.work_mem_limit = '4MB';
ALTER ROLE app_user IN DATABASE appdb SET qos.max_concurrent_update = '10';

Enforcement Behavior

  • Work memory: Intercepts SET work_mem and rejects values exceeding configured limits
  • CPU limiting (Linux only): Binds backend to N CPU cores via CPU affinity; on non-Linux platforms, limits parallel workers instead
  • Concurrency: Executor hooks track active transactions/statements by type; violations block execution

Observability

SET client_min_messages = 'debug1';  -- enable debug output for QoS events

The most restrictive combination of role-level and database-level settings takes effect. Requires shared_preload_libraries = 'qos' and PostgreSQL 15+.


Last Modified 2026-03-12: add pg extension catalog (95749bf)