PostgreSQL UUIDv7 생성

PostgreSQL UUIDv7 generation

PostgreSQL 18의 uuidv7()은 시간순 UUID를 생성합니다.

···
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은 시간 정보를 앞부분에 둬 생성 시각 기준으로 대체로 정렬됩니다. PostgreSQL 18은 이를 만드는 uuidv7() 함수를 제공합니다.

데모는 새 키가 인덱스 잎의 중간 또는 끝에 삽입되는 위치를 비교합니다. 시간순 특성이 모든 쓰기에서 성능 향상을 보장하지는 않으며, ID에서 생성 시각 정보가 드러날 수 있다는 점도 고려합니다.

언제 쓰나

분산 환경의 고유 ID가 필요하고 생성 순서가 인덱스 지역성에 도움이 될 때 검토합니다.

페이지로 열기 ↗