-
Notifications
You must be signed in to change notification settings - Fork 1
troubleshooting
This guide helps you resolve common issues when using BMLibrarian's migration system.
Symptoms:
psycopg.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
Solutions:
-
Check if PostgreSQL is running:
# On macOS with Homebrew brew services list | grep postgresql brew services start postgresql # On Linux with systemd sudo systemctl status postgresql sudo systemctl start postgresql # On Windows net start postgresql-x64-13 # Adjust version as needed
-
Verify connection parameters:
# Test direct connection psql -h localhost -p 5432 -U your_username -d postgres -
Check PostgreSQL configuration:
- Ensure
postgresql.confhaslisten_addressesconfigured - Check
pg_hba.conffor authentication settings
- Ensure
Symptoms:
psycopg.OperationalError: FATAL: password authentication failed for user "username"
Solutions:
-
Verify credentials:
# Test with psql psql -h localhost -U your_username -d postgres -
Check environment variables:
echo $POSTGRES_USER echo $POSTGRES_PASSWORD
-
Reset password if needed:
-- Connect as superuser and reset password ALTER USER your_username PASSWORD 'new_password';
Symptoms:
psycopg.OperationalError: FATAL: database "bmlibrarian_dev" does not exist
Solutions:
-
For first-time setup: Use
migrate initinstead ofmigrate apply - Check database name: Verify spelling and case sensitivity
-
Create database manually:
CREATE DATABASE bmlibrarian_dev;
Symptoms:
psycopg.errors.InsufficientPrivilege: permission denied to create database
Solutions:
-
Grant CREATEDB privilege:
-- Connect as superuser ALTER USER your_username CREATEDB;
-
Use a superuser account for initial setup:
bmlibrarian migrate init --user postgres --password admin_password --database bmlibrarian_dev
-
Create database with appropriate owner:
CREATE DATABASE bmlibrarian_dev OWNER your_username;
Symptoms:
psycopg.errors.InsufficientPrivilege: permission denied for table bmlibrarian_migrations
Solutions:
-
Grant necessary permissions:
GRANT ALL PRIVILEGES ON DATABASE bmlibrarian_dev TO your_username; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO your_username; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO your_username;
-
Check table ownership:
SELECT tableowner FROM pg_tables WHERE tablename = 'bmlibrarian_migrations';
Symptoms:
Error: baseline_schema.sql not found. Please specify --baseline-schema
Solutions:
-
Specify baseline schema explicitly:
bmlibrarian migrate init --baseline-schema /path/to/baseline_schema.sql ...
-
Check file location: Ensure
baseline_schema.sqlis in the project root -
Use absolute path:
bmlibrarian migrate init --baseline-schema "$(pwd)/baseline_schema.sql" ...
Symptoms:
Baseline schema has already been applied.
Solutions:
This is normal behavior. The migration system tracks applied migrations to prevent duplicate application.
-
Check applied migrations:
SELECT * FROM bmlibrarian_migrations ORDER BY applied_at;
-
To reapply (dangerous):
-- Only if you know what you're doing DELETE FROM bmlibrarian_migrations WHERE filename = 'baseline_schema.sql';
Symptoms:
psycopg.errors.SyntaxError: syntax error at or near "INVALID"
Solutions:
-
Review migration file: Check SQL syntax carefully
-
Test migration separately:
psql -d bmlibrarian_dev -f ~/.bmlibrarian/migrations/001_problematic.sql -
Fix and rename migration:
# Fix the SQL file mv 001_problematic.sql 001_fixed_migration.sql
Symptoms: Migration was modified after being applied.
Solutions:
- Don't modify applied migrations - create a new one instead
-
Create corrective migration:
-- In 002_fix_previous_migration.sql -- Add corrective statements here
Symptoms:
ValueError: Database credentials not configured. Please set POSTGRES_USER and POSTGRES_PASSWORD environment variables.
Solutions:
-
Set required environment variables:
export POSTGRES_USER=your_username export POSTGRES_PASSWORD=your_password export POSTGRES_HOST=localhost export POSTGRES_PORT=5432 export POSTGRES_DB=bmlibrarian_dev
-
Use .env file:
# Create .env file cat > .env << EOF POSTGRES_USER=your_username POSTGRES_PASSWORD=your_password POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_DB=bmlibrarian_dev EOF
-
Specify parameters explicitly:
bmlibrarian migrate apply --host localhost --user username --password password --database dbname
Symptoms:
bmlibrarian: command not foundSolutions:
-
Install BMLibrarian:
pip install bmlibrarian
-
Check PATH:
pip show bmlibrarian which bmlibrarian
-
Use full path:
python -m bmlibrarian.cli migrate --help
-
Activate virtual environment:
source venv/bin/activate # or your venv path bmlibrarian --help
Symptoms:
ModuleNotFoundError: No module named 'psycopg'
Solutions:
-
Install missing dependencies:
pip install psycopg[binary]
-
Reinstall BMLibrarian:
pip uninstall bmlibrarian pip install bmlibrarian
-
Check virtual environment:
pip list | grep bmlibrarian pip list | grep psycopg
Symptoms:
psycopg.errors.UndefinedObject: extension "pgvector" does not exist
Solutions:
-
Install required PostgreSQL extensions:
# On Ubuntu/Debian sudo apt-get install postgresql-contrib postgresql-14-pgvector # On macOS with Homebrew brew install pgvector # On CentOS/RHEL sudo yum install postgresql-contrib
-
Enable extensions manually:
-- Connect as superuser CREATE EXTENSION IF NOT EXISTS pgvector; CREATE EXTENSION IF NOT EXISTS pg_trgm; -
Check available extensions:
SELECT * FROM pg_available_extensions WHERE name LIKE '%vector%';
Symptoms: Large migrations hang or take excessive time.
Solutions:
-
Check for locks:
SELECT * FROM pg_locks WHERE NOT granted;
-
Break up large migrations:
-- Instead of one large migration, create multiple smaller ones -- 001_create_indexes_part1.sql -- 002_create_indexes_part2.sql
-
Run during maintenance window:
- Schedule large migrations during low-traffic periods
- Consider using
CONCURRENTLYfor index creation
-
PostgreSQL logging:
-- In postgresql.conf log_statement = 'all' log_min_duration_statement = 0
-
Python logging:
import logging logging.basicConfig(level=logging.DEBUG)
-- See all applied migrations
SELECT filename, applied_at FROM bmlibrarian_migrations ORDER BY applied_at;
-- Check migration table structure
\d bmlibrarian_migrations
-- See database size
SELECT pg_size_pretty(pg_database_size('bmlibrarian_dev'));If the migration system gets into a bad state:
-
Backup your data:
pg_dump bmlibrarian_dev > backup.sql -
Reset migration state:
-- DANGER: Only if you know what you're doing DROP TABLE IF EXISTS bmlibrarian_migrations;
-
Reinitialize:
bmlibrarian migrate init --database bmlibrarian_dev ...
If these solutions don't resolve your issue:
- Check the logs: Look for detailed error messages
- Verify your setup: Ensure all prerequisites are met
- Test with minimal configuration: Try with a fresh database
- Check documentation: Review the relevant documentation sections
- Create a test case: Try to reproduce with minimal example
# Check PostgreSQL version
psql --version
# Check BMLibrarian version
python -c "import bmlibrarian; print(bmlibrarian.__version__)"
# Test database connection
psql -h localhost -U username -d database_name -c "SELECT version();"
# Check Python environment
pip list | grep -E "(bmlibrarian|psycopg)"
# List migration files
ls -la ~/.bmlibrarian/migrations/Getting Started
Applications
Features
- Workflow Guide
- Agents Guide
- Multi-Model Query Guide
- Query Agent Guide
- Citation Guide
- Reporting Guide
- Counterfactual Guide
Advanced
Architecture
Systems
- Workflow System
- Queue System Architecture
- Citation System
- Reporting System
- Counterfactual System
- Multi-Model Architecture
Contributing