SadServers
  • Scenarios
  • Labs
    All Labs Linux & Bash Web Servers Databases Data Processing Docker Kubernetes CI/CD Infrastructure as Code Tooling / Applications
  • Dashboard
  • Solutions
    For Individuals For Businesses
  • Ranking
  • Newsletter
  • Documentation
    FAQ Support Pro Accounts Pro+ Accounts Business Accounts Gift API CLI/TUI Privacy Troubleshooting Interviews
  • Blog
  • Pricing
  • Gift
    Gift Purchase Gift Redeem
  • About
Log In - Sign Up
  1. Labs
  2. SQLite
  3. Cheatsheet

Guide

Concepts and learning path

Troubleshooting

Failure modes and fixes

Cheatsheet

Commands to keep handy

SQLite cheatsheet

sqlite3 CLI

CommandDescription
sqlite3 app.dbOpen database interactively
sqlite3 app.db "SELECT 1"Run single query
.tablesList tables
.schema table_nameShow CREATE statement
.databasesList attached databases
.quitExit

PRAGMA — inspect and tune

PRAGMADescription
PRAGMA journal_mode;Current journal mode (want WAL)
PRAGMA integrity_check;Verify database integrity
PRAGMA foreign_keys;Check if FK enforcement is on
PRAGMA page_count; page_size;Size estimation
PRAGMA wal_checkpoint(TRUNCATE);Checkpoint WAL into main db
PRAGMA quick_check;Faster integrity scan

Production PRAGMA block

PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL; PRAGMA foreign_keys = ON; PRAGMA busy_timeout = 5000; PRAGMA cache_size = -64000;

Backup

CommandDescription
sqlite3 app.db ".backup backup.db"Online consistent backup
sqlite3 app.db "VACUUM INTO 'backup.db';"Copy to new file (vacuumed)
litestream replicate /path/app.dbStream changes to S3 (Litestream)
litestream restore -o app.db s3://bucket/dbRestore from Litestream

File inspection

CommandDescription
ls -la app.db app.db-wal app.db-shmDatabase and WAL sidecars
file app.dbConfirm SQLite format
lsof app.dbWhich processes hold the file open
fuser -v app.dbProcesses using the database file

Useful SQL

SELECT name FROM sqlite_master WHERE type='table'; SELECT COUNT(*) FROM table_name; VACUUM; -- rebuild db, reclaim space (exclusive lock)

Pro tips

  • Enable WAL before production traffic — PRAGMA journal_mode=WAL
  • Never rsync a live database without the backup API or Litestream
  • Set busy_timeout so apps retry instead of failing instantly on lock
  • For server deployments, consider Litestream for continuous off-site backup

Practice scenarios

Hands-on SQLite scenarios on live Linux VMs: sqlite

SadServersSadServers

Real-world Linux and DevOps scenarios for hands-on learning and technical assessment.

Uptime Robot ratio (30 days)
Product
  • Scenarios
  • For Individuals
  • For Businesses
  • Pricing
Resources
  • FAQ
  • Blog
  • Newsletter
Company
  • About Us
  • Support
  • Privacy Policy
  • Terms of Service
  • Contact
Connect With Us
info@sadservers.com

Made in Canada 🇨🇦
Updated: 2026-06-13 16:06 UTC – 2d2950a