• 검색 결과가 없습니다.

PostgreSQL Architecture 정리

N/A
N/A
Protected

Academic year: 2022

Share "PostgreSQL Architecture 정리"

Copied!
25
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

PostgreSQL

Architecture 정리

(2)

참고 : Oracle Architecture

(3)

참고 : SQL Server Architecture

(4)

PostgreSQL Architecure

Client Interface

Library (Libpg) Client Application

Client Pro- cesses Client Pro- cesses

Postgres In- stance

Server Pro- cesses Server Pro- cesses

Postmaster (Daemon/Listener)

Postgres Server (backend) Postgres

Server (backend) Postgres

Server (backend)

System Mem- ory

System Mem- ory

DB Re- quests and Re- sults via Li- brary API

SQL Queries and Re- sults

Initial Connection Request and Authentica- tion

Spawn Server Processes

PG Shared Memory

Shared Buffer WAL Buffer CLOG Buffer

Lock Space Other Buffers

Per Backend Memory Per Backend Memory Per Backend Memory

• maintenace_

work_mem

• temp_buffer

• work_mem

• catalog_cache

• optimizer/executor

OS Cache Cre-

ate

Read/

Write

Utility Process Utility Process

BG

Writer WAL

Writer Archiver

SYS Logger Stats

Collector

Auto Vaccum

WAL Sender

WAL Receiver

Indepen- dent Attached to

PG Shared Mem- ory

Storage Man- ager

Storage Man- ager

Buffer

Manager Lock

Manager File

Manager

Database Cluster Database Cluster

(5)

Client Processes

Client Interface

Library (Libpg) Client Application

Client Pro- cesses Client Pro- cesses

DB Re- quests and Re- sults via Li- brary API

<Client Application & Client Interface Library>

• Client Application이 Client Interface Library 를 통해 Server 와 통신 .

• Client Interface Library는 Server 가 명령을 이해하고 Parsing 할 수 명령어를 SQL 로 바꿈 .

(6)

Postmaster

Server Pro- cesses Server Pro- cesses

Postmaster (Daemon/Listener)

Postgres Server (backend) Postgres

Server (backend) Postgres

Server (backend)

Spawn Server Processes

<Postmaster>

• 항상 수행되는 데몬 쓰레드 .

• DB에 대한 모든 요청 (Call) 을 Listen하기 위한 암시적 호출 (Implicit Invocationi) 아키텍처로 사용 (Wait for client requst).

• 요청 (Call) 수신시 Back-end process 를 생성하여 Call 에 1:1 로 대응시킴 .

• Postmaster가 Call 과 Postgres 를 연결하면 더이상 Postmaster 와 통신할 필요 없음 .

• 5444(PPAS), 5432(PGS)

Client Apps

postmas- ter

shared memory

archiver bgwriter stats

Wait for client re- quest

(7)

Postgres Server

Server Pro- cesses Server Pro- cesses

Postmaster (Daemon/Listener)

Postgres Server (backend) Postgres

Server (backend) Postgres

Server (backend)

Spawn Server Processes

<Postgres Server>

• Postgres는 Hybrid pipe & Filter architecure 방식 .

• 각 Component 는 Catalog, Rule, Table 의 공유 Repository 를 참조 .

• SQL Query를 전달받고 결과적으로 Result Data 로 변환 .

• Storage Manager와 Utilities 사용

Client Apps

postmas- ter

shared memory

archiver bgwriter stats

post- mater

work mem

Authentication Call back to client

Wait for SQL

(8)

SQL Process Step

Parser Traffic Cop Rewriter Planner/Optimizer Executor

Symbol Tables, Data Tables, Libraries and so on. (Shared Repository)

Simple Query commands Complex Query Commands

Client Input(SQL) Data Rows/Output

Post- gres Server

<Pipe & filter Architecture>

• Parser(syntax)

- ASCII로 전달 받아 Query String 파싱 .

- 키워드 , 식별자 인지를 위해 Pattern Matching.

- ParseTree 생성 , SQL Syntax 체크 .

• Traffic Cop(syntax/complex)

- Simple Command를 Executor 에 전달 .

- Complex Command는 Planner/Optimizer 에 전달 .

• Rewirter(rule argument)

- 전달된 ParseTreedml 의 lower order 명령어로 재작성

• Planner/Optimizer(optimal plan)

- 최적의 쿼리 플랜 결정 , Tree 형태의 플랜 생성 .

• Executor(execute optimal plan) - 실행계획을 수행하여 Data 추출 . - Client에 결과 반환 .

Postgres Server (backend) Postgres

Server (backend) Postgres

Server (backend)

Object

Definitions Rule/View

Definitions Statistics User

Data

(9)

System Memory

System Mem- ory

System Mem- oryPG Shared Memory

