6.1 KiB
6.1 KiB
Troubleshooting Guide
Common Issues and Solutions
Database Connection Issues
Unable to Connect to Database
Error: could not connect to server: Connection refused
Possible Causes:
- PostgreSQL service not running
- Incorrect connection details
- Network/firewall issues
Solutions:
-
Check PostgreSQL service:
# Check service status sudo systemctl status postgresql # Start service if stopped sudo systemctl start postgresql -
Verify connection details in
.database:# Test connection manually psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${DB_USER}" -d "${DB_NAME}" -
Check firewall settings:
# Check if port is open sudo netstat -tulpn | grep 5432
Authentication Failed
Error: FATAL: password authentication failed for user
Solutions:
- Verify credentials in
.database - Check PostgreSQL authentication settings:
# View pg_hba.conf location psql -U postgres -c 'SHOW hba_file;' # Check user permissions psql -U postgres -c '\du'
Import Process Issues
GKWP Import Failures
File Format Errors:
Error: Invalid filename format. Expected: GKWP - {KEYWORD}.csv
Solutions:
- Check file naming convention
- Verify file content format:
# View file headers head -n 1 "GKWP - keyword.csv" # Check file encoding file -i "GKWP - keyword.csv"
Data Processing Errors:
Error: Invalid data format in row X
Solutions:
- Examine problematic rows:
# View specific line sed -n 'Xp' "GKWP - keyword.csv" - Check for special characters:
# Look for non-ASCII characters grep -P '[^\x00-\x7F]' "GKWP - keyword.csv"
SEMRush Import Issues
Duplicate Keywords:
Error: duplicate key value violates unique constraint
Solutions:
- Check existing keywords:
SELECT keyword FROM Keywords WHERE LOWER(keyword) = LOWER('problematic_keyword'); - Use conflict resolution:
INSERT ... ON CONFLICT (LOWER(keyword)) DO UPDATE ...
LibreOffice Base Connection Issues
Unable to Connect
Symptoms:
- Connection error dialog
- Database not showing in available connections
Solutions:
- Verify PostgreSQL ODBC/JDBC settings
- Check LibreOffice Base configuration:
- Database URL format
- Driver selection
- Connection parameters
Slow Performance
Solutions:
-
Check indexes:
-- View missing indexes SELECT schemaname, tablename, reason, round(percent,2) FROM pg_stat_user_tables WHERE n_live_tup > 100000 ORDER BY n_live_tup DESC; -
Optimize views:
-- Analyze view performance EXPLAIN ANALYZE SELECT * FROM v_active_keywords_per_ad_group;
Script Execution Issues
Permission Denied
bash: ./bin/db-admin/create-db.sh: Permission denied
Solutions:
-
Check file permissions:
# View permissions ls -l bin/db-admin/create-db.sh # Set correct permissions chmod +x bin/db-admin/create-db.sh -
Verify script ownership:
# Change ownership if needed chown proper_user:proper_group bin/db-admin/create-db.sh
Path Issues
Error: Could not source .database file
Solutions:
- Check script execution directory
- Use absolute paths:
# Get script directory SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "${SCRIPT_DIR}/../../.database"
Data Integrity Issues
Orphaned Records
Symptoms:
- Missing relationships
- Incomplete data
Solutions:
-
Check for orphaned records:
-- Find keywords without ad groups SELECT k.keyword_id, k.keyword FROM Keywords k LEFT JOIN Keyword_Ad_Group_Assignments kaga ON k.keyword_id = kaga.keyword_id WHERE kaga.ad_group_id IS NULL; -
Clean up orphaned data:
-- Remove orphaned assignments DELETE FROM Keyword_Ad_Group_Assignments WHERE ad_group_id NOT IN (SELECT ad_group_id FROM Ad_Groups);
Logging and Monitoring
Missing Logs
Solutions:
- Check log directory permissions
- Verify log configuration:
# Check log directory ls -la logs/ # Create log directory if missing mkdir -p logs/ chmod 750 logs/
Error Investigation
# Search for errors in logs
grep -r "ERROR" logs/
# View recent errors
tail -f logs/$(date +%Y-%m-%d)-*.log
Preventive Measures
Regular Maintenance
-
Database cleanup:
VACUUM ANALYZE; -
Log rotation:
# Rotate logs older than 30 days find logs/ -name "*.log" -mtime +30 -delete -
Backup verification:
# Test backup integrity ./bin/db-admin/verify-backup.sh backups/latest.sql.gz
Monitoring
-
Database size monitoring:
SELECT pg_size_pretty(pg_database_size('keyword_management')); -
Table growth monitoring:
SELECT relname, n_live_tup FROM pg_stat_user_tables ORDER BY n_live_tup DESC;
Emergency Procedures
Database Recovery
- Stop all active processes
- Restore from latest backup:
./bin/db-admin/restore-db.sh backups/latest.sql.gz
Data Corruption
-
Switch to read-only mode:
ALTER DATABASE keyword_management SET default_transaction_read_only = on; -
Investigate issues:
-- Check table integrity SELECT * FROM pg_stat_database WHERE datname = 'keyword_management';
Support Resources
-
Log locations:
- Script logs:
/logs - PostgreSQL logs: (system-dependent)
- LibreOffice Base logs
- Script logs:
-
Configuration files:
.database- PostgreSQL configuration
- Script configurations
Would you like me to expand on any particular troubleshooting aspect or add more examples?