PostgreSQL UUIDv7 generation

PostgreSQL UUIDv7 생성

PostgreSQL 18 uuidv7() generates timestamp-ordered UUIDs.

···
html
<div class="demo"><div class="head"><b>INDEX LEAF INSERT</b><span id="uuidmode">UUIDv7</span></div><div class="stage uuid"><div class="leaf"><span>random</span><div class="slots"><i>1</i><i>2</i><i>3</i><i>4</i></div></div><div class="leaf"><span>UUIDv7</span><div class="slots"><i>1</i><i>2</i><i>3</i><i>4</i></div></div></div><div class="foot"><span id="uuidstatus">new key at the end</span><span>illustrative slots</span></div></div>
css
*{box-sizing:border-box}.demo{width:min(96vw,820px);height:min(94vh,350px);padding:clamp(8px,2vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--fg);display:flex;flex-direction:column;gap:clamp(5px,1.5vmin,12px);font:600 clamp(12px,3.5vmin,15px)/1.25 var(--font-sans),sans-serif;overflow:hidden}.head,.foot,.row{display:flex;justify-content:space-between;align-items:center;gap:8px}.head b{color:var(--accent)}.head span,.foot,.muted{color:var(--muted)}.stage{flex:1;min-height:0;display:flex;align-items:center;justify-content:center;gap:8px}.cell,.pill{border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:clamp(4px,1.2vmin,9px);text-align:center}.pill{border-radius:999px}.on{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 17%,var(--surface))!important;color:var(--fg)!important}.bad{border-color:#e16a5d!important;background:color-mix(in srgb,#e16a5d 18%,var(--surface))!important}.foot{font-size:clamp(12px,3vmin,14px)}.uuid{flex-direction:column;align-items:stretch;justify-content:center}.leaf{display:grid;grid-template-columns:70px 1fr;gap:7px;align-items:center}.slots{display:flex;gap:5px}.slots i{font:700 clamp(14px,4vmin,20px) ui-monospace,monospace;font-style:normal;flex:1;text-align:center;padding:5px;border:1px solid var(--line);border-radius:5px;background:var(--bg)}.leaf.on:first-child .slots i:nth-child(2),.leaf.on:last-child .slots i:last-child{background:color-mix(in srgb,var(--accent) 17%,var(--surface));border-color:var(--accent)}
js
let n=0;function tick(){document.querySelectorAll('.leaf').forEach((e,i)=>e.classList.toggle('on',i===n));document.getElementById('uuidmode').textContent=n?'UUIDv7':'random UUID';document.getElementById('uuidstatus').textContent=n?'new key at the end':'new key between old keys';n=1-n}tick();const t=setInterval(tick,1200);document.querySelector('.demo').onclick=()=>{clearInterval(t);tick()}

UUIDv7 places time information near the start, making generated values broadly time ordered. PostgreSQL 18 provides uuidv7() to create them.

The demo contrasts a new key inserted within an index leaf with one added at the end. This does not guarantee faster writes for every workload, and the identifier exposes timing information.

When to use

Consider it when distributed unique IDs are needed and insertion order may help index locality.

Open as page ↗