Shared Buffer WAL Buffer CLOG Buffer

Lock Space Other Buffers

Per Backend Memory Per Backend Memory Per Backend Memory

• maintenace_

work_mem

• temp_buffer

• work_mem

• catalog_cache

• optimizer/executor

OS Cache

<System Memory>

• http://www.postgresql.org/docs/9.2/interactive/runtime-config-resource.html

• Shared Memory는 매우 크고 모든 Buffer 는 동기화되지 않음 .

• Shared Buffer

- PostgreSQL 서버가 사용하는 공유 메모리 버퍼 .

• temp_buffer

- 각각의 세션이 사용하는 임시 버퍼 .

• work_mem

- 임시 디스크 파일에 쓰기 전에 내부 정렬 및 해시 테이블 조작에 사용되는 메모리 .

• maintenace_work_mem

- VACUUM, CREATE INDEX, ALTER TABLE ADD FOREIGN KEY등 유지 관리에 사용되는 메모 리 .

(10)

Shared Buffer

System Mem- ory

System Mem- oryPG Shared Memory

Shared Buffer WAL Buffer CLOG Buffer

Lock Space Other Buffers

Per Backend Memory Per Backend Memory Per Backend Memory

• maintenace_

work_mem

• temp_buffer

• work_mem

• catalog_cache

• optimizer/executor

OS Cache

Disk Read Buffering

• On shred buffer

• One read I/O

• Manu logical read from buffer chache

Client

Apps postmater

shared memory postmater

work

mem postmater

work

mem postmater

work mem

Shared Buffer Log Buffer

Database Files

WAL Files

(11)

Internal Shared Buffer

(12)

bgwirter

BGWriter

Utility Process Utility Process

BG

Writer WAL

Writer Archiver

SYS Logger Stats

Collector Auto Vaccum

WAL Sender

WAL Receiver

Client

Apps postmater

shared memory postmater

work

mem postmater

work

mem postmater

work mem

Shared Buffer Log Buffer

Database Files

WAL Files

checkpoint commit

• 버퍼 쓰기

• 체크포인트 발생

Shared Buffer -> Data Files

• 커밋 발생

Log Buffer -> WAL Files

• WAL

- Write Ahead Log - 트랜잭션 변경 기록

- segment = 16MB(default) checkpoint_segment = 3(default)

checkpoint_timeout = 300초

(13)

bgwirter

Archiver

Utility Process Utility Process

BG

Writer WAL

Writer Archiver

SYS Logger Stats

Collector Auto Vaccum

WAL Sender

WAL Receiver

Client

Apps postmater

shared memory postmater

work

mem postmater

work

mem postmater

work mem

Shared Buffer Log Buffer

• WAL 로그 아카이브

• default = OFF

archiv er

(14)

bgwirter

Archiver

Utility Process Utility Process

BG

Writer WAL

Writer Archiver

SYS Logger Stats

Collector Auto Vaccum

WAL Sender

WAL Receiver

Client

Apps postmater

shared memory postmater

work

mem postmater

work

mem postmater

work mem

Shared Buffer Log Buffer

Database Files

WAL Files

• Statistics 정보 수집

테이블 엑세스 정보

인덱스 액세스 정보

현재 실행 쿼리 정보

버퍼 캐시 상태 정보

Archive Files archive

r stats

(15)

Storage Manager

Storage Man- ager

Storage Man- ager

Buffer Manager

Lock Manager

File Manager

Semaphore &

Shared Memory Page

Manager Disk

Manager

<Storage Manager>

• 버퍼에 공유메모리를 제공하고 DB 를 Access 함 .

(16)

Database Cluster

Database Cluster Database Cluster

Sub Direc- tory

Config- ure File

Lock File

• Collection of databases

• Managed by Single server instance(Postmaster)

• Cluster 구조 - 데이터 디렉토리

- shared catalog tables - port

• 클러스터 생성 - directory 생성 - initdb –D /data2

- port 변경 (5432->5445)

(17)

Data Directory

Database Cluster Database Cluster

Sub Direc- tory

Config- ure File

Lock File

(18)

16931 -> /Databases/ts_data1 68656 -> /Databases/ts_data2

∙∙∙

Tablespace

Database Cluster Database Cluster

Sub Direc- tory

Config- ure File

Lock File

$POSTGRES_HOME

(/home/postgres/pgsql) data base 1 (template1)

12865 (template0)

12870 (postgres) 12607 12613 12621 12636

∙∙∙

pg_tblspc

• database 위치

select oid, dataname from pg_database;

• ts_data1 테이블 스페이스 위치

select oid, spcname from pg_tablespace;

(19)

12870

16931 -> /Databases/ts_data1

Table

Database Cluster Database Cluster

Sub Direc- tory

Config- ure File

Lock File

$POSTGRES_HOME

