Compact (Data Management)

Summary

Compacts a file or mobile geodatabase, SQLite database, or Open Geospatial Consortium (OGC) GeoPackage file. Compacting rearranges data storage, often reducing the file's size and improving performance.

Usage

  • If data entry, deletion, or general editing is frequently performed, regularly compact the geodatabase, database, or file to ensure optimal performance.

  • A database that is open in ArcGIS AllSource for editing cannot be compacted. To compact the database, remove any layers with a source table or feature class in that database from the Contents pane.

  • Dive-in:

    File geodatabases are binary files on a disk drive. Adding, removing, or editing the data causes the files to fragment, decreasing overall database performance. This tool rearranges the database storage by defragmenting these files. This reduces the database's size on disk and improves database performance.

  • Learn more about compacting a mobile geodatabase

Parameters

LabelExplanationData Type
Input Workspace

The file or mobile geodatabase, SQLite database, or GeoPackage that will be compacted.

Workspace

Derived Output

LabelExplanationData Type
Updated Input Workspace

The updated input workspace.

Workspace

arcpy.management.Compact(in_workspace)
NameExplanationData Type
in_workspace

The file or mobile geodatabase, SQLite database, or GeoPackage that will be compacted.

Workspace

Derived Output

NameExplanationData Type
out_workspace

The updated input workspace.

Workspace

Code sample

Compact example 1 (Python window)

The following Python window script demonstrates how to use the Compact function in immediate mode.

import arcpy
arcpy.management.Compact("c:/landuse.gdb")
Compact example 2 (stand-alone script)

The following stand-alone script is a simple example of how to use the Compact function in a scripting environment.

# Name: Compact_Example.py
# Description: compact a file geodatabase

# Import the system modules
import arcpy

# Set local variables
gdbWorkspace = "C:/data/data.gdb"

arcpy.management.Compact(gdbWorkspace)

Related topics