pg_slug_gen
生成带时间戳的加密安全短标识
仓库
nandoolle/pg_slug_gen
https://github.com/nandoolle/pg_slug_gen
源码
pg_slug_gen-1.0.0.tar.gz
pg_slug_gen-1.0.0.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pg_slug_gen | 1.0.0 | FUNC | MIT | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 4550 | pg_slug_gen | 否 | 是 | 否 | 是 | 否 | 是 | - |
| 相关扩展 | pg_hashids sequential_uuids uuid-ossp pg_uuidv7 |
|---|
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0.0 | 1817161514 | pg_slug_gen | - |
| RPM | PIGSTY | 1.0.0 | 1817161514 | pg_slug_gen_$v | - |
| DEB | PIGSTY | 1.0.0 | 1817161514 | postgresql-$v-pg-slug-gen | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0.0 el8.x86_64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY MISS |
| el8.aarch64 | PIGSTY 1.0.0 el8.aarch64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY MISS |
| el9.x86_64 | PIGSTY 1.0.0 el9.x86_64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY MISS |
| el9.aarch64 | PIGSTY 1.0.0 el9.aarch64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY MISS |
| el10.x86_64 | PIGSTY 1.0.0 el10.x86_64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY MISS |
| el10.aarch64 | PIGSTY 1.0.0 el10.aarch64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY MISS |
| d12.x86_64 | PIGSTY 1.0.0 d12.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~bookworm_amd64.deb
| PIGSTY MISS |
| d12.aarch64 | PIGSTY 1.0.0 d12.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~bookworm_arm64.deb
| PIGSTY MISS |
| d13.x86_64 | PIGSTY 1.0.0 d13.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~trixie_amd64.deb
| PIGSTY MISS |
| d13.aarch64 | PIGSTY 1.0.0 d13.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~trixie_arm64.deb
| PIGSTY MISS |
| u22.x86_64 | PIGSTY 1.0.0 u22.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~jammy_amd64.deb
| PIGSTY MISS |
| u22.aarch64 | PIGSTY 1.0.0 u22.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~jammy_arm64.deb
| PIGSTY MISS |
| u24.x86_64 | PIGSTY 1.0.0 u24.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~noble_amd64.deb
| PIGSTY MISS |
| u24.aarch64 | PIGSTY 1.0.0 u24.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~noble_arm64.deb
| PIGSTY MISS |
| u26.x86_64 | PIGSTY 1.0.0 u26.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~resolute_amd64.deb
| PIGSTY 1.0.0 u26.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~resolute_amd64.deb
| PIGSTY 1.0.0 u26.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~resolute_amd64.deb
| PIGSTY 1.0.0 u26.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~resolute_amd64.deb
| PIGSTY MISS |
| u26.aarch64 | PIGSTY 1.0.0 u26.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~resolute_arm64.deb
| PIGSTY 1.0.0 u26.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~resolute_arm64.deb
| PIGSTY 1.0.0 u26.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~resolute_arm64.deb
| PIGSTY 1.0.0 u26.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~resolute_arm64.deb
| PIGSTY MISS |
构建
您可以使用 pig build 命令构建 pg_slug_gen 扩展的 RPM / DEB 包:
pig build pkg pg_slug_gen # 构建 RPM / DEB 包
安装
您可以直接安装 pg_slug_gen 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install pg_slug_gen; # 当前活跃 PG 版本安装
pig ext install -y pg_slug_gen -v 18 # PG 18
pig ext install -y pg_slug_gen -v 17 # PG 17
pig ext install -y pg_slug_gen -v 16 # PG 16
pig ext install -y pg_slug_gen -v 15 # PG 15
dnf install -y pg_slug_gen_18 # PG 18
dnf install -y pg_slug_gen_17 # PG 17
dnf install -y pg_slug_gen_16 # PG 16
dnf install -y pg_slug_gen_15 # PG 15
apt install -y postgresql-18-pg-slug-gen # PG 18
apt install -y postgresql-17-pg-slug-gen # PG 17
apt install -y postgresql-16-pg-slug-gen # PG 16
apt install -y postgresql-15-pg-slug-gen # PG 15
创建扩展:
CREATE EXTENSION pg_slug_gen;
用法
来源:repo README, official PGXN release page, official release README, official release SQL, official release metadata
pg_slug_gen 使用加密随机性生成基于时间戳的 slug。官方 1.0.0 release 将它描述为安全、URL-friendly 的短 ID 生成器,请求长度决定时间戳精度。
CREATE EXTENSION pg_slug_gen;
SELECT gen_random_slug();
SELECT gen_random_slug(13);
函数
gen_random_slug(slug_length int DEFAULT 16) returns text
release SQL comment 和 README 记录了这些支持值:
10:秒13:毫秒16:微秒,也是默认值19:纳秒
精度与格式
每种精度对应一种时间戳宽度和固定 slug 形状:
10digits:5-5格式,总长 11 个字符13digits:6-7格式,总长 14 个字符16digits:8-8格式,总长 17 个字符19digits:9-10格式,总长 20 个字符
README 说明无冲突窗口受时间戳精度限制:每秒、每毫秒、每微秒或每纳秒最多 1 次插入。
示例
SELECT gen_random_slug();
SELECT gen_random_slug(10);
SELECT gen_random_slug(16);
CREATE TABLE products (
id serial PRIMARY KEY,
name text NOT NULL,
slug text DEFAULT gen_random_slug() UNIQUE
);
工作方式
官方 README 描述的算法如下:
- 以所选精度获取当前时间戳
- 将每个数字映射到一个基于 QWERTY 的字符桶
- 使用
pg_strong_random()从该桶中随机选择一个字符 - 在中点插入连字符
注意事项
- 这是安全短 ID 生成器,不是文本音译或标题转 URL slugifier。
- 相同时间戳下仍可能冲突;上游只声称在插入量不超过所选时间单位每单位一次时保持唯一。
- catalog URL 是当前
https://github.com/nandoolle/pg_slug_gen仓库;PGXN release metadata 仍指向较旧的fernandoolleGitHub URL。 - curated package matrix 面向 PostgreSQL 15 到 18,而 PGXN metadata 只声明最低 PostgreSQL 版本。包可用性请以 catalog matrix 为准。