Configure SQLite or PostgreSQL database for scrapai CLI
Overview
scrapai stores crawl metadata, spider configurations, and queue data in a relational database.
Database Options
SQLite (Default)
Best for: Development, small to medium projects (< 1M items), single-user usage.Pros: No setup, zero configuration, file-based, built into Python.Cons: Limited concurrency, single writer, not suitable for distributed systems.
PostgreSQL
Best for: Production, large projects (1M+ items), multi-user environments, distributed crawling.Pros: Excellent concurrency, scales to billions of rows, advanced indexing.Requires: PostgreSQL 12+ installed and running.
SQLite Configuration
Default Setup
SQLite is configured by default. Run ./scrapai setup to create scrapai.db in the project root.
scrapai uses SQLAlchemy ORM with Alembic migrations. Schema defined in core/models.py.Key Tables: spiders, projects, crawls, items, queue, analysis
View Schema
SQLite
PostgreSQL
sqlite3 scrapai.db ".schema"
psql scrapai -c "\dt"
Performance Tuning
SQLite
scrapai automatically applies optimal settings. For extreme performance, increase cache size in core/db.py.
PostgreSQL
Edit postgresql.conf to tune memory settings:
shared_buffers = 256MB # 25% of RAMeffective_cache_size = 1GB # 50-75% of RAMwork_mem = 16MBrandom_page_cost = 1.1 # For SSD
Restart: sudo systemctl restart postgresql
Troubleshooting
Connection Failed
SQLite: Check file exists and permissions. Recreate with rm scrapai.db* && ./scrapai setup.PostgreSQL: Test connection with psql -U user -d scrapai. Check service status and verify DATABASE_URL.