DEV Community

Scale
Scale

Posted on

πŸ”„ GBase Database Internals: Transactions, Logging, and Service Lifecycle Explained

In production systems, executing SQL is only part of the story.

Behind every operation in GBase database, there is a full lifecycle:

  1. A transaction begins
  2. Data changes are written
  3. Logs record every step
  4. The database service ensures durability
  5. Recovery is possible if something fails

This article connects transactions + logging + service management into one complete picture.


🧠 Part 1: Transactions β€” The Foundation of Data Consistency

In GBase, all data operations are executed inside transactions.

Example:

BEGIN;
UPDATE users SET age = 30 WHERE id = 1;
COMMIT;
Enter fullscreen mode Exit fullscreen mode

What happens:

  • Transaction starts
  • Data is modified
  • Logs capture the change
  • Commit finalizes the operation

GBase ensures ACID compliance, meaning operations are atomic and recoverable.


🧱 Part 2: Logging β€” How GBase Tracks Every Change

GBase uses logical and physical logs to track database activity.

πŸ”Ή Logical Logs

  • Record SQL-level operations
  • Track transactions (INSERT / UPDATE / DELETE)

πŸ”Ή Physical Logs

  • Record low-level storage changes
  • Track page modifications

You can monitor logs with:

onstat -l
Enter fullscreen mode Exit fullscreen mode

This shows:

  • Log usage
  • Number of records
  • Space consumption (gbasedbt.com)

πŸ“Š Example Log Output

numrecs    Log Space used
82067      12130972
Enter fullscreen mode Exit fullscreen mode

This indicates how many operations have been recorded and how much space they consume (gbase.cn)


πŸ”„ What Happens During an UPDATE?

UPDATE users SET age = 30 WHERE id = 1;
Enter fullscreen mode Exit fullscreen mode

Internally:

  1. Transaction begins
  2. Old data is logged
  3. New data is written
  4. Log entry is created
  5. Transaction commits

πŸ‘‰ If something fails, logs allow rollback or recovery.


βš™οΈ Part 3: Database Service Lifecycle

Transactions and logs rely on a running database engine.

πŸš€ Start Database

oninit -vy
Enter fullscreen mode Exit fullscreen mode

This:

  • Allocates shared memory
  • Loads configuration
  • Initializes logs and storage
  • Starts background processes (gbase.cn)

πŸ›‘ Stop Database

onmode -ky
Enter fullscreen mode Exit fullscreen mode

This:

  • Terminates sessions
  • Flushes logs to disk
  • Ensures safe shutdown (gbasedbt.com)

πŸ” Check Status

onstat -
Enter fullscreen mode Exit fullscreen mode

Example:

On-Line -- Up 00:00:14
Enter fullscreen mode Exit fullscreen mode

Shows database is running normally (gbase.cn)


πŸ”„ Part 4: Recovery β€” When Things Go Wrong

Scenario: System Crash

If the database crashes:

  1. Restart with oninit
  2. GBase reads logs
  3. Applies committed transactions
  4. Rolls back incomplete ones

During startup, GBase initializes:

  • Log/checkpoint information
  • Storage structures
  • Recovery processes (gbase.cn)

Example Error During Startup

Cannot open chunk '/path/datadbs1_1'
Enter fullscreen mode Exit fullscreen mode

This indicates storage issues, but logs still help recover valid data (gbase.cn)


πŸ“Š Part 5: Monitoring Transactions and Logs

After heavy operations, monitoring is critical.


Check Logs

onstat -l
Enter fullscreen mode Exit fullscreen mode

Check System Performance

onstat -p
Enter fullscreen mode Exit fullscreen mode

Shows:


Check Sessions

onstat -g ses
Enter fullscreen mode Exit fullscreen mode

Displays active transactions and connections (gbase.cn)


⚠️ Real-World Issues

1. Heavy Logging

Large updates:

UPDATE orders SET status = 'done';
Enter fullscreen mode Exit fullscreen mode

May cause:

  • High disk I/O
  • Log space exhaustion

2. Lock Contention

Transactions can lock rows or tables:

  • Blocking other queries
  • Causing performance issues (DEV Community)

3. Startup Failures

Incorrect configuration or missing files can prevent startup.


⚑ Best Practices

βœ… Use Transactions Explicitly

BEGIN;
UPDATE ...
COMMIT;
Enter fullscreen mode Exit fullscreen mode

βœ… Monitor Logs Regularly

onstat -l
Enter fullscreen mode Exit fullscreen mode

βœ… Ensure Proper Shutdown

onmode -ky
Enter fullscreen mode Exit fullscreen mode

Avoid force killing processes.


βœ… Watch System After Heavy Operations

onstat -p
Enter fullscreen mode Exit fullscreen mode

🧠 Key Insight

GBase reliability comes from the combination of three layers:

Layer Role
Transaction Controls data changes
Logging Records every operation
Service Ensures execution & recovery

πŸ‘‰ You need all three to work together.


πŸš€ Final Thoughts

GBase is not just executing SQLβ€”it is constantly:

  • Tracking changes through logs
  • Managing transactions
  • Maintaining system state
  • Ensuring recovery

Understanding this lifecycle helps you:

πŸ‘‰ Debug issues faster
πŸ‘‰ Prevent data loss
πŸ‘‰ Optimize performance


πŸ’¬ Key Takeaways

  • Every data change is logged
  • Transactions ensure consistency
  • Logs enable recovery
  • Service lifecycle controls everything

πŸ”₯ What to Try Next

  • Run an UPDATE and observe logs with onstat -l
  • Restart the database and observe recovery
  • Simulate rollback scenarios

If you want, I can next generate:

  • πŸ§ͺ A hands-on lab (simulate crash + recovery step-by-step)
  • πŸ” A deep dive into GBase logging internals
  • ⚑ Or a performance tuning guide for transactions

Top comments (0)