#Troubleshooting
Common issues and their solutions when working with PhoenixmlDb.
#Storage Issues
#"Map full" Error
Symptom: MDB_MAP_FULL: Environment mapsize limit reached
Cause: Database size exceeded configured MapSize.
Solution:
// Increase MapSize
db.Resize(currentMapSize * 2);
// Or set larger initial size
var options = new DatabaseOptions
{
MapSize = 20L * 1024 * 1024 * 1024 // 20 GB
};#"Max readers reached"
Symptom: MDB_READERS_FULL: Environment maxreaders limit reached
Cause: Too many concurrent read transactions.
Solution:
// Increase max readers
var options = new DatabaseOptions
{
MaxReaders = 256
};
// Or ensure transactions are being disposed
using (var txn = db.BeginTransaction(readOnly: true))
{
// Always dispose transactions
}#Database Corruption
Symptom: Errors on startup, data inconsistency
Cause: Unclean shutdown, disk failure
Solution:
# Check database integrity
phoenixmldb-admin check ./data
# If corruption detected, restore from backup
phoenixmldb-admin restore ./data --from backup.tar#Query Issues
#Slow Queries
Symptom: Queries take longer than expected
Diagnosis:
var plan = db.Explain(query);
Console.WriteLine(plan);
// Check if indexes are being usedSolutions:
-
Add appropriate indexes
-
Rewrite query to filter early
-
Limit result size
-
Use parameters instead of string concatenation
#Query Parse Errors
Symptom: XQueryParseException
Common causes:
-
Missing quotes around strings
-
Invalid XPath syntax
-
Mismatched brackets
-
Reserved word used as variable
Example fixes:
(: Wrong :)
for $x in //item where name = test return $x
(: Correct - quote the string :)
for $x in //item where name = 'test' return $x
(: Wrong :)
for $for in //item return $for
(: Correct - don't use reserved words :)
for $item in //item return $item#Type Errors
Symptom: XPTY0004: Type error
Solution:
(: Wrong - comparing string to number :)
//product[price > '100']
(: Correct - use number :)
//product[xs:decimal(price) > 100]#Transaction Issues
#Deadlock
Symptom: Transaction hangs or times out
Cause: Multiple transactions waiting on each other
Solution:
// Use retry pattern
public T ExecuteWithRetry<T>(Func<ITransaction, T> operation)
{
for (int i = 0; i < 3; i++)
{
try
{
using var txn = db.BeginTransaction();
var result = operation(txn);
txn.Commit();
return result;
}
catch (TransactionConflictException)
{
Thread.Sleep(100 * (i + 1));
}
}
throw new Exception("Max retries exceeded");
}#Transaction Timeout
Symptom: TransactionTimeoutException
Solution:
// Increase timeout
var options = new TransactionOptions
{
Timeout = TimeSpan.FromMinutes(5)
};
// Or break into smaller transactions#Write Blocked
Symptom: Write operations hang
Cause: Long-running read transaction blocking writes
Solution:
-
Ensure read transactions are disposed promptly
-
Use shorter transactions
-
Don't hold transactions across async operations
#Connection Issues
#Cannot Connect to Server
Symptom: ConnectionRefusedException
Checklist:
-
Server is running:
phoenixmldb-server status -
Port is correct
-
Firewall allows connection
-
TLS certificate is valid
#Authentication Failed
Symptom: AuthenticationException
Checklist:
-
Username and password correct
-
User exists in server config
-
API key is valid (if using)
#TLS Errors
Symptom: SSL/TLS handshake failed
Solutions:
// Trust self-signed certificate
var options = new ClientOptions
{
TlsSkipVerify = true // Only for development
};
// Or specify certificate
var options = new ClientOptions
{
TlsCaCertificate = "/path/to/ca.crt"
};#Cluster Issues
#Split Brain
Symptom: Multiple nodes claim to be leader
Cause: Network partition with nodes unable to communicate
Solution:
-
Restore network connectivity
-
If persistent, restart minority partition
-
Check firewall rules between nodes
#Node Won't Join
Symptom: New node cannot join cluster
Checklist:
-
Cluster ID matches
-
Network connectivity to peers
-
Raft ports open
-
Configuration correct
#Replication Lag
Symptom: Followers behind leader
Diagnosis:
phoenixmldb-cluster status
# Shows replication status for each nodeSolutions:
-
Check network bandwidth
-
Reduce write load
-
Increase snapshot frequency
#Performance Issues
#High Memory Usage
Causes and solutions:
-
Large transactions — Use smaller batches
-
Unclosed transactions — Ensure disposal
-
Large documents in memory — Use streaming
-
Many readers — Reduce max readers
#High CPU Usage
Causes and solutions:
-
Complex queries — Optimize or add indexes
-
Full scans — Add path/value indexes
-
XPath compilation — Use prepared queries
#High Disk I/O
Causes and solutions:
-
Frequent syncs — Consider NoMetaSync
-
Large writes — Batch in transactions
-
No SSD — Upgrade to SSD storage
#Logging and Diagnostics
#Enable Debug Logging
var options = new DatabaseOptions
{
Logger = LoggerFactory.Create(builder =>
{
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Debug);
}).CreateLogger<XmlDatabase>()
};#Query Metrics
var options = new QueryOptions
{
CollectMetrics = true
};
var result = db.Query(xquery, options);
Console.WriteLine($"Parse: {result.Metrics.ParseTime}");
Console.WriteLine($"Execute: {result.Metrics.ExecuteTime}");
Console.WriteLine($"Rows scanned: {result.Metrics.RowsScanned}");#Database Statistics
var stats = db.GetStatistics();
Console.WriteLine($"Containers: {stats.ContainerCount}");
Console.WriteLine($"Documents: {stats.DocumentCount}");
Console.WriteLine($"Size: {stats.UsedBytes / 1024 / 1024} MB");
Console.WriteLine($"Readers: {stats.ActiveReaders}");#Getting Help
If you can't resolve an issue:
-
Check the documentation
-
Search GitHub Issues
-
Create a new issue with:
-
PhoenixmlDb version
-
.NET version
-
Operating system
-
Minimal reproduction code
-
Full error message and stack trace
-