Transaction Log (Write-Ahead Log)
Transaction Log (Write-Ahead Log) is a SQL statement in the Transactions category. Transaction log (WAL) ensures durability and enables recovery. Records every data modification before applying. The syntax is -- The transaction log records all changes before they are written to the data files (WAL).. It returns transaction log info. A typical example: -- SQL Server: transaction log file (.ldf) SELECT name, size/128 AS size_mb, recovery_model_desc FROM sys.database_files WHERE type_desc = 'LOG'; -- View log space usage: DBCC SQLPERF(LOGSPACE); -- PostgreSQL WAL: SELECT * FROM pg_stat_wal; -- WAL size: pg_current_wal_lsn() to track write-ahead log position -- Log backups (FULL recovery model): -- BACKUP LOG db_name TO DISK = 'log_backup.trn'; A close relative is BEGIN / START TRANSACTION, which begins a new transaction. Changes made within are invisible to others until COMMIT. A close relative is COMMIT, which saves all changes made in the current transaction permanently. A close relative is ROLLBACK, which undoes all changes made in the current transaction (or to a savepoint).