Database Maintenance
Over time, every production database needs structured maintenance.
Routine administrative tasks keep schemas healthy, queries fast, and recovery reliable.
In the event of hardware failure, human error, or natural disasters, disciplined backup and restore procedures allow you to recover the database back into production with minimal data loss.
Maintenance Tasks
Database administration spans the full lifecycle from initial provisioning to disaster recovery. Each stage requires repeatable scripts rather than ad-hoc manual changes:
- Install: Run database creation and initial schema build scripts.
- Secure: Create roles, users, and least-privilege grants.
- Evolve: Run versioned migration scripts to update schemas safely.
- Load: Populate initial seed data or import previously extracted datasets.
- Extract: Export tables or schemas into portable dump or data files.
- Transform: Clean, normalize, or reshape data structures between stages.
- Replicate: Synchronize changes to standby or remote databases.
- Backup: Capture consistent snapshots of datafiles, control files, and archive logs.
- Restore: Recover data and structure from verified backups and test the recovery path regularly.
Backup and Recovery
In Oracle environments, physical backups are managed with Recovery Manager (RMAN), while logical exports and schema transfers use Data Pump (expdp / impdp). Physical backups protect against media failure and support point-in-time recovery; logical exports are ideal for migrating schemas between environments.
# Physical full backup with archived redo logs via RMAN
rman target / <<'EOF'
BACKUP DATABASE PLUS ARCHIVELOG;
DELETE NOPROMPT OBSOLETE;
EOF
# Logical schema export with Oracle Data Pump
expdp app_admin/secret@prod schemas=HR directory=DATA_PUMP_DIR dumpfile=hr_backup.dmp logfile=hr_exp.log
Statistics and Health Checks
As tables grow and data distributions shift, the query optimizer relies on fresh statistics to pick efficient execution plans. Gathering table statistics and checking for invalid PL/SQL objects after schema deployments prevents silent performance regressions.
-- Refresh optimizer statistics for the HR schema
BEGIN
DBMS_STATS.GATHER_SCHEMA_STATS(
ownname => 'HR',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
cascade => TRUE
);
END;
/
-- Detect any invalid packages, views, or triggers after a migration
SELECT object_name, object_type, status
FROM user_objects
WHERE status <> 'VALID'
ORDER BY object_type, object_name;