(/home/postgres/pgsql) data base

pg_tblspc

PG_9.2_201204301

77869

• ttt 테이블 정보

select oid, relname, reltablespace, relfilenode

from pg_class where relkind = ‘r’

and relname = ‘ttt’;

(20)

Data File

Database Cluster Database Cluster

Sub Direc- tory

Config- ure File

Lock File

• database는 하나의 디렉토리를 가짐

- /postgres/pgsql/data/base/1 -- template1 - /postgres/pgsql/data/base/12870 -- postgres

• 테이블은 하나의 파일에 저장됨

- /postgres/pgsql/data/pg_tblspc/16931/12870/77869 -- ttt 테이블 - 파일 최대 크기 : 1GB

- 테이블 크기가 늘어나면 파일이 split 됨 (32TB 까지 , TOAST) - 77869 (1GB)

77869.1 (1GB) 77869.2 (1GB)

(21)

기타 Files

Database Cluster Database Cluster

Sub Direc- tory

Config- ure File

Lock File

• PG_VERSION : PostgreSQL의 주요 버전 번호를 보유하는 파일 .

• base : 데이터베이스마다 하위 디렉토리를 보유 .

           각 데이터베이스의 디렉토리 생성 . 각 디렉토리에는 테이블과 인덱스 파일 생성 .            pg_default 테이블스페이스 경로 . 

• global : pg_database 같은 클러스터에서 공유 테이블을 보유 .        모든 데이터베이스에서 공유하는 서버 카탈로그 테이블 존재 .        pg_global 테이블스페이스 경로 . 

• pg_multixact : 멀티 트랜잭션의 상태 데이터를 보유 .        공유 행 잠금에서 사용 . 

       저수준 (Row-level) 의 락 (Lock) 상태 파일들이 존재 .

• pg_notify : LISTEN/NOTIFY 상태 데이터를 보유 .

• pg_serial : 커밋된 serializable 트랜잭션에 대한 정보를 보유 .

• pg_snapshots : 내보내기 된 스냅샷을 보유 .

• DATA Directory

• $POSTGRES/data/* = $PGDATA 파일 정의

(22)

기타 Files(cont.)

Database Cluster Database Cluster

Sub Direc- tory

Config- ure File

Lock File

• pg_subtrans : 서브 트랜잭션의 상태 데이터를 보유 .

      서브트랜잭션 (Subtransaction) 상태 파일들이 존재 .

• pg_tblspc : 테이블스페이스에 대한 심볼릭 링크를 보유 .

• pg_towpahse : 준비된 트랜잭션에 대한 상태 파일을 보유 .         2단계 커밋 또는 준비된 트랜잭션 상태 존재 .

• pg_xlog : WAL(로그 선행 기입 ) 파일을 보유 .

        트랜잭션 로그 (또는 Write Ahead Log - WAL)들이 존재 .

• pg_clog : 트랜잭션의 커밋 상태의 데이터를 보유 .        트랜잭션 (Transaction) 상태 파일들이 존재 .

• postmaster.opt : 마지막으로 서버를 시작할 때 명령 줄 옵션을 기록 .           이 파일의 내용이 status 모드로 표시됨 .

• postmaster.pid : 데이터디렉토리에 이 파일이 있는지 여부에 따라 pg_ctl 는 서버가 현재 실행 중인지 여부 결정 .

       서비스가 stop되면 이 파일이 존재하지 않음 .

• DATA Directory

• $POSTGRES/data/* = $PGDATA 파일 정의

(23)

Internal Block

(24)

Database Size Limitations

• 데이터베이스 용량 제약

• 데이터베이스 개체 이름

• 스토리지 개체 이름

(25)

Q & A

참조

관련 문서

LoRa® Network Server – Open Source... LoRa® Network Server

Market 참여자는 데이터 거래를 위한 AMO Blockchain Client 또는 AMO Wallet 3 으로 블록체인과 연결된다.. 자동차 사용자가 생성한 CAR DATA와 서비스

VMware Server Console: Edit virtual machine settings 를 클릭합니다.. Virtual Machine Settings: Add

(Attached to a noun) This is used to indicate the topics, to compare two information or to emphasize the preceding noun in a sentence.. (Attached to a noun) This is used

짝과 같이 말하기 연습을 하도록 하고 교사는 교실을 돌아다니면서 말하기 활동이 제대로 이루어지고 있 는지 확인하고 도움을 준다.. 평소에 누구하고 무엇을 하는지

(Attached to a verb) This is used to show that the succeeding action takes place right after the preceding action.. (Attached to a verb) This is used to indicate a

(Attached to a verb or an adjective) This is used to indicate a succeeding action or situation. This is used

(Attached to a verb or an adjective) This is used to reflect on a past situation. (Attached to an adjective) This is used to show another