permuteseq

Pseudo-randomly permute sequences with a format-preserving encryption on elements

Overview

PackageVersionCategoryLicenseLanguage
permuteseq1.2.2FUNCPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4550permuteseqNoYesNoYesNoYes-
Relatedpg_idkit random sequential_uuids pg_hashids pgx_ulid pg_uuidv7 uuid-ossp

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.2.21817161514permuteseq-
RPMPIGSTY1.2.21817161514permuteseq_$v-
DEBPIGSTY1.2.21817161514postgresql-$v-permuteseq-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
d13.x86_64
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
d13.aarch64
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
u22.x86_64
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
u22.aarch64
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
u24.x86_64
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
u24.aarch64
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2
PIGSTY 1.2.2

Build

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

pig build pkg permuteseq         # build RPM / DEB packages

Install

You can install permuteseq 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 permuteseq;          # Install for current active PG version
pig ext install -y permuteseq -v 18  # PG 18
pig ext install -y permuteseq -v 17  # PG 17
pig ext install -y permuteseq -v 16  # PG 16
pig ext install -y permuteseq -v 15  # PG 15
pig ext install -y permuteseq -v 14  # PG 14
dnf install -y permuteseq_18       # PG 18
dnf install -y permuteseq_17       # PG 17
dnf install -y permuteseq_16       # PG 16
dnf install -y permuteseq_15       # PG 15
dnf install -y permuteseq_14       # PG 14
apt install -y postgresql-18-permuteseq   # PG 18
apt install -y postgresql-17-permuteseq   # PG 17
apt install -y postgresql-16-permuteseq   # PG 16
apt install -y postgresql-15-permuteseq   # PG 15
apt install -y postgresql-14-permuteseq   # PG 14

Create Extension:

CREATE EXTENSION permuteseq;

Usage

permuteseq: scalable pseudo-random permutations of sequences

Generate unique, non-sequential, random-looking series of numbers without storing previous values. Uses a Feistel cipher with cycle-walking for format-preserving encryption.

CREATE EXTENSION permuteseq;

Functions

FunctionDescription
permute_nextval(seq_oid, crypt_key bigint)Advance sequence and return encrypted value within sequence bounds
reverse_permute(seq_oid, value bigint, crypt_key bigint)Compute original value from its permuted element
range_encrypt_element(clear_val bigint, min_val bigint, max_val bigint, crypt_key bigint)Encrypt a bigint in a given range
range_decrypt_element(crypt_val bigint, min_val bigint, max_val bigint, crypt_key bigint)Decrypt a previously encrypted value

Examples

CREATE SEQUENCE s MINVALUE -10000 MAXVALUE 15000;

-- Generate random-looking unique values from a sequence
SELECT permute_nextval('s'::regclass, 123456789012345)
  FROM generate_series(1, 10);

-- Reverse a permuted value back to the original
SELECT reverse_permute('s'::regclass, -545, 123456789012345);
-- -10000

-- Encrypt/decrypt within an arbitrary range
SELECT range_encrypt_element(91919191919, 1e10::bigint, 1e11::bigint, 123456789012345);
-- 83028080992

SELECT range_decrypt_element(83028080992, 1e10::bigint, 1e11::bigint, 123456789012345);
-- 91919191919

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