Delete geoprocessing history from a geodatabase in ArcGIS Pro using Python

Last Published: September 12, 2023


Geoprocessing tools add metadata about their execution in a geodatabase. The metadata includes the tool name, its location, and the parameters used when geoprocessing logging is enabled. Enterprise Geodatabases with large metadata stored can impact the performance. GIS administrators and managers sometimes need to delete the geoprocessing history from a feature class or workspace metadata.

The geodatabase workspace, together with some feature classes, may have quite a bit of geoprocessing history contained in the metadata. Thumbnails may also be a big contributor to the total metadata. This can also increase over time as analyses are done on datasets within the geodatabase.

The size of the metadata in bytes can be checked for the geodatabase workspace, and the top 20 feature classes in an SQL Server geodatabase, by running the following T-SQL statement. Remember to replace <Database Name>. This statement assumes the geodatabase repository is owned by the sde user, otherwise use 'dbo' in place of 'sde':

SELECT TOP 20 datalength(documentation) Length, Name
FROM <Database Name>.sde.GDB_ITEMS

image of query and results in SQL editor


Remove geoprocessing history from feature classes in ArcGIS Pro

The capabilities that were provided in ArcGIS Desktop via the XSLT stylesheets listed are now available in ArcGIS Pro from the Metadata deleteContent method.

The script automates the process of deleting the metadata for all feature classes in an enterprise geodatabase, including feature classes stored in a feature dataset. Run the included Python script after updating the variables.

import arcpy
import os
from arcpy import metadata as md

# Update the following variables before running the script.
myWorkspace = r"D:\Databases\geodata.sde"
db_type = "SQL" #Set this to either "SQL", "Oracle or Postgres" if your db has spatial views. If not you may set it to "".

def RemoveHistory(myWorkspace):
##Removes GP History for feature dataset stored feature classes, and feature classes in the File Geodatabase.
    arcpy.env.workspace = myWorkspace
    for fds in arcpy.ListDatasets('','feature') + ['']:
        for fc in arcpy.ListFeatureClasses('','',fds):
            data_path = os.path.join(myWorkspace, fds, fc)
            if isNotSpatialView(myWorkspace, fc):
                print("Removed the geoprocessing metadata from: {0}".format(fc))
    print("Removed the geoprocessing metadata from: {0}".format(myWorkspace))

def isNotSpatialView(myWorkspace, fc):
##Determines if the item is a spatial view and if so returns True to listFcsInGDB()
    if db_type != "":
        desc = arcpy.Describe(fc)
        fcName =
        #Connect to the GDB
        egdb_conn = arcpy.ArcSDESQLExecute(myWorkspace)
        #Execute SQL against the view table for the specified RDBMS
        if db_type == "SQL":
            db, schema, tableName = fcName.split(".")
            sql = r"IF EXISTS(select * FROM sys.views where name = '{0}') SELECT 1 ELSE SELECT 0".format(tableName)
        elif db_type == "Oracle":
            schema, tableName = fcName.split(".")
            sql = r"SELECT count(*) from dual where exists (select * from user_views where view_name = '{0}')".format(tableName)
        elif db_type == "Postgres":
            db, schema, tableName = fcName.split(".")
            sql = r"SELECT count(*) from information_schema.views where table_schema NOT IN ('information_schema', 'pg_catalog') and table_name = '{0}'".format(tableName)
        egdb_return = egdb_conn.execute(sql)
        if egdb_return == 0:
            return True
            return False
        return True

def removeMetaData(data_path):
    # Get the metadata for the dataset
    tgt_item_md = md.Metadata(data_path)
    # Delete all geoprocessing history from the item's metadata
    if not tgt_item_md.isReadOnly:

if __name__ == "__main__":
    print("Done Done")

Article ID:000027149

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic