board logo
Posted by: DogMan - 12 December 2025 15:13:31
What can I do about thsi message - is it because it cannot reach the database?

Posted by: sirclesadmin - 12 December 2025 17:51:49

This error typically indicates that the system cannot calculate or retrieve the current stock levels during the initialization phase. Since uzERP relies heavily on a "calc_stock" process to reconcile inventory from the ledger, this often points to a database connectivity issue or a corruption in the stock transaction table.

Here is a step-by-step troubleshooting guide to resolve the "Failed to start uzERP stock balances" error.

1. Check Service Status (Database is usually the culprit)

The most common cause is that the PostgreSQL database service hasn't fully started before uzERP tries to access it.

  • Check PostgreSQL status:
    sudo systemctl status postgresql
    
  • Restart the services manually to see if the error clears (this often fixes race conditions on boot):
    sudo systemctl restart postgresql
    sudo systemctl restart apache2  # Or nginx, depending on your setup
    

2. Inspect the Logs

If restarting the services doesn't work, you need to see exactly why the calculation is failing.

  • Apache/Web Server Error Log: This is the most likely place to find the PHP fatal error or timeout.

    • Location: Typically /var/log/apache2/error.log
    • Command: tail -f /var/log/apache2/error.log
    • Look for: PHP timeouts (e.g., Maximum execution time exceeded) or Postgres connection refused errors.
  • PostgreSQL Log:

    • Location: Typically /var/log/postgresql/postgresql-X.X-main.log (where X.X is your version).
    • Look for: "PANIC", "FATAL", or corruption warnings specifically related to the stock_tran or stock_balance tables.

3. Clear the Cache (Stock Map Rebuild)

uzERP caches stock balances to speed up performance. If this cache is corrupted, the boot process will fail.

  1. Navigate to your uzERP data directory (often /var/www/uzerp/data/ or similar).
  2. Clear the contents of the cache folder.
    sudo rm -rf /var/www/uzerp/data/cache/*
    
  3. Try logging in again. This forces uzERP to recalculate the stock map from scratch.

4. Database Integrity Check

If you recently had a power outage or a hard crash, the stock transaction table might be locked or damaged.

  1. Access the PostgreSQL prompt:
    sudo -u postgres psql uzerp_db  # Replace 'uzerp_db' with your actual DB name
    
  2. Run a simple query to see if the stock table is readable:
    SELECT count(*) FROM stock_tran;
    
    • If this queries successfully: Your database is likely fine, and the issue is configuration/PHP related.
    • If this fails: You may need to repair the table or restore from a backup.

Summary Checklist

  • Restart PostgreSQL and Apache.
  • Check /var/log/apache2/error.log for specific PHP errors.
  • Delete the contents of the data/cache directory.

Next Step: Would you like me to provide the specific command to rebuild the stock map via the command line (CLI) if you cannot access the web interface?