Skip to content

citus

citus : Distributed PostgreSQL as an extension

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2400
citus
citus
14.1.0
OLAP
AGPL-3.0
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--
No
Yes
Yes
Yes
no
no
Relationships
Schemaspg_catalog
Need By
documentdb_distributed
See Also
pg_partman
plproxy
columnar
pg_fkpart
timescaledb
pg_duckdb
tablefunc
hll
Siblings
citus_columnar

conflict with hydra

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
14.1.0
18
17
16
15
14
citus-
RPM
PIGSTY
14.1.0
18
17
16
15
14
citus_$v-
DEB
PIGSTY
14.1.0
18
17
16
15
14
postgresql-$v-citus-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PGDG 13.2.0
PGDG 13.0.0
el8.aarch64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PGDG 13.2.0
PGDG 13.0.0
el9.x86_64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PGDG 13.2.0
PGDG 13.0.0
el9.aarch64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PGDG 13.2.0
PGDG 13.0.0
el10.x86_64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PGDG 13.2.0
MISS
el10.aarch64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PGDG 13.2.0
MISS
d12.x86_64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 13.2.0
PIGSTY 13.0.0
d12.aarch64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 13.2.0
PIGSTY 13.0.0
d13.x86_64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 13.2.0
MISS
d13.aarch64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 13.2.0
MISS
u22.x86_64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 13.2.0
PIGSTY 13.0.0
u22.aarch64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 13.2.0
PIGSTY 13.0.0
u24.x86_64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 13.2.0
PIGSTY 13.0.0
u24.aarch64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 13.2.0
PIGSTY 13.0.0
u26.x86_64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
MISS
MISS
u26.aarch64
PIGSTY 14.1.0
PIGSTY 14.1.0
PIGSTY 14.1.0
MISS
MISS
PackageVersionOSORGSIZEFile URL
citus_1814.1.0el8.x86_64pigsty983.9 KiBcitus_18-14.1.0-1PIGSTY.el8.x86_64.rpm
citus_1814.1.0el8.x86_64pgdg871.9 KiBcitus_18-14.1.0-1PGDG.rhel8.10.x86_64.rpm
citus_1814.0.0el8.x86_64pgdg859.5 KiBcitus_18-14.0.0-1PGDG.rhel8.10.x86_64.rpm
citus_1814.1.0el8.aarch64pigsty943.8 KiBcitus_18-14.1.0-1PIGSTY.el8.aarch64.rpm
citus_1814.1.0el8.aarch64pgdg822.0 KiBcitus_18-14.1.0-1PGDG.rhel8.10.aarch64.rpm
citus_1814.0.0el8.aarch64pgdg810.2 KiBcitus_18-14.0.0-1PGDG.rhel8.10.aarch64.rpm
citus_1814.1.0el9.x86_64pigsty881.8 KiBcitus_18-14.1.0-1PIGSTY.el9.x86_64.rpm
citus_1814.1.0el9.x86_64pgdg837.2 KiBcitus_18-14.1.0-1PGDG.rhel9.8.x86_64.rpm
citus_1814.0.0el9.x86_64pgdg823.8 KiBcitus_18-14.0.0-1PGDG.rhel9.8.x86_64.rpm
citus_1814.0.0el9.x86_64pgdg823.9 KiBcitus_18-14.0.0-1PGDG.rhel9.7.x86_64.rpm
citus_1814.0.0el9.x86_64pgdg824.3 KiBcitus_18-14.0.0-1PGDG.rhel9.6.x86_64.rpm
citus_1814.1.0el9.aarch64pigsty835.7 KiBcitus_18-14.1.0-1PIGSTY.el9.aarch64.rpm
citus_1814.1.0el9.aarch64pgdg808.3 KiBcitus_18-14.1.0-1PGDG.rhel9.8.aarch64.rpm
citus_1814.0.0el9.aarch64pgdg797.4 KiBcitus_18-14.0.0-1PGDG.rhel9.8.aarch64.rpm
citus_1814.0.0el9.aarch64pgdg797.3 KiBcitus_18-14.0.0-1PGDG.rhel9.7.aarch64.rpm
citus_1814.0.0el9.aarch64pgdg797.8 KiBcitus_18-14.0.0-1PGDG.rhel9.6.aarch64.rpm
citus_1814.1.0el10.x86_64pigsty875.7 KiBcitus_18-14.1.0-1PIGSTY.el10.x86_64.rpm
citus_1814.1.0el10.x86_64pgdg849.0 KiBcitus_18-14.1.0-1PGDG.rhel10.2.x86_64.rpm
citus_1814.0.0el10.x86_64pgdg836.1 KiBcitus_18-14.0.0-1PGDG.rhel10.2.x86_64.rpm
citus_1814.0.0el10.x86_64pgdg835.4 KiBcitus_18-14.0.0-1PGDG.rhel10.1.x86_64.rpm
citus_1814.0.0el10.x86_64pgdg835.7 KiBcitus_18-14.0.0-1PGDG.rhel10.0.x86_64.rpm
citus_1814.1.0el10.aarch64pigsty843.7 KiBcitus_18-14.1.0-1PIGSTY.el10.aarch64.rpm
citus_1814.1.0el10.aarch64pgdg818.3 KiBcitus_18-14.1.0-1PGDG.rhel10.2.aarch64.rpm
citus_1814.0.0el10.aarch64pgdg805.9 KiBcitus_18-14.0.0-1PGDG.rhel10.2.aarch64.rpm
citus_1814.0.0el10.aarch64pgdg806.0 KiBcitus_18-14.0.0-1PGDG.rhel10.1.aarch64.rpm
citus_1814.0.0el10.aarch64pgdg806.1 KiBcitus_18-14.0.0-1PGDG.rhel10.0.aarch64.rpm
postgresql-18-citus14.1.0d12.x86_64pigsty2.7 MiBpostgresql-18-citus_14.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-citus14.1.0d12.aarch64pigsty2.6 MiBpostgresql-18-citus_14.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-citus14.1.0d13.x86_64pigsty2.7 MiBpostgresql-18-citus_14.1.0-1PIGSTY~trixie_amd64.deb
postgresql-18-citus14.1.0d13.aarch64pigsty2.6 MiBpostgresql-18-citus_14.1.0-1PIGSTY~trixie_arm64.deb
postgresql-18-citus14.1.0u22.x86_64pigsty2.9 MiBpostgresql-18-citus_14.1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-citus14.1.0u22.aarch64pigsty2.9 MiBpostgresql-18-citus_14.1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-citus14.1.0u24.x86_64pigsty2.8 MiBpostgresql-18-citus_14.1.0-1PIGSTY~noble_amd64.deb
postgresql-18-citus14.1.0u24.aarch64pigsty2.8 MiBpostgresql-18-citus_14.1.0-1PIGSTY~noble_arm64.deb
postgresql-18-citus14.1.0u26.x86_64pigsty2.8 MiBpostgresql-18-citus_14.1.0-1PIGSTY~resolute_amd64.deb
postgresql-18-citus14.1.0u26.aarch64pigsty2.8 MiBpostgresql-18-citus_14.1.0-1PIGSTY~resolute_arm64.deb

