ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

重新构建系统表索引

在 Standard 或 Advanced 许可等级下可用。

  • 使用重建索引工具
  • 计划 Python 脚本

数据库索引用于快速确定符合查询谓词过滤器的行。大多数地理数据库系统表都具有索引,但在版本化企业级地理数据库中,states、state_lineages 和 mv_tables_modified 系统表很容易会有大量更改,因此最经常需要重新构建索引。作为数据库管理员,您可以使用重建索引地理处理工具对 IBM Db2、Microsoft SQL Server、Oracle 或 PostgreSQL 中的地理数据库的这些表重新构建索引。

在编辑量大的版本化(传统)地理数据库中,可以在夜间更新 states、state_lineages 和 mv_tables_modified 表的索引。要执行此操作,可以创建独立 Python 脚本,此脚本可调用重建索引工具,并使用 Windows 计划任务或 cron 作业安排其运行。

提示:

数据所有者还可以使用重建索引工具重新构建其数据的属性和空间索引。有关详细信息,请参阅重新构建数据集索引。

使用重建索引工具

要使用重建索引工具重新构建 states、state_lineages 和 mv_tables_modified 地理数据库系统表的索引,请执行以下操作:

  1. 启动 ArcGIS Desktop 客户端并以地理数据库管理员身份连接到地理数据库。
  2. 打开重建索引地理处理工具。

    该工具位于“数据管理”工具箱的“地理数据库管理”工具集中。

  3. 使用步骤 1 中创建的连接作为输入数据库连接。
  4. 选中包括系统表复选框。
  5. 取消选中仅重建增量表。
  6. 单击确定 (ArcMap) 或运行 (ArcGIS Pro)。

计划 Python 脚本

要运行该脚本,您必须能够以地理数据库管理员身份连接到地理数据库。您可以创建连接文件 (.sde) 并从脚本指向该文件,或者直接在脚本中键入连接信息。下一步,使用“Windows 计划任务”或 Linux cron 后台程序安排该脚本运行。

  1. 将以下脚本之一复制到已安装 Python 和下列 ArcGIS 产品之一的计算机:
    • ArcGIS Desktop(Desktop Standard 或 Desktop Advanced)
    • 具有 Geodatabase Update 扩展模块的 ArcGIS Engine
    • ArcGIS Server

    使用特定于您的站点的信息修改脚本。

    以下示例脚本包含连接到 Oracle 数据库以更新 states、state_lineages 和 mv_tables_modified 系统表索引所需的信息:

    # Name: RSysIdxOracle.py
    # Description: Rebuilds indexes on the states, state_lineages,
    # and mv_tables_modified tables in an enterprise geodatabase
    # in Oracle.
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    platform = ORACLE
    instance = "myserver/orcl"
    account_authentication = OPERATING_SYSTEM_AUTH | DATABASE_AUTH
    #Leave username and password blank if using OPERATING_SYSTEM_AUTH
    username = gdb_admin
    password = gdb_admin_password
    
    
    # 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
    
    print ("Creating Database Connection File...")
    # Create Database Connection File
    # Usage: out_folder_path, out_name, database_platform, instance, account_authentication, username, password, save_user_pass
    arcpy.CreateDatabaseConnectionFile_management(temp, "connection.sde", platform, instance, account_authentication, username, password, saveUserInfo)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print ("Rebuild Complete")
    

    以下示例脚本包含使用操作系统验证的 dbo 用户连接到 SQL Server 并更新 sde_states、sde_state_lineages 和 sde_mv_tables_modified 系统表索引所需的信息:

    # 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.
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    platform = SQL_SERVER
    instance = sqlserver_instance_name
    account_authentication = OPERATING_SYSTEM_AUTH
    database = database_name
    
    
    # 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)
    
    print ("Creating Database Connection File...")
    # Create Database Connection File
    # Usage: out_folder_path, out_name, database_platform, instance, account_authentication, database
    arcpy.CreateDatabaseConnectionFile_management(temp, "connection.sde", platform, instance, account_authentication, database)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print ("Rebuild Complete")
    

    在以下示例中,sde 用户连接到 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.
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    platform = POSTGRESQL
    instance = pg_cluster
    account_authentication = DATABASE_AUTH
    username = gdb_admin
    password = gdb_admin_password
    database = database_name
    
    
    # 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
    
    print ("Creating Database Connection File...")
    # Create Database Connection File
    # Usage: out_folder_path, out_name, database_platform, instance, account_authentication, username, password, save_user_pass, database
    arcpy.CreateDatabaseConnectionFile_management(temp, "connection.sde", platform, instance, account_authentication, username, password, saveUserInfo, database)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print ("Rebuild Complete")
    

    在以下示例中,sde 用户连接到 DB2 数据库:

    # Name: RSysIdxDb2.py
    # Description: Rebuilds indexes on the states, state_lineages,
    # and mv_tables_modified tables in an enterprise geodatabase
    # in DB2.
    
    # Import system modules
    import sys
    import arcpy
    import os
    
    # Provide connection information
    platform = DB2
    instance = db2gdb
    account_authentication = OPERATING_SYSTEM_AUTH | DATABASE_AUTH
    #Leave username and password blank if using OPERATING_SYSTEM_AUTH
    username = sde
    password = gdb_admin_password
    
    
    # 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
    
    print ("Creating Database Connection File...")
    # Create Database Connection File
    # Usage: out_folder_path, out_name, database_platform, instance, account_authentication, username, password, save_user_pass
    arcpy.CreateDatabaseConnectionFile_management(temp, "connection.sde", platform, instance, account_authentication, username, password, saveUserInfo)
    
    # Rebuild indexes on system tables
    arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL")
    print ("Rebuild Complete")
    
  2. 修改脚本以包含连接信息后,可安排脚本在每晚特定的时间运行。
    • 在 Windows 中,从控制面板打开“计划任务”并使用向导添加计划任务。当系统询问要运行哪个程序时,浏览至您的 Python 脚本。
    • 在 Linux 中,创建一个 cron 文本文件,其中包含希望脚本运行的日期和时间信息,然后使用 crontab 程序将该文件加载到 cron 中。

      例如,以下信息将 Python 脚本(名为 rsysidxdb2.py)设置为在每个星期三晚上 10:00 运行。:

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

      有关 cron 的使用信息,请参阅随 Linux 安装提供的 Linux 手册页。

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2019 Esri. | 隐私政策 | 法律声明