Skip to main content

SQLite Databases

SQLite is a self-contained, file-based database engine. Unlike MySQL or PostgreSQL, SQLite doesn’t require a server - the entire database is stored in a single file on your Mac.

Quick Setup

1

Open Connection Form

Click New Connection from the Welcome screen or File > New Connection
2

Select SQLite

Choose SQLite from the database type selector
3

Select Database File

Click Browse and select your .sqlite, .db, or .sqlite3 file
4

Create Connection

Give your connection a name and click Create

Connection Settings

SQLite connections are simple since no server is involved:
FieldDescription
NameA friendly name for this connection
File PathFull path to the SQLite database file
SQLite connection
No username, password, or network settings are needed for SQLite databases.

Common SQLite Locations

Application Databases

Many macOS applications use SQLite:
ApplicationDatabase Location
Safari~/Library/Safari/History.db
Photos~/Pictures/Photos Library.photoslibrary/database/Photos.sqlite
Messages~/Library/Messages/chat.db
Notes~/Library/Group Containers/group.com.apple.notes/NoteStore.sqlite
System databases may be locked while their parent applications are running. Quit the application before opening its database.

Development Databases

Common development database locations:
# Ruby on Rails
./db/development.sqlite3

# Django
./db.sqlite3

# iOS Simulator
~/Library/Developer/CoreSimulator/Devices/*/data/Containers/Data/Application/*/Documents/*.sqlite

# Core Data
*.sqlite (in app's container)

Creating a New Database

To create a new SQLite database:
  1. Create a new connection
  2. Enter a path for a file that doesn’t exist yet
  3. TablePro will create the file when you connect
Or use the command line:
sqlite3 ~/Documents/newdatabase.sqlite "SELECT 1;"

Features

Database Browser

The sidebar shows all tables and views in your SQLite database:
SQLite browser

Table Information

For each table, TablePro provides:
  • Structure: Column names, types, and constraints
  • Indexes: All indexes including UNIQUE constraints
  • DDL: The CREATE TABLE statement

SQLite System Tables

TablePro can display SQLite’s internal tables:
TablePurpose
sqlite_masterSchema information
sqlite_sequenceAUTOINCREMENT tracking

Query Execution

Execute queries with full SQLite syntax support:
-- JSON functions (SQLite 3.38+)
SELECT json_extract(data, '$.name') as name
FROM users
WHERE json_extract(data, '$.active') = true;

-- Window functions
SELECT
    category,
    product,
    price,
    rank() OVER (PARTITION BY category ORDER BY price DESC) as rank
FROM products;

-- CTEs
WITH RECURSIVE
    cnt(x) AS (
        SELECT 1
        UNION ALL
        SELECT x+1 FROM cnt WHERE x < 10
    )
SELECT x FROM cnt;

-- Full-text search (if FTS enabled)
SELECT * FROM documents WHERE documents MATCH 'sqlite AND database';

-- UPSERT (INSERT OR REPLACE)
INSERT INTO settings (key, value)
VALUES ('theme', 'dark')
ON CONFLICT(key) DO UPDATE SET value = excluded.value;

SQLite Data Types

SQLite uses a dynamic type system with type affinity:
AffinityDescriptionExamples
TEXTString dataVARCHAR, TEXT, CLOB
INTEGERSigned integerINT, INTEGER, BIGINT
REALFloating pointREAL, DOUBLE, FLOAT
NUMERICNumeric or textDECIMAL, BOOLEAN, DATE
BLOBBinary dataBLOB, raw bytes
SQLite accepts any data type in any column (except INTEGER PRIMARY KEY). The type is a hint, not a constraint.

Working with Large Files

File Size

SQLite databases can grow quite large. TablePro handles:
  • Databases up to several GB
  • Tables with millions of rows
  • BLOB data (images, files)

Performance Tips

  1. Use pagination: Enable pagination in settings for large tables
  2. Add indexes: Create indexes for frequently queried columns
  3. Use LIMIT: Always limit result sets when exploring
  4. Vacuum periodically: Reclaim space with VACUUM
-- Check database size
SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size();

-- Analyze tables for query optimization
ANALYZE;

-- Reclaim unused space
VACUUM;

Troubleshooting

Database is Locked

Symptoms: “database is locked” or “database table is locked” Causes:
  • Another application has the database open
  • A previous query is still running
  • Write-ahead logging (WAL) mode conflicts
Solutions:
  1. Close other applications using the database
  2. Wait for running queries to complete
  3. Check for WAL files:
    ls -la /path/to/database.sqlite*
    # You might see: database.sqlite-wal, database.sqlite-shm
    

Cannot Open Database

Symptoms: “unable to open database file” Causes and Solutions:
  1. File doesn’t exist: Verify the path is correct
  2. Permission denied: Check file permissions
    ls -la /path/to/database.sqlite
    chmod 644 /path/to/database.sqlite
    
  3. Path contains special characters: Use absolute paths without spaces

Corrupt Database

Symptoms: “database disk image is malformed” Recovery options:
  1. Check integrity:
    PRAGMA integrity_check;
    
  2. Attempt recovery:
    sqlite3 corrupt.sqlite ".recover" | sqlite3 recovered.sqlite
    
  3. Restore from backup (if available)

Schema Changes Not Visible

Symptoms: Tables or columns you created aren’t showing Solution: Refresh the connection:
  1. Right-click the connection
  2. Select Refresh
Or disconnect and reconnect.

SQLite Pragmas

TablePro supports SQLite PRAGMA commands for configuration:
-- Check SQLite version
SELECT sqlite_version();

-- Show table info
PRAGMA table_info(users);

-- Check foreign keys are enabled
PRAGMA foreign_keys;

-- Enable foreign key enforcement
PRAGMA foreign_keys = ON;

-- Check journal mode
PRAGMA journal_mode;

-- Use WAL mode for better concurrency
PRAGMA journal_mode = WAL;

Backup and Restore

Manual Backup

SQLite databases are just files. To backup:
# Simple copy (ensure database is not being written to)
cp database.sqlite database-backup.sqlite

# SQLite backup command (safer, handles locks)
sqlite3 database.sqlite ".backup backup.sqlite"

Export to SQL

Export your database as SQL statements:
sqlite3 database.sqlite .dump > backup.sql

Restore from SQL

sqlite3 newdatabase.sqlite < backup.sql

Differences from Server Databases

FeatureSQLiteMySQL/PostgreSQL
Server requiredNoYes
Multiple connectionsLimitedUnlimited
User authenticationNoYes
Network accessFile-basedTCP/IP
Concurrent writesLimitedFull support
Stored proceduresNoYes
Data typesDynamicStatic

Common Use Cases

SQLite is ideal for:
  • Local development: Prototype applications quickly
  • Embedded apps: Mobile apps, desktop apps
  • Single-user apps: Personal databases
  • Data analysis: Quick data exploration
  • Testing: Unit tests with isolated databases
  • Prototyping: Before migrating to a server database

Next Steps