brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: PRAGMA integrity_check tells you whether a SQLite database file is damaged

Database
~/tips/tip-database-sqlite-pragma-integrity-check

sqlite3 app.db "PRAGMA integrity_check;"

Verifies the structure of a SQLite file and reports damage or broken foreign keys.

Corruption in a SQLite file often stays unnoticed until the one query that hits it. A one-line check finds it earlier.

sqlite3 app.db "PRAGMA integrity_check;"
sqlite3 app.db "PRAGMA foreign_key_check;"

A healthy database prints a single line, ok. Anything else is a list of problems, one per line. PRAGMA quick_check skips some of the slower checks and is fine for a daily cron job on a large file.

integrity_check looks at the file structure and index contents. It does not verify foreign keys, which is what foreign_key_check is for, and it prints rows only for violations.

Further reading: SQLite: PRAGMA Statements

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link