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)