ITstudy

PostgreSQL UUID uuid-ossp ์‚ฌ์šฉ๋ฒ•

martinooo 2024. 8. 27. 14:03

PostgreSQL UUID

 

 

 

 

๐Ÿคท‍โ™‚๏ธ UUID ๊ฐœ๋…


UUID(Universally Unique Identifier)๋Š” ์ „ ์„ธ๊ณ„์—์„œ ๊ณ ์œ ํ•œ ์‹๋ณ„์ž๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ‘œ์ค€ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

๊ณ ์œ ํ•œ ์‹๋ณ„์ž๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ UUID ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ™œ์šฉํ•œ ๊ฒฝํ—˜๋“ค์ด ์žˆ์œผ์‹ค๊ฒ๋‹ˆ๋‹ค.

 

PostgreSQL์—์„œ๋„ UUID ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ณ ์œ ํ•œ ์‹๋ณ„์ž๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

PostgreSQL ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ์ด์œ ?

https://itibiza.tistory.com/entry/%EA%B0%80%EC%9E%A5-%ED%95%AB%ED%95%9C-DB-postgresql-%EA%B0%9C%EB%85%90%EA%B3%BC-%EC%82%AC%EC%9A%A9%ED%95%B4%EC%95%BC-%ED%95%98%EB%8A%94-%EC%9D%B4%EC%9C%A0

 

๊ฐ€์žฅ ํ•ซํ•œ DB postgresql ๊ฐœ๋…๊ณผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ์ด์œ 

์•ˆ๋…•ํ•˜์„ธ์š”! ITibiza์ž…๋‹ˆ๋‹ค. ์š”์ฆ˜ ๋งŽ์€ ๊ธฐ์—…์—์„œ ์‚ฌ์šฉํ•˜๋Š” RDBMS postgresql์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์„œ๋น„์Šค๊ฐ€ ์ปค์ง€๋ฉด ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ๊ด€๋ฆฌ์™€ ๋ณต์žกํ•œ ์ฟผ๋ฆฌ ์ฒ˜๋ฆฌ๋Š” ํ•„์ˆ˜์ ์œผ๋กœ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.์•„๋งˆ๋„ ์ด

itibiza.tistory.com

 

 

 

๐Ÿคท‍โ™‚๏ธ uuid-ossp ๊ฐœ๋…


PostgreSQL์—์„œ UUID๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ œ๊ณตํ•˜๋Š” ํ™•์žฅ(Extension) ํ”„๋กœ๊ทธ๋žจ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

uuid-ossp ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ์€ ์—ฌ๋Ÿฌ ๋ฒ„์ „์˜ UUID๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

 

PostgreSQL uuid-ossp ๊ณต์‹ ๋ฌธ์„œ

https://www.postgresql.org/docs/current/uuid-ossp.html

 

F.49. uuid-ossp — a UUID generator

F.49. uuid-ossp — a UUID generator # F.49.1. uuid-ossp Functions F.49.2. Building uuid-ossp F.49.3. Author The uuid-ossp module provides functions to …

www.postgresql.org

 

๐Ÿคท‍โ™‚๏ธ uuid-ossp ์„ค์น˜ ๋ฐ ์‚ฌ์šฉ๋ฒ•


uuid-ossp ํ™•์žฅ ์„ค์น˜

PostgreSQL์—์„œ uuid-ossp ํ™•์žฅ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋จผ์ € ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์„ค์น˜๋ฅผ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

 

์ด ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด uuid-ossp ํ™•์žฅ์ด ์„ค์น˜๋ฉ๋‹ˆ๋‹ค. 

 

uuid-ossp ๋ฒ„์ „ 

  • uuid_generate_v1(): ํ•˜๋“œ์›จ์–ด ์ฃผ์†Œ(MAC ์ฃผ์†Œ)์™€ ํ˜„์žฌ ์‹œ๊ฐ„์„ ๊ธฐ๋ฐ˜์œผ๋กœ UUID๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  • uuid_generate_v4(): ์ž„์˜์˜ ๋‚œ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ UUID๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ๋ฒ„์ „์ž…๋‹ˆ๋‹ค.
  • uuid_generate_v3(namespace UUID, name text): MD5 ํ•ด์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•ด UUID๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  • uuid_generate_v5(namespace UUID, name text): SHA-1 ํ•ด์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•ด UUID๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

์‚ฌ์šฉ ์˜ˆ์‹œ

SELECT uuid_generate_v4();

 

์ด ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด uuid๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

550e8400-e29b-41d4-a716-446655440000

 

์ž„์˜์˜ ๋‚œ์ˆ˜์— ๊ฐ’์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

 

ํ…Œ์ด๋ธ”์— UUID ์‚ฌ์šฉ๋ฒ•

CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    name VARCHAR(100),
    email VARCHAR(100)
);

 

 

ํ…Œ์ด๋ธ”์— ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ์‚ฌ์šฉ๋ฒ•

INSERT into main."users" ("id", "name", "email")
VALUES
  (uuid_generate_v4(), "hello", "123@gmail.com")

 

