Actualizar estadísticas en las tablas del sistema de geodatabase utilizando la secuencia de comandos de Python

Estadísticas de bases de datos utilizadas por el optimizador DBMS para seleccionar el plan óptimo de ejecución para que pueda ejecutarse la solicitud. Debería actualizar las estadísticas después de que el contenido de una tabla cambie significativamente. En el caso de las tablas del sistema geodatabase ArcSDE, deberían actualizarse las estadísticas después de que tablas o clases de entidades nuevas hayan sido agregadas a geodatabase, se haya llevado a cabo un gran número de ediciones versionadas, o geodatabase se haya comprimido.

Debido a que actualizar las estadísticas de base de datos puede ser una operación intensiva de E/S, es posible que desee hacer esto mientras la mayoría de usuarios está desconectados de la base de datos. Puede escribir una secuencia de comandos Python para invocar la herramienta Analizar datasets para actualizar estadísticas en las tablas del sistema de la geodatabase de ArcSDE y programar la secuencia de comandos para que se ejecute durante la noche. Puede utilizar Tareas programadas en Windows para establecer una hora para ejecutar su secuencia de comandos. En Linux, puede configurar un trabajo de cron para ejecutar la secuencia de comandos.

Pasos:
  1. Copie una de las siguientes secuencias de comandos en una computadora en la cual esté instalado Phyton y uno de los siguientes clientes de ArcGIS:
    • ArcGIS for Desktop (Standardo Advanced)
    • ArcGIS Engine con la extensión Geodatabase Update
    • ArcGIS Engine
    • ArcGIS for Server (Standard o Advanced)

    Altere la secuencia de comando con información específica para su sitio.

    Esta secuencia de comandos utiliza un archivo de conexión de base de datos existente en la máquina local para conectarse a la base de datos y ejecutar la secuencia de comandos:

    # Name: UStatsSysTbls.py # Description: Updates statistics on enterprise geodatabase   # system tables 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 analyze datasets for system tables arcpy.AnalyzeDatasets_management(workspace, "SYSTEM", "", "","","") print "Analyze Complete"
    

    Esta secuencia de comandos contiene la información necesaria para conectarse a una base de datos Oracle para actualizar las estadísticas en las tablas del sistema:

    # Name: UStatsSysOracle.py
    # Description: Updates statistics on system 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)
    
    # Update statistics on system tables
    arcpy.AnalyzeDatasets_management(Connection_File_Name, "SYSTEM","","","","")
    print "Analyze Complete"
    

    Esta secuencia de comandos de muestra contiene información para utilizar un usuario dbo autenticado del sistema operativo para conectarse a SQL Server y actualizar las estadísticas en las tablas del sistema:

    # Name: UStatsSysSqlServer.py
    ## Description: Updates statistics on system 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)
    
    # Update statistics on system tables
    arcpy.AnalyzeDatasets_management(Connection_File_Name, "SYSTEM","","","","")
    print "Analyze Complete"
    

    En este ejemplo, el usuario sde se conecta a la base de datos PostgreSQL:

    # 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'
    

    En este ejemplo, el usuario sde se conecta a la base de datos DB2:

    # Name: UStatsSysDb2.py
    # Description: Updates statistics on system 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)
    
    # Update statistics on system tables
    arcpy.AnalyzeDatasets_management(Connection_File_Name, "SYSTEM","","","","")
    print "Analyze Complete"
    

    En este ejemplo, el usuario sde se conecta a la base de datos Informix:

    # Name: UStatsSysIDS.py
    # Description: Updates statistics on system 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)
    
    # Update statistics on system tables
    arcpy.AnalyzeDatasets_management(Connection_File_Name, "SYSTEM","","","","")
    print "Analyze Complete"
    
  2. Después de que altere la secuencia de comandos para que incluya la información de conexión, programe la secuencia de comandos para que se ejecute a una hora específica cada noche.
    • En Windows, abra Tareas programadas en el Panel de control y utilice el asistente para agregar una tarea programada. Cuándo se le pregunte qué programa ejecutar, vaya a su secuencia de comandos Python.
    • En Linux, cree un archivo de texto cron que incluya información sobre el día y la hora que desea ejecutar la secuencia de comandos, luego cargue el archivo en cron utilizando el programa crontab.

      Por ejemplo, la información siguiente establece la secuencia de comandos Python (denominada ustatssysids.py) para que se ejecute cada sábado a la 1:30 a.m.:

      30 1 * * 6 /usr/bin/ustatssysids.py

      Vea las páginas Man de Linux que se proporcionan con la instalación Linux para obtener información sobre cron.
9/11/2013