Erneutes Erstellen von Indizes in Geodatabase-Systemtabellen mit einem Python-Skript

Dieses Thema gilt nur für ArcGIS for Desktop Standard und ArcGIS for Desktop Advanced.

Datenbankindizes werden verwendet, um Zeilen, die mit dem Prädikatfilter einer Abfrage übereinstimmen, schnell zu identifizieren. Die meisten der Geodatabase-Systemtabellen haben Indizes, aber die Tabellen, die tendenziell die größte Menge an Änderungen in einer versionierten Enterprise-Geodatabase aufweisen und die häufigste Neuerstellung der Indizes erfordern, sind die Status-, state_lineages- und mv_tables_modified-Systemtabellen. In einer stark bearbeiteten versionierten Geodatabase könnten Sie jede Nacht Indizes in diesen Tabellen aktualisieren.

Als Geodatabase-Administrator können Sie ein Standalone-Python-Skript erstellen, das das Werkzeug Index neu erstellen aufruft und die Neuerstellung der Indizes in diesen Tabellen in Geodatabases in IBM DB2, Microsoft SQL Server, Oracle oder PostgreSQL planen.

Zur Ausführung des Skripts müssen Sie eine Verbindung zur Geodatabase als Geodatabase-Administrator herstellen können. Sie können entweder eine Verbindungsdatei (.sde) erstellen und vom Skript aus darauf zeigen oder die Verbindungsinformationen direkt in das Skript eingeben. Planen Sie danach das Skript so, dass es mit der Windows-Aufgabenplanung oder dem Linux-cron-Daemon ausgeführt wird.

