SQL - PostgreSQL, Extensions

2026. 4. 6. 13:26·🧩 SQL

PostgreSQL

 

 

✅ 사용 가능한 PostgreSQL의 Extensions 목록 보는 법


SELECT
	*
FROM
	pg_available_extensions;

 

 

✅ Extension 활성화 방법


CREATE EXTENSION hstore;

 

 

✅ hstore


Key, Value 데이터를 저장할 수 있게 해준다.(현재는 JSONB를 많이 사용한다.)

 

CREATE TABLE users (
	user_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
	prefs  hstore
);

INSERT INTO
	users (prefs)
VALUES
	('theme => dark, lang => kr, notifications => off'),
	('theme => light, lang => es, notifications => on, push_notifications => on, email_notifications => off'),
	('theme => dark, lang => it, start_page => dashboard, font-size => large');

SELECT
	user_id,
	prefs -> 'theme',
	prefs -> ARRAY['lang', 'notifications'],
	prefs ? 'font-size' AS has_font_size,
	prefs ?| ARRAY['push_notifications', 'start_page']
FROM
	users;

key와 value를 theme => dark 이런 식으로 줄 수 있다.

 

SELECT
	user_id,
	akeys (prefs),
	avals (prefs),
	EACH (prefs)
FROM
	users;

akeys: all keys, avals: all values, each: prefs의 모든 key와 value를 한 쌍씩 순회하며 보여준다.

 

UPDATE users
SET
	prefs = prefs || hstore (ARRAY['currency', 'cookies_ok'], ARRAY['krw', 'yes']);

SELECT
	*
FROM
	users;

새로운 key, value값을 넣어 기존 값 수정하기

 

UPDATE users
SET
	prefs = DELETE (prefs, 'cookies_ok');
SELECT
	*
FROM
	users;

key값으로 삭제하기

 

https://www.postgresql.org/docs/current/hstore.html

 

F.17. hstore — hstore key/value datatype

F.17. hstore — hstore key/value datatype # F.17.1. hstore External Representation F.17.2. hstore Operators and Functions F.17.3. Indexes F.17.4. Examples F.17.5. …

www.postgresql.org

 

 

✅ pgcrypto


데이터베이스에서 암호화 작업을 실행할 수 있도록 해준다.

CREATE TABLE users (user_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, username VARCHAR(100), password VARCHAR(100));

INSERT INTO
	users (username, PASSWORD)
VALUES
	('nico', crypt ('user_password', gen_salt ('bf'))); -- bf -> BlowFish algorithm

 

SELECT
	username
FROM
	users
WHERE
	PASSWORD = crypt ('user_password', PASSWORD);

해싱된 비밀번호 일치 확인

 

https://www.postgresql.org/docs/current/pgcrypto.html

 

F.26. pgcrypto — cryptographic functions

F.26. pgcrypto — cryptographic functions # F.26.1. General Hashing Functions F.26.2. Password Hashing Functions F.26.3. PGP Encryption Functions F.26.4. Raw Encryption …

www.postgresql.org

 

 

✅ uuid-ossp


데이터베이스에서 uuid를 생성할 수 있도록 해주는 아주 유용한 extension

BIGINT도 꽤 큰 숫자이긴 하지만 한계가 있다.(PostgreSQL에는 unsigned number도 없음)

 

데이터가 너무 많아서 BIGINT로 표현할 수 있는 범위를 넘어간다면 id를 uuid로 변경한다.

(무작위로 생성된 문자열)

 

활성화

CREATE EXTENSION "uuid-ossp";

얘는 무조건 ""로 적어줘야 한다.

 

사용

CREATE TABLE users (user_id UUID PRIMARY KEY DEFAULT (uuid_generate_v4 ()), username VARCHAR(100), password VARCHAR(100));

 

 

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

 

'🧩 SQL' 카테고리의 다른 글

SQL - SQL with Python  (0) 2026.04.13
SQL - SQL Injection  (0) 2026.04.09
SQL - PostgreSQL, JSON Column  (0) 2026.04.06
SQL - PostgreSQL, DCL(Data Control Language)  (0) 2026.04.03
SQL - PostgreSQL, Transaction, Save Point, Isolation Level, Phenomena  (0) 2026.04.02
'🧩 SQL' 카테고리의 다른 글
  • SQL - SQL with Python
  • SQL - SQL Injection
  • SQL - PostgreSQL, JSON Column
  • SQL - PostgreSQL, DCL(Data Control Language)
j2yonghwa
j2yonghwa
Trying to be a fullstack developer 🚀
  • j2yonghwa
    j2yonghwa
    j2yonghwa
  • 전체
    오늘
    어제
    • 분류 전체보기 (156)
      • ⏰ Daily WakaTime (1)
      • 🏖️ 노마드코더 (2)
      • 🍺 Dev Setup (3)
      • 🔭 Tech Info (1)
      • 🚫 Error (1)
      • 📂 라이브러리 (23)
      • ♣️ Next.js 14 (10)
      • ♠️ Next.js 12 (20)
      • 🛸 React Native (12)
      • 🦋 TypeScript (1)
      • 🐍 Python (2)
      • 🌊 TailwindCSS (4)
      • 🧩 SQL (25)
      • 💎 Prisma (5)
      • 🌱 MongoDB (4)
      • 🎯 Redis (1)
      • 🧬 GraphQL (2)
      • 🔥 Firebase (7)
      • 💸 Third-Party Services (2)
      • 🕸️ Web (1)
      • 🏆 코딩테스트 (23)
      • 📙 모딥다 (5)
      • 📗 코테 합격자 되기 -JS- (0)
      • 📘 클린코드 (0)
      • 🍯 꿀팁 🐝 (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 깃헙
  • 공지사항

  • 인기 글

  • 태그

    next.js 14
    Firebase
    라이브러리
    Python
    PostgreSQL
    SQL
    MySQL
    Prisma
    API
    dev setup
    0레벨
    mongoDB
    react router
    React Native
    코딩테스트 입문
    자바스크립트
    Next.js
    모딥다
    tailwindcss
    next.js 12
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
j2yonghwa
SQL - PostgreSQL, Extensions
상단으로

티스토리툴바