> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SQLite The Database on Every Phone

> Explains SQLite as the embedded, zero configuration relational database used on phones, how it stores data, embeds in apps, concurrency and security trade offs, and best practices.

Your phone’s internal databases are not powered by [MySQL](https://www.mysql.com/) or [PostgreSQL](https://www.postgresql.org/). Instead, most mobile apps use an embedded relational database called [SQLite](https://www.sqlite.org/).

SQLite is present on almost every phone (iOS and Android). In this article we’ll explain what SQLite is, how it’s embedded in apps, how it stores data on disk, and the important trade-offs you should know when using it in mobile and embedded environments.

Almost every app on your phone — WhatsApp, Chrome, Spotify, Slack, etc. — needs to persist data locally. For example, WhatsApp keeps your chats on the device. These apps cannot reasonably host a heavyweight client–server DBMS like MySQL or PostgreSQL inside the app process. Instead, each app embeds SQLite directly into its process, giving it a lightweight, full-featured SQL engine without requiring a separate server.

![A stylized diagram showing a smartphone with app icons (messaging, browser, music, Slack) on the left and a large "Database Server" box on the right containing MySQL and PostgreSQL logos. Below the server are CPU, memory, and disk usage bars and many user stick figures connecting into the server, labeled "thousands of users."](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Databases/SQLite-The-Database-on-Every-Phone/mobile-apps-mysql-postgres-server-load.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=a0216cb9108c8a52e21bb5a70b1699f7)

## How SQLite is embedded

SQLite is a compact C library — small enough to be included inside an app (often well under one megabyte when compiled). It is linked into the application process, so using SQLite is just a normal function call from the app; there is no separate database server process. That design gives:

* Zero-configuration deployment: no daemon to install or manage.
* Low memory and binary-size overhead.
* Direct, local file access semantics with POSIX file locking semantics on the underlying filesystem.

## On-disk format: a single-file relational database

On disk, SQLite stores an entire database in a single file (for example, `msgstore.db`). Inside that file are all relational structures — tables, indexes, and schema metadata. The file is organized into fixed-size pages (commonly `4 KiB` each, though the page size can vary), and the file header (located in the first page) describes the file format, page size, and how the database schema is laid out.

Internally, tables and indexes are typically stored as B-tree structures spread across pages. The first page contains the database header and metadata that tells SQLite which pages contain each table and index.

![A stylized diagram of a database file labeled "msgstore.db" showing stacked page blocks (one marked "4 KB") connected to an expanded "Page 1" content box below. The illustration uses orange and white outlines on a black background.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Databases/SQLite-The-Database-on-Every-Phone/msgstore-db-stacked-pages-4kb-page1.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=aeb96bf20b8a95ed008c0792bb6262b9)

Example: opening a local SQLite file in Python

```python theme={null}
import sqlite3

# Opens (or creates) msgstore.db in the current working directory
conn = sqlite3.connect('msgstore.db')
cur = conn.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY, text TEXT)')
conn.commit()
conn.close()
```

Example: Android (Kotlin) snippet to access a local SQLite database

```kotlin theme={null}
class MyDatabaseHelper(context: Context) :
    SQLiteOpenHelper(context, "msgstore.db", null, 1) {

    override fun onCreate(db: SQLiteDatabase) {
        db.execSQL("CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY, text TEXT)")
    }

    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { /* ... */ }
}
```

## Where database files live

When an app needs persistent storage, the operating system gives the app its own private folder that other apps cannot read. The app creates (or is assigned) a path inside that folder, and SQLite creates the database file there (for example, `msgstore.db`). As a result, a device can contain hundreds or thousands of SQLite files — one or more per installed app.

![A simple diagram showing app icons (WhatsApp, Chrome, Spotify, Slack) above an "Operating System" layer with arrows down to separate, locked storage folders — one folder labeled "msgstore.db".](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Databases/SQLite-The-Database-on-Every-Phone/apps-os-locked-folders-msgstore-db.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=5003c37bd272f283347f7dfd29bd13e3)

## Concurrency, networking, and security trade-offs

SQLite’s embedded design trades off some server-grade features for simplicity and portability. Key characteristics:

* Single-writer concurrency: By default, only one write transaction can modify a given SQLite database file at a time. Multiple readers can operate concurrently, but writers acquire locks that serialize writes. Enabling [Write-Ahead Logging (WAL)](https://www.sqlite.org/wal.html) improves concurrency by allowing readers to run while a writer is active, but there still remains only one writer at a time.
* No built-in networking: SQLite is local to the device and the process that opens it. There’s no network protocol provided out of the box, so you cannot natively share an SQLite file across multiple remote servers the way you would with PostgreSQL or MySQL.
* No internal user accounts/permissions: SQLite does not implement database-level users or role-based permissions. Access control is provided by the operating system’s file permissions and the app’s own logic.

A concise comparison of typical use cases:

| Feature | SQLite (embedded) | Client–Server DBMS (PostgreSQL/MySQL) |
| - | - | - |
| Deployment complexity | Zero-config, embedded in app | Requires server process and network setup |
| Concurrency | Multiple readers, single writer (WAL helps) | Many concurrent readers/writers with sophisticated locking/transactions |
| Networking | Local file only | Network protocol, remote clients supported |
| User management | OS-level file permissions | Built-in users, roles, and access control |
| Typical use case | Mobile apps, desktop apps, small devices | Multi-user server applications, shared databases |

SQLite is designed for simplicity and portability: a small, fast, zero-configuration database engine embedded in your app. For multi-user, networked, or highly-concurrent server workloads, a client–server DBMS (PostgreSQL, MySQL, etc.) is still the appropriate choice.

## Best practices and tips

* Use WAL for better read/write concurrency when many readers exist during writers.
* Keep transactions short to avoid blocking other writers.
* Use indices selectively to speed reads; indices increase file size and write cost.
* Regularly VACUUM or use the `PRAGMA auto_vacuum` setting to reclaim space if your workload deletes many rows.
* Protect database files using the platform’s file permissions; encrypt sensitive data (or the file) where needed.

## Links and references

* [SQLite Home](https://www.sqlite.org/)
* [SQLite Write-Ahead Logging (WAL)](https://www.sqlite.org/wal.html)
* [B-tree (Wikipedia)](https://en.wikipedia.org/wiki/B-tree)
* [Kotlin Android SQLiteOpenHelper documentation](https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper)

This overview should help you understand why SQLite is the default embedded relational database on phones and other constrained devices, and what trade-offs to consider when using it in your applications.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/1ee75c71-d566-42df-8cc2-7aa8e79b0f04/lesson/78ce83b3-0634-4d8b-8f2a-cffb0354a006)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.