Skip to content

qos

QoS resource governor extension for PostgreSQL sessions and queries

pg_qos · QoS resource governor extension for PostgreSQL sessions and queries

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
5240qospg_qos1.1.0ADMINGPL-3.0-or-laterC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Preload; restart on upgrade; Linux affinity.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.1.019 18 17 16 15pg_qos-
RPMPIGSTY1.1.019 18 17 16 15pg_qos_$v-
DEBPIGSTY1.1.019 18 17 16 15postgresql-$v-qos-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el8.aarch64N/APIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el9.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el9.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el10.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el10.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d12.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d12.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d13.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d13.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u22.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u22.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u24.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u24.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u26.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u26.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0

Source

pig build pkg pg_qos;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_qos;		# install by package name
pig install qos;		# install by extension name

pig install qos -v 19;   # install for PG 19
pig install qos -v 18;   # install for PG 18
pig install qos -v 17;   # install for PG 17
pig install qos -v 16;   # install for PG 16
pig install qos -v 15;   # install for PG 15

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'qos';

Create this extension with:

CREATE EXTENSION qos;

Usage

Sources:

qos 1.1 (distribution 1.1.0) applies per-role and per-database resource limits on PostgreSQL 15+. Merge qos into shared_preload_libraries and restart before creating its SQL objects as an administrator. CPU affinity limits require Linux.

Configure Limits

CREATE EXTENSION qos;
ALTER ROLE app_user SET qos.work_mem_limit = '32MB';
ALTER ROLE app_user SET qos.max_concurrent_select = '100';
ALTER ROLE app_user SET qos.max_select_rate = '10/500ms';
SELECT * FROM qos_stat_rate;

Limit Semantics

qos.work_mem_limit caps effective work memory; qos.cpu_core_limit controls CPU affinity on Linux and limits parallel workers on other platforms. qos.max_concurrent_tx, qos.max_concurrent_select, qos.max_concurrent_update, qos.max_concurrent_delete and qos.max_concurrent_insert cap concurrent operations.

qos.max_tx_rate, qos.max_select_rate, qos.max_update_rate, qos.max_delete_rate and qos.max_insert_rate use count/window pairs such as 100/1s. The default -1 disables each rate limit. Windows range from 100 ms to one day. Rate and concurrency violations raise SQLSTATE 54000; clients should use the retry hint. The most restrictive applicable role/database setting wins, and rate pairs are compared by normalized rate.

Observability and Upgrade

qos_stat_rate exposes live windows; the other qos_stat views expose activity and counters. qos_prometheus_metrics() renders Prometheus exposition text. Counters reset at server restart. Version 1.1 replaces the old nonfunctional qos_get_stats() with these views.

Upgrading requires replacing the library and restarting PostgreSQL because the shared-memory layout changes, followed by ALTER EXTENSION qos UPDATE TO '1.1' in each database. New rate limits stay disabled until configured. These controls do not replace application admission limits or operating-system isolation.

Table reader