인메모리 테이블 / 가속
Oracle
-- Keep the table in memory with Database In-Memory:
ALTER TABLE orders INMEMORY;
-- Memory size (init parameter):
ALTER SYSTEM SET inmemory_size = 4G SCOPE=SPFILE;Oracle Database In-Memory는 자주 조회되는 테이블을 메모리에 컬럼 형식으로 보관해 분석을 가속한다(별도 라이선스). OLTP에서는 Buffer Cache와 KEEP pool도 자주 접근하는 블록을 메모리에 유지한다. 인메모리 솔루션은 디스크의 행 형식을 통해 내구성을 보장한다.
PostgreSQL
-- Fast table without durability (writes no WAL):
CREATE UNLOGGED TABLE temp_calc (id int, data text);
-- Session-private temporary table (tends to stay in memory):
CREATE TEMP TABLE session_data (id int) ON COMMIT DELETE ROWS;PostgreSQL은 전용 인메모리 테이블 엔진을 제공하지 않는다. UNLOGGED 테이블은 WAL 쓰기를 생략해 쓰기 속도를 높인다(크래시 시 내용 손실, 내구성 없음). TEMP 테이블은 세션 동안 유지되며 가능하면 temp_buffers를 통해 메모리에 보관된다. 자주 쓰는 데이터는 shared_buffers에 캐시된다.
MySQL
-- Table using the MEMORY (HEAP) storage engine:
CREATE TABLE cache_table (
id INT PRIMARY KEY,
data VARCHAR(100)
) ENGINE=MEMORY;MySQL MEMORY(이전 HEAP) 스토리지 엔진은 테이블 데이터를 전부 RAM에 보관한다. 매우 빠르지만 서버를 재시작하면 데이터가 사라진다(구조는 유지됨). BLOB/TEXT를 지원하지 않으며 고정 행 크기를 사용한다. 내구성이 필요한 자주 쓰는 데이터에는 InnoDB buffer pool이 권장된다.
SQL Server
-- In-Memory OLTP: memory-optimized table
CREATE TABLE dbo.session_state (
id INT NOT NULL PRIMARY KEY NONCLUSTERED,
data NVARCHAR(100)
) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA);SQL Server In-Memory OLTP(Hekaton)는 memory-optimized 테이블(MEMORY_OPTIMIZED=ON)과 latch-free 구조로 높은 동시성의 OLTP를 제공한다. DURABILITY=SCHEMA_AND_DATA는 데이터의 내구성을 유지하고, SCHEMA_ONLY는 스키마만 보존한다. memory-optimized 파일 그룹이 필요하다.
MongoDB
-- Hot data is kept in the WiredTiger cache automatically.
-- Set the cache size (default ~50% of RAM):
// mongod --wiredTigerCacheSizeGB 8
// or in the configuration: storage.wiredTiger.engineConfig.cacheSizeGBMongoDB에는 별도의 인메모리 테이블 유형이 없다(기존 In-Memory Storage Engine은 Enterprise 전용이었으며 deprecated됨). 기본 WiredTiger 엔진은 자주 접근하는 데이터와 인덱스를 메모리 캐시에 유지해 읽기 속도를 높이며, OS 파일 캐시도 기여한다.
Redis
# Redis already runs entirely in memory; nothing extra is needed.
# Persistence and memory policy settings:
CONFIG SET maxmemory 4gb
CONFIG SET maxmemory-policy allkeys-lruRedis는 모든 데이터를 RAM에 보관하며, 이것이 설계상 속도의 원천이다. 영속성은 RDB(스냅샷) 및/또는 AOF(명령 로그)로 제공한다. maxmemory 한도와 eviction 정책(LRU/LFU/random)이 메모리가 가득 찼을 때의 동작을 결정한다.
Elasticsearch
-- Not applicable: there is no fully in-memory table mode.
# Place hot data on fast nodes with a hot/cold architecture:
PUT sale/_settings
{ "index.routing.allocation.require.data": "hot" }Elasticsearch는 데이터를 디스크(Lucene 세그먼트)에 저장하며 전용 인메모리 테이블 엔진을 제공하지 않는다. 속도는 OS 파일 캐시(page cache), doc_values, hot-warm-cold 아키텍처에 의존한다. 충분한 RAM과 heap 설정이 성능에 매우 중요하다.