Sqlite3-pragma

From 탱이의 잡동사니
Jump to navigation Jump to search

Overvew

Sqlite3 pragma 내용 정리

List

전체 Pragma 목록

application_id
auto_vacuum
automatic_index
busy_timeout
cache_size
cache_spill
case_sensitive_like
cell_size_check
checkpoint_fullfsync
collation_list
compile_options
count_changes
data_store_directory
data_version
database_list
default_cache_size
defer_foreign_keys
empty_result_callbacks
encoding
foreign_key_check
foreign_key_list
foreign_keys
freelist_count
full_column_names
fullfsync
ignore_check_constraints
incremental_vacuum
index_info
index_list
index_xinfo
integrity_check
journal_mode
journal_size_limit
legacy_file_format
locking_mode
max_page_count
mmap_size
page_count
page_size
parser_trace
query_only
quick_check
read_uncommitted
recursive_triggers
reverse_unordered_selects
schema_version
secure_delete
short_column_names
shrink_memory
soft_heap_limit
stats
synchronous
table_info
temp_store
temp_store_directory
threads
user_version
vdbe_addoptrace
vdbe_debug
vdbe_listing

application_id

PRAGMA schema.application_id; 
PRAGMA schema.application_id = integer;

The application_id PRAGMA is used to query or set the 32-bit unsigned big-endian "Application ID" integer located at offset 68 into the database header. Applications that use SQLite as their application file-format should set the Application ID integer to a unique integer so that utilities such as file(1) can determine the specific file type rather than just reporting "SQLite3 Database". A list of assigned application IDs can be seen by consulting the magic.txt file in the SQLite source repository.

auto_vacuum

database 의 auto-vacuum option 을 질의/설정한다.

PRAGMA schema.auto_vacuum;
PRAGMA schema.auto_vacuum = 0 | NONE | 1 | FULL | 2 | INCREMENTAL;

sqlite3 컴파일시, SQLITE_DEFAULT_AUTOVACUUM 옵션을 따로 지정하지 않는 한, 기본 설정 값은 0 또는 "NONE"이다.

기본적으로 sqlite3 에서 DELETE 명령을 한다고 해도, 데이터베이스 자체의 파일 사이즈의 크기는 줄어들지 않는다. 이는 단지 DELETE 된 항목을 사용하지 않을 뿐이다. 이를 확실히 지우기 위해서는 VACUUM 명령어를 사용해야 하는데, auto_vacuum pragma 는 auto-vacuum 기능을 설정할 수 있도록 한다.

table_info()

입력된 table 의 정보를 출력한다. 각각의 라인마다 테이블에 있는 모든 칼럼과 속성을 하나씩 출력한다. table 뿐만 아니라 view 정보도 확인할 수 있다. 각각의 항목별 내용은 아래 순서와 같다.

  • Index
  • Column name
  • Data type
  • Set NULL 가능 여부.(0:가능, 1:불가능)
  • Default value
  • Primary key 여부
sqlite> pragma table_info(plan);
0|uuid|varchar(255)|1||1
1|name|varchar(255)|0|null|0

jounal_mode

Sqlite3 DB의 Journal mode 를 설정한다.

Sqlite3 의 Journal mode 에 대한 자세한 설명은 이곳<ref>https://www.sqlite.org/atomiccommit.html</ref>을 참조하도록 한다.

PRAGMA schema.journal_mode; 
PRAGMA schema.journal_mode = DELETE | TRUNCATE | PERSIST | MEMORY | WAL | OFF
  • DELETE(default)
Rollback journal file 을 매번 Create/Delete 한다.
  • TRUNCATE
Rollback journal file 을 매번 Create/Delete 하지 않고, 파일 사이즈만을 0으로 설정 후 재활용 한다.
  • PERSIST
저널링 파일을 지우지 않는다.
  • MEMORY
저널링 파일을 메모리에서 유지한다. Sqlite3 를 사용하는 어플리케이션에서 장애시 데이터는 유실된다.
  • WAL
쓰기 요청이 들어오면 변경사항을 먼저 WAL-log 에 기록한다. 이후 일괄적으로 데이터에 반영한다.
  • OFF
데이터 파일에 직접 기록한다. 문제 발생시 데이터 복원이 불가하다.

WAL(Write Ahead to Log)

원문은 이곳<ref>https://www.sqlite.org/wal.html</ref>에서 확인할 수 있다.

쓰기 요청이 들어오면, 변경 사항을 먼저 WAL-Log 에 기록한다. 그리고 WAL-Log 파일이 1000 Page(Default)가 넘게되면, 일괄 데이터에 반영한다.

Reference

<references/>