Skip to content

uhsear/database-maintenance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

database-maintenance

This Python script provides a series of ArcPy functions to perform routine database maintenance on a Spatial Database Engine (SDE) geodatabase. This includes blocking and disconnecting all connections, reconciling all versions, compressing the database, rebuilding indexes on system tables, updating statistics, and allowing connections again.

Explanation

The script begins by setting up a logging functionality to track the script's progress. Logs are written to a file and saved in a specified directory.

A function set_up_workspace is defined to set the workspace environment.

The function block_connections blocks all new connections to the database.

The function disconnect_users disconnects all currently connected users to the database.

The function reconcile_versions compiles a list of versions to reconcile against the default version. It then reconciles and posts all versions to the default.

The function compress_database is used to compress the database, which reduces storage space and improves performance.

The function maintain_db_system rebuilds indexes and updates statistics on the system tables.

The function allow_connections allows new connections to the database again.

In the primary function, the script calls the above functions in sequence. Any errors that occur are caught and logged.

The script logs the successful completion of each function call and the overall process.

Requirements

This script requires ArcPy, logging, and time Python libraries. It is necessary to have an administrative connection to the SDE geodatabase with sufficient privileges to execute the maintenance tasks. The script will also need the ability to write logs to the local file system.

How to Run

The script can be run from a command line by executing python .py, replacing with the name of the python file. The script doesn't take any command line arguments.

The script can be run directly from ArcGIS Pro.

The script can also be scheduled to run at specific intervals using task scheduler (this is how I have it setup).

Notes

This script manipulates an active SDE geodatabase and should be used cautiously. Always back up your data before running the script. The database will be inaccessible to other users while the script is running.

This script only works off of the assumption that there is only one owner for the database, otherwise it will not work.

Author

My name is Asir Khan and I am a programmer who was introduced to the world of GIS in Feburary 2023.