Source

pig build pkg citus;		# 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 citus;		# install via package name, for the active PG version

pig install citus -v 18;   # install for PG 18
pig install citus -v 17;   # install for PG 17
pig install citus -v 16;   # install for PG 16

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'citus';

Create this extension with:

CREATE EXTENSION citus;

Usage

Sources:

Citus turns PostgreSQL into a distributed database by sharding tables across worker nodes while keeping PostgreSQL SQL, indexes, extensions, transactions, and operational tooling as the user-facing surface. It is commonly used for multi-tenant SaaS databases, real-time analytics, time-series/event workloads, and distributed microservice schemas.

The local Pigsty catalog packages Citus as citus and exposes the lead extension citus; the same package also contains citus_columnar. Citus is a preload extension, so every node must load the library before CREATE EXTENSION.

Enable Citus

shared_preload_libraries = 'citus'

Restart PostgreSQL on the coordinator and workers, then create the extension in the database:

CREATE EXTENSION IF NOT EXISTS citus;
SELECT citus_version();

On a multi-node cluster, register the coordinator and workers from the coordinator:

SELECT citus_set_coordinator_host('coord-1', 5432);
SELECT * FROM citus_add_node('worker-1', 5432);
SELECT * FROM citus_add_node('worker-2', 5432);

SELECT * FROM citus_get_active_worker_nodes();

