在 Standard 或 Advanced 许可等级下可用。
数据库索引用于快速确定符合查询谓词过滤器的行。大多数地理数据库系统表都具有索引,但在版本化企业级地理数据库中,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 地理数据库系统表的索引,请执行以下操作:
- 启动 ArcMap 或 ArcCatalog 并以地理数据库管理员身份连接到地理数据库。
- 打开重建索引地理处理工具。
该工具位于“数据管理”工具箱的“地理数据库管理”工具集中。
- 使用您在步骤 1 中创建的连接作为输入工作空间。
- 选中系统表复选框。
- 单击确定运行工具。
计划 Python 脚本
要运行该脚本,您必须能够以地理数据库管理员身份连接到地理数据库。您可以创建连接文件 (.sde) 并从脚本指向该文件,或者直接在脚本中键入连接信息。下一步,使用“Windows 计划任务”或 Linux cron 后台程序安排该脚本运行。
- 将以下脚本之一复制到已安装 Python 和下列 ArcGIS 客户端之一的计算机:
- ArcGIS for Desktop(Standard 或 Advanced)
- 具有 Geodatabase Update 扩展模块的 ArcGIS Engine
- ArcGIS Runtime
- ArcGIS for 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. # Author: Esri # Import system modules import sys import arcpy import os # Provide connection information database_platform = Oracle instance = Oracle_instance 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 database connection file..." # Usage: out_folder_path, out_name, database_platform, instance, account_authentication, username, password, saveUserInfo, version, saveVersionInfo arcpy.CreateDatabaseConnection_management(temp, "connection.sde", database_platform, instance, account_authentication, username, password, saveUserInfo, version, saveVersionInfo) # 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. # Author: Esri # Import system modules import sys import arcpy import os # Provide connection information database_platform = SQL_Server instance = dbms_instance_name account_authentication = OPERATING_SYSTEM_AUTH | DATABASE_AUTH database = database_name #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 database connection file..." # Usage: out_folder_path, out_name, database_platform, instance, account_authentication, username, password, saveUserInfo, database, version, saveVersionInfo arcpy.CreateDatabaseConnection_management(temp, "connection.sde", instance, account_authentication, username, password, saveUserInfo, database, version, saveVersionInfo) # 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. # Author: Esri # Import system modules import sys import arcpy import os # Provide connection information database_platform = PostgreSQL instance = 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 database connection file..." # Usage: out_folder_path, out_name, database_platform, instance, account_authentication, username, password, saveUserInfo, database, version, saveVersionInfo arcpy.CreateDatabaseConnection_management(temp, "connection.sde", instance, account_authentication, username, password, saveUserInfo, database, version, saveVersionInfo) # 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. # Author: Esri # Import system modules import sys import arcpy import os # Provide connection information database_platform = DB2 instance = 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 database connection file..." # Usage: out_folder_path, out_name, database_platform, instance, account_authentication, username, password, saveUserInfo, version, saveVersionInfo arcpy.CreateDatabaseConnection_management(temp, "connection.sde", database_platform, instance, account_authentication, username, password, saveUserInfo, version, saveVersionInfo) # Rebuild indexes on system tables arcpy.RebuildIndexes_management(Connection_File_Name, "SYSTEM", "", "ALL") print 'Rebuild Complete'
- 修改脚本以包含连接信息后,可安排脚本在每晚特定的时间运行。
- 在 Windows 中,从控制面板打开“计划任务”并使用向导添加计划任务。当系统询问要运行哪个程序时,浏览至您的 Python 脚本。
- 在 Linux 中,创建一个 cron 文本文件,其中包含希望脚本运行的日期和时间信息,然后使用 crontab 程序将该文件加载到 cron 中。
例如,以下信息将 Python 脚本(名为 rsysidxdb2.py)设置为在每个星期三晚上 10:00 运行:
0 22 * * 3 /usr/bin/rsysidxdb2.py
有关 cron 的使用信息,请参阅随 Linux 安装提供的 Linux 手册页。