Schritte:
  1. Kopieren Sie eines der folgenden Skripte auf einen Computer, auf dem Python und einer der folgenden ArcGIS-Clients installiert sind:
    • ArcGIS for Desktop (Standardoder Advanced)
    • ArcGIS Engine mit der Erweiterung Geodatabase-Aktualisierung
    • ArcGIS Runtime
    • ArcGIS for Server (Standard oder Erweitert)

    Ändern Sie die Skripte, um Ihre standortspezifischen Informationen einzuschließen.

    Dieses Skript verwendet auf dem lokalen Computer eine vorhandene Datenbankverbindungsdatei, um eine Verbindung mit der Datenbank herzustellen und das Skript auszuführen:

    # Name: RSysIdx.py
    # Description: Rebuilds indexes on the states, state_lineages, 
    # and mv_tables_modified tables in an enterprise geodatabase 
    # using an existing .sde file.
    
    # Author: Esri
    
    # Import system modules
    import arcpy, os
    
    # set workspace
    workspace = arcpy.GetParameterAsText(0)
    default_gdb = "C:\\Documents and Settings\<user>\Application Data\ESRI\ArcCatalog\sp_data.sde"
    # set the workspace environment
    arcpy.env.workspace = workspace
    
    # Execute rebuild indexes
    # Note: To use the "SYSTEM" option the workspace user must be an administrator.
    arcpy.RebuildIndexes_management(workspace, "SYSTEM", "", "ALL")
    print 'Rebuild Complete'
    

    Dieses Beispielskript enthält die notwendigen Informationen für eine Verbindung mit einer Oracle-Datenbank, um die Indizes in den Status-, state_lineages- und mv_tables_modified-Systemtabellen zu aktualisieren:

    # Name: RSysIdxOracle.py
    # Description: Rebuilds indexes on the states, state_lineages,
    # and mv_tables_modified tables in an enterprise geodatabase
    # in Oracle.
    
    # Author: Esri
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    server = servername
    service = "5151 | sde:oracle:sid"
    account_authentication = OPERATING_SYSTEM_AUTH | DATABASE_AUTH
    #Leave username and password blank if using OPERATING_SYSTEM_AUTH
    username = gdb_admin_user_name
    password = gdb_admin_password
    version = sde.DEFAULT
    
    
    # Set local variables
    if os.name.lower() == "nt":
       slashsyntax = "\\"
       if os.environ.get("TEMP") == None:
          temp = "c:\\temp"
       else:
          temp = os.environ.get("TEMP")
    else:
       slashsyntax = "/"
       if os.environ.get("TMP") == None:
          temp = "/usr/tmp"
       else:
          temp = os.environ.get("TMP")
    
    Connection_File_Name = temp + slashsyntax + "connection.sde"
    
    # Check for the .sde file and delete it if present
    if os.path.exists(Connection_File_Name):
       os.remove(Connection_File_Name)
    
    #Variable defined within the script; other variable options commented out at the end of the line
    saveUserInfo = "SAVE_USERNAME" #DO_NOT_SAVE_USERNAME
    saveVersionInfo = "SAVE_VERSION" #DO_NOT_SAVE_VERSION
    
    print "Creating ArcSDE Connection File..."
    # Create ArcSDE Connection File
    # Usage: out_folder_path, out_name, server, service, database, account_authentication, username, password, save_username_password
    arcpy.CreateArcSDEConnectionFile_management(temp, "connection.sde", server, service, account_authentication, username, password, saveUserInfo, version, saveVersionInfo)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print 'Rebuild Complete'
    

    Dieses Beispielskript enthält die Informationen für die Verwendung eines vom Betriebssystem authentifizierten dbo-Benutzers, um eine Verbindung zum SQL-Server herzustellen und die Indizes in den sde_states-, sde_state_lineages- und sde_mv_tables_modified-Systemtabellen zu aktualisieren:

    # Name: RSysIdxSqlServer.py
    # Description: Rebuilds indexes on the sde_states, sde_state_lineages,
    # and sde_mv_tables_modified tables in an enterprise geodatabase
    # in SQL Server.
    
    # Author: Esri
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    server = servername
    service = "5151 | sde:sqlserver:sqlserver_instance"
    database = database_name
    account_authentication = OPERATING_SYSTEM_AUTH | DATABASE_AUTH
    #Leave username and password blank if using OPERATING_SYSTEM_AUTH
    username = gdb_admin_user_name
    password = gdb_admin_password
    version = sde.DEFAULT
    
    
    # Set local variables
    if os.name.lower() == "nt":
       slashsyntax = "\\"
       if os.environ.get("TEMP") == None:
          temp = "c:\\temp"
       else:
          temp = os.environ.get("TEMP")
    else:
       slashsyntax = "/"
       if os.environ.get("TMP") == None:
          temp = "/usr/tmp"
       else:
          temp = os.environ.get("TMP")
    
    Connection_File_Name = temp + slashsyntax + "connection.sde"
    
    # Check for the .sde file and delete it if present
    if os.path.exists(Connection_File_Name):
       os.remove(Connection_File_Name)
    
    #Variable defined within the script; other variable options commented out at the end of the line
    saveUserInfo = "SAVE_USERNAME" #DO_NOT_SAVE_USERNAME
    saveVersionInfo = "SAVE_VERSION" #DO_NOT_SAVE_VERSION
    
    print "Creating ArcSDE Connection File..."
    # Create ArcSDE Connection File
    # Usage: out_folder_path, out_name, server, service, database, account_authentication, username, password, save_username_password
    arcpy.CreateArcSDEConnectionFile_management(temp, "connection.sde", server, service, database, account_authentication, username, password, saveUserInfo, version, saveVersionInfo)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print 'Rebuild Complete'
    

    In diesem Beispiel stellt der sde-Benutzer eine Verbindung mit einer PostgreSQL-Datenbank her:

    # Name: RSysIdxpg.py
    # Description: Rebuilds indexes on the sde_states, sde_state_lineages,
    # and sde_mv_tables_modified tables in an enterprise geodatabase
    # in PostgreSQL.
    
    # Author: Esri
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    server = servername
    service = "5151 | sde:postgresql:servername"
    database = database_name
    account_authentication = DATABASE_AUTH
    username = gdb_admin_user_name
    password = gdb_admin_password
    version = sde.DEFAULT
    
    
    # Set local variables
    if os.name.lower() == "nt":
       slashsyntax = "\\"
       if os.environ.get("TEMP") == None:
          temp = "c:\\temp"
       else:
          temp = os.environ.get("TEMP")
    else:
       slashsyntax = "/"
       if os.environ.get("TMP") == None:
          temp = "/usr/tmp"
       else:
          temp = os.environ.get("TMP")
    
    Connection_File_Name = temp + slashsyntax + "connection.sde"
    
    # Check for the .sde file and delete it if present
    if os.path.exists(Connection_File_Name):
       os.remove(Connection_File_Name)
    
    #Variable defined within the script; other variable options commented out at the end of the line
    saveUserInfo = "SAVE_USERNAME" #DO_NOT_SAVE_USERNAME
    saveVersionInfo = "SAVE_VERSION" #DO_NOT_SAVE_VERSION
    
    print "Creating ArcSDE Connection File..."
    # Create ArcSDE Connection File
    # Usage: out_folder_path, out_name, server, service, database, account_authentication, username, password, save_username_password
    arcpy.CreateArcSDEConnectionFile_management(temp, "connection.sde", server, service, database, account_authentication, username, password, saveUserInfo, version, saveVersionInfo)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print 'Rebuild Complete'
    

    In diesem Beispiel stellt der sde-Benutzer eine Verbindung mit einer DB2-Datenbank her:

    # Name: RSysIdxDb2.py
    # Description: Rebuilds indexes on the states, state_lineages,
    # and mv_tables_modified tables in an enterprise geodatabase
    # in DB2.
    
    # Author: Esri
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    server = servername
    service = "5151 | sde:db2"
    database = db_alias
    account_authentication = OPERATING_SYSTEM_AUTH | DATABASE_AUTH
    #Leave username and password blank if using OPERATING_SYSTEM_AUTH
    username = gdb_admin_user_name
    password = gdb_admin_password
    version = sde.DEFAULT
    
    
    # Set local variables
    if os.name.lower() == "nt":
       slashsyntax = "\\"
       if os.environ.get("TEMP") == None:
          temp = "c:\\temp"
       else:
          temp = os.environ.get("TEMP")
    else:
       slashsyntax = "/"
       if os.environ.get("TMP") == None:
          temp = "/usr/tmp"
       else:
          temp = os.environ.get("TMP")
    
    Connection_File_Name = temp + slashsyntax + "connection.sde"
    
    # Check for the .sde file and delete it if present
    if os.path.exists(Connection_File_Name):
       os.remove(Connection_File_Name)
    
    #Variable defined within the script; other variable options commented out at the end of the line
    saveUserInfo = "SAVE_USERNAME" #DO_NOT_SAVE_USERNAME
    saveVersionInfo = "SAVE_VERSION" #DO_NOT_SAVE_VERSION
    
    print "Creating ArcSDE Connection File..."
    # Create ArcSDE Connection File
    # Usage: out_folder_path, out_name, server, service, database, account_authentication, username, password, save_username_password
    arcpy.CreateArcSDEConnectionFile_management(temp, "connection.sde", server, service, database, account_authentication, username, password, saveUserInfo, version, saveVersionInfo)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print 'Rebuild Complete'
    

    In diesem Beispiel stellt der sde-Benutzer eine Verbindung mit einer Informix-Datenbank her:

    # Name: RSysIdxIDS.py
    # Description: Rebuilds indexes on the states, state_lineages,
    # and mv_tables_modified tables in an enterprise geodatabase
    # in Informix IDS.
    
    # Author: Esri
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    server = servername
    service = "5151 | sde:informix"
    database = odbc_dsn
    account_authentication = OPERATING_SYSTEM_AUTH | DATABASE_AUTH
    #Leave username and password blank if using OPERATING_SYSTEM_AUTH
    username = gdb_admin_user_name
    password = gdb_admin_password
    version = sde.DEFAULT
    
    
    # Set local variables
    if os.name.lower() == "nt":
       slashsyntax = "\\"
       if os.environ.get("TEMP") == None:
          temp = "c:\\temp"
       else:
          temp = os.environ.get("TEMP")
    else:
       slashsyntax = "/"
       if os.environ.get("TMP") == None:
          temp = "/usr/tmp"
       else:
          temp = os.environ.get("TMP")
    
    Connection_File_Name = temp + slashsyntax + "connection.sde"
    
    # Check for the .sde file and delete it if present
    if os.path.exists(Connection_File_Name):
       os.remove(Connection_File_Name)
    
    #Variable defined within the script; other variable options commented out at the end of the line
    saveUserInfo = "SAVE_USERNAME" #DO_NOT_SAVE_USERNAME
    saveVersionInfo = "SAVE_VERSION" #DO_NOT_SAVE_VERSION
    
    print "Creating ArcSDE Connection File..."
    # Create ArcSDE Connection File
    # Usage: out_folder_path, out_name, server, service, database, account_authentication, username, password, save_username_password
    arcpy.CreateArcSDEConnectionFile_management(temp, "connection.sde", server, service, database, account_authentication, username, password, saveUserInfo, version, saveVersionInfo)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print 'Rebuild Complete'
    
  2. Nachdem Sie das Skript geändert haben, um die Verbindungsinformationen einzuschließen, planen Sie das Skript so, dass es jede Nacht zu einem bestimmten Zeitpunkt ausgeführt wird.
    • Öffnen Sie unter Windows die Aufgabenplanung in der Systemsteuerung, und verwenden Sie den Assistenten, um einen geplanten Task hinzuzufügen. Wenn Sie gefragt werden, welches Programm ausgeführt werden soll, wechseln Sie zum Python-Skript.
    • Erstellen Sie unter Linux eine cron-Textdatei, die Informationen zu Tag und Uhrzeit für die Ausführung des Skripts enthält, und laden Sie dann die Datei mit dem crontab-Programm in cron.

      Die folgenden Informationen legen z. B. das Python-Skript (rsysidxdb2.py genannt) so fest, dass es jeden Mittwoch um 22:00 Uhr ausgeführt wird:

      0 22 * * 3 /usr/bin/rsysidxdb2.py

      Informationen zur Verwendung von cron finden Sie auf den Linux-man-Seiten zu Ihrer Linux-Installation.
9/11/2013