Distributed Tables

Distribute a table by a shard key. Rows with the same shard-key value are colocated on the same shard, so tenant-scoped joins and point lookups stay local.

CREATE TABLE events (
  tenant_id  bigint,
  event_id   bigserial,
  event_at   timestamptz DEFAULT now(),
  kind       text,
  payload    jsonb,
  PRIMARY KEY (tenant_id, event_id)
);

SELECT create_distributed_table('events', 'tenant_id');

You can tune the shard count and colocation explicitly:

SELECT create_distributed_table(
  'events',
  'tenant_id',
  shard_count  := 64,
  colocate_with := 'default'
);

Queries that filter on the distribution column can route to a single shard:

SELECT *
FROM events
WHERE tenant_id = 42
ORDER BY event_at DESC
LIMIT 50;

Cross-shard queries are planned as distributed tasks and run in parallel on the workers:

SELECT kind, count(*)
FROM events
WHERE event_at >= now() - interval '1 hour'
GROUP BY kind
ORDER BY count DESC;

Reference Tables

Reference tables are fully replicated to all workers. They are useful for small lookup tables that must join with many distributed tables.

CREATE TABLE countries (
  code text PRIMARY KEY,
  name text NOT NULL
);

SELECT create_reference_table('countries');

Schema-Based Sharding

Schema-based sharding is useful when each tenant or service owns its own schema. In v14.1.0, Citus adds support for running several schema-sharding DDLs from any node, including CREATE SCHEMA, DROP SCHEMA, ALTER SCHEMA RENAME, ALTER SCHEMA OWNER, and table-level DDL on distributed schemas.

CREATE SCHEMA tenant_42;
SELECT citus_schema_distribute('tenant_42');

CREATE TABLE tenant_42.orders (
  id bigserial PRIMARY KEY,
  amount numeric,
  created_at timestamptz DEFAULT now()
);

Use row-based distribution for shared tables and schema-based sharding for per-tenant schema layouts; do not mix the two models casually without checking colocation and SQL-support implications.

Node and Shard Operations

-- Add or disable nodes.
SELECT * FROM citus_add_node('worker-3', 5432);
SELECT * FROM citus_disable_node('worker-2', 5432);
SELECT * FROM citus_activate_node('worker-2', 5432);

-- Drain and remove a node.
SELECT * FROM citus_drain_node('worker-1', 5432);
SELECT * FROM citus_remove_node('worker-1', 5432);

-- Rebalance shards.
SELECT citus_rebalance_start();
SELECT * FROM citus_rebalance_status();
SELECT rebalance_table_shards('events');

-- Inspect tables and shards.
SELECT * FROM citus_tables;
SELECT * FROM citus_shards;

Backup Coordination

Citus v14.1.0 adds UDFs for blocking distributed 2PC commit decisions and schema/topology changes while taking coordinated disk snapshots. Use them only inside a controlled backup workflow, and always unblock the cluster after the snapshot step.

SELECT citus_cluster_changes_block();
SELECT * FROM citus_cluster_changes_block_status();

-- Take coordinated filesystem or volume snapshots here.

SELECT citus_cluster_changes_unblock();

Pair these functions with regular PostgreSQL backup discipline: consistent checkpoints, WAL archiving, snapshot ordering across nodes, and a tested restore procedure.

Caveats

  • Pigsty local metadata currently tracks Citus 14.x for PostgreSQL 16-18; Citus 14 dropped PostgreSQL 15 support.
  • shared_preload_libraries = 'citus' must be set before extension creation. A plain CREATE EXTENSION citus is not enough on a fresh server.
  • Choose the distribution column carefully. Primary keys and unique constraints on distributed tables generally need to include the distribution column.
  • Cross-shard joins, repartition joins, distributed DDL, and multi-shard writes are powerful but have different planning and locking behavior from single-node PostgreSQL.
  • Citus includes its own columnar storage surface through citus_columnar; Pigsty metadata marks it as conflicting with Hydra columnar.
  • The cluster-change blocking functions are operational tools for backups. Do not leave a cluster blocked after a failed backup script.
Last updated on