์ด ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ id ์ปฌ๋Ÿผ์— ๊ณ ์œ ํ•œ key ๊ฐ’์„ ์ž๋™์œผ๋กœ UUID ๊ฐ’์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

 

uuid-ossp ํ™•์žฅ์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 

  1. ๊ณ ์œ ์„ฑ ๋ณด์žฅ: ์ „ ์„ธ๊ณ„์—์„œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” ๊ณ ์œ ํ•œ ์‹๋ณ„์ž๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. ๋ถ„์‚ฐ ์‹œ์Šคํ…œ์— ์ ํ•ฉ: ์ค‘์•™ ์ง‘์ค‘์‹ ์„œ๋ฒ„ ์—†์ด๋„ ๊ณ ์œ ํ•œ ์‹๋ณ„์ž๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ์—ฌ๋Ÿฌ ์„œ๋ฒ„์—์„œ ๋…๋ฆฝ์ ์œผ๋กœ UUID๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
  3. ๋ณด์•ˆ: UUID๋Š” ์˜ˆ์ธกํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋ณด์•ˆ์ด ํ•„์š”ํ•œ ์ƒํ™ฉ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ ์ ํ•ฉํ•ฉ๋‹ˆ๋‹ค.

 

uuid-ossp ํ™•์žฅ๊ณผ ๊ทธ ์‚ฌ์šฉ๋ฒ•์„ ํ†ตํ•ด PostgreSQL์—์„œ ๊ณ ์œ ํ•œ ์‹๋ณ„์ž๋ฅผ ์†์‰ฝ๊ฒŒ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 


 

์žฌ๋ฐŒ๋Š” ์˜ค๋Š˜์˜ ๋ ๋ณ„ ์šด์„ธ ๋ณด๊ณ  ๊ฐ€์„ธ์š”! 

 

 

https://wtemplate.qshop.ai/

 

wtemplate

์„ฑ๊ณต์ ์ธ ์˜จ๋ผ์ธ ๋น„์ฆˆ๋‹ˆ์Šค๋ฅผ ์œ„ํ•œ ์ฒซ๊ฑธ์Œ, ์ „๋ฌธ ๋žœ๋”ฉ ํŽ˜์ด์ง€ ์ œ์ž‘, SEO ๊ตฌ๊ธ€ GA ์ „ํ™˜ ,ํŠธ๋ฆฌ๊ฑฐ, ์• ๋„๋ฆฌ์Šคํ‹ฑ ์…‹ํŒ…

wtemplate.qshop.ai

 

 

https://cometruedream.tistory.com/243

 

NestJS Lifecycle (์ƒ๋ช…์ฃผ๊ธฐ) ๊ฐœ๋…

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ Nest JS ๊ฐœ๋…?Nest JS๋Š” Node JS ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋ ˆ์ž„์›Œํฌ ์ž…๋‹ˆ๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์ƒ๋‹นํžˆ ์˜ค๋žซ๋™์•ˆ Express ๊ธฐ๋ฐ˜์œผ๋กœ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์—์„œ ์••๋„์ ์ธ ์ 

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/242

 

๋ฆฌ์•กํŠธ Vite Proxy ํ™œ์šฉํ•œ CORS ์˜ค๋ฅ˜ ํ•ด๊ฒฐ

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋ก ํŠธ์—”๋“œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ต์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€๋ฅผ ํ•˜๊ณ  ๊ธ€์„ ๋ณด์‹œ๋ฉด ๋” ๋งŽ์€ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค^^ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ตhttps://comet

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/241

 

React ํด๋”๊ตฌ์กฐ FSD ๊ธฐ๋Šฅ ๋ถ„ํ™œ ์„ค๊ณ„ ์•„ํ‚คํ…์ฒ˜

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๊ธฐ์— ์•ž์„œ ํด๋” ๊ตฌ์กฐ, ์„ค๊ณ„์— ๋Œ€ํ•œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์€ ์ƒ๋‹นํžˆ ์–ด๋ ต๋‹ค. ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์— React FSD ํด๋”๊ตฌ์กฐ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์„ค๊ณ„ํ•  ์˜ˆ์ •์ด๋ผ์„œ FSD ์•„ํ‚คํ…

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/244

 

์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๋Š” Prisma ๋ช…๋ น์–ด ์ •๋ฆฌ

๐Ÿคท‍โ™‚๏ธ Prisma ๋ช…๋ น์–ด ๋ณธ๋ก ์— ์•ž์„œ Prisma๋ž€?Nest JS ํ”„๋ ˆ์ž„์›Œํฌ์™€ Prisma ORM์„ ํ™œ์šฉํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ Prisma๋Š” Node JS ๊ธฐ๋ฐ˜์— ํ”„๋ ˆ์ž„์›Œํฌ/๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ์ƒํ˜ธ์ž‘์šฉ์ด ์ž˜๋˜๋ฉฐ Prisma + DB ์—ฐ๋™์œผ

cometruedream.tistory.com