升级地理数据库 (数据管理)

摘要

将地理数据库升级至最新的 ArcGIS 版本以使用新功能。

必须在将运行升级的计算机上安装当前版本的 ArcGIS ProArcGIS Server

使用情况

  • 升级地理数据库工具接受文件地理数据库或企业级地理数据库连接文件作为输入。

  • 您不能从具有基本许可的 ArcGIS Pro 升级企业级地理数据库。

  • 在升级企业级地理数据库之前,您必须对正在使用的数据库管理系统执行所需的准备步骤,包括创建数据库的备份。 对于 Oracle 以及使用 ST_Geometry 类型的 PostgreSQL 中的地理数据库,您必须从 My Esri 下载 DatabaseSupport 文件夹以获取新的 ST_Geometry 库。 有关其他准备步骤,请参阅以下主题:

  • 您必须选中执行必要的先行检查参数或升级地理数据库参数,或者同时选中这两个参数。 必须至少先选中其中一个参数,您才可以运行该工具。

  • 在升级地理数据库之前,请使用先决条件检查来确定其是否已准备好进行升级。 如果不满足任何先决条件,则会在地理处理历史记录中记录一条错误。 这可以使您不会在升级过程中仅因为某个先决条件未得到满足而使其失败。 如果任意检查失败,您必须纠正问题并重新启动升级流程。

  • 不支持从地理数据库的测试版本进行升级。

  • 执行必要的先行检查参数针对每个类型的地理数据库执行不同检查。 对于文件地理数据库,确定以下情况:

    • 地理数据库是否为只读。
    • 是否有其他用户连接到此地理数据库。
    • 当前连接是否未在地理数据库中编辑数据。
    • 当前地理数据库系统表中的所有信息是否可以打开。
    • 对于企业级地理数据库,确定是否满足以下条件:
      • 连接的用户具有升级地理数据库所需的适当权限。
      • 连接的用户现在没有对数据库中的数据进行编辑。
      • 无其他用户连接到数据库。
      • 数据库已启用支持 XML 数据类型。
      • 当前地理数据库系统表中的所有信息是否可以打开。
      • 对于 Oracle 中的地理数据库以及使用 ST_Geometry 类型的 PostgreSQL 中的地理数据库,它会检测数据库是否可以访问 ST_Geometry 库的当前版本。

参数

标注说明数据类型
输入地理数据库

要进行升级的地理数据库。 当升级企业级地理数据库时,指定以地理数据库管理员身份连接到地理数据库的数据库连接文件 (.sde)。

Workspace
执行必要的先行检查

指定是否会在升级地理数据库之前执行先决条件检查。

  • 未选中 - 不会执行先决条件检查。 这是默认设置。
  • 选中 - 将在升级地理数据库之前执行先决条件检查。
Boolean
升级地理数据库

指定是否会对输入地理数据库进行升级以与正在运行该工具的 ArcGIS 客户端版本相匹配。

  • 未选中 - 不会升级地理数据库。 这是默认设置。
  • 选中 - 将升级地理数据库。
Boolean

派生输出

标注说明数据类型
更新的输入地理数据库

更新的地理数据库。

Workspace

arcpy.management.UpgradeGDB(input_workspace, input_prerequisite_check, input_upgradegdb_check)
名称说明数据类型
input_workspace

要进行升级的地理数据库。 当升级企业级地理数据库时,指定以地理数据库管理员身份连接到地理数据库的数据库连接文件 (.sde)。

Workspace
input_prerequisite_check

指定是否会在升级地理数据库之前执行先决条件检查。

  • NO_PREREQUISITE_CHECK不会执行先决条件检查。
  • PREREQUISITE_CHECK将在升级地理数据库之前执行先决条件检查。 这是默认设置。
Boolean
input_upgradegdb_check

指定是否会升级输入地理数据库。

  • NO_UPGRADE不会升级地理数据库。
  • UPGRADE将升级地理数据库。 这是默认设置。
Boolean

派生输出

名称说明数据类型
out_workspace

更新的地理数据库。

Workspace

代码示例

UpgradeGDB 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 UpgradeGDB 函数升级文件地理数据库:

import arcpy
default_gdb = "C:/temp/Default.gdb"
arcpy.management.UpgradeGDB(default_gdb, "PREREQUISITE_CHECK", "UPGRADE")
UpgradeGDB 示例 2(独立脚本)

以下独立 Python 脚本演示了如何在 Python 脚本中使用 UpgradeGDB 函数升级文件地理数据库:

 
# Description: upgrade a geodatabase
 
# Import arcpy module
import arcpy

# Local variables:
default_gdb = "C:/temp/Default.gdb"

# Process: Upgrade Geodatabase
arcpy.management.UpgradeGDB(default_gdb, "PREREQUISITE_CHECK", "UPGRADE")
UpgradeGDB 示例 3(独立脚本)

以下独立 Python 脚本演示了如何在 Python 脚本中通过现有 .sde 连接文件使用 UpgradeGDB 函数升级企业级地理数据库:

# Description: upgrade a geodatabase

# Import arcpy module
import arcpy

# Local variables:
default_gdb = "C:/connections/gdbconnection.sde"

# Process: Upgrade Geodatabase
arcpy.management.UpgradeGDB(default_gdb, "PREREQUISITE_CHECK", "UPGRADE")
UpgradeGDB 示例 4(独立脚本)

以下独立 Python 脚本演示了如何在 Python 脚本中使用 UpgradeGDB 函数升级企业级地理数据库:

"""
Name: upgrade_gdb.py
Description: Provide connection information to an Enterprise geodatabase 
and upgrade the geodatabase
Type upgrade_gdb.py -h or upgrade_gdb.py --help for usage
"""

# Import system modules
import arcpy
import os
import optparse
import sys


# Define usage and version
parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 2.0; valid for 10.1 only")

#Define help and options
parser.add_option ("--DBMS", dest="Database_type", type="choice", choices=['SQLSERVER', 'ORACLE', 'POSTGRESQL', 'DB2','INFORMIX','DB2ZOS',''], default="", help="Type of enterprise DBMS:  SQLSERVER, ORACLE, or POSTGRESQL.")
parser.add_option ("-i", dest="Instance", type="string", default="", help="DBMS instance name")
parser.add_option ("--auth", dest="account_authentication", type ="choice", choices=['DATABASE_AUTH', 'OPERATING_SYSTEM_AUTH'], default='DATABASE_AUTH', help="Authentication type options (case-sensitive):  DATABASE_AUTH, OPERATING_SYSTEM_AUTH.  Default=DATABASE_AUTH")
parser.add_option ("-u", dest="User", type="string", default="", help="Geodatabase administrator user name")
parser.add_option ("-p", dest="Password", type="string", default="", help="Geodatabase administrator password")
parser.add_option ("--upgrade", dest="Upgrade", type="choice", choices=['TRUE', 'FALSE'], default="FALSE", help="Upgrade Options (case-sensitive):  TRUE=Perform Pre-requisite check and upgrade geodatabase, FALSE=Perform Pre-requisite check only.  Default=FALSE")                   
parser.add_option ("-D", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")


# Check if value entered for option
try:
	(options, args) = parser.parse_args()

	
#Check if no system arguments (options) entered
	if len(sys.argv) == 1:
		print("%s: error: %s\n" % (sys.argv[0], "No command options given"))
		parser.print_help()
		sys.exit(3)

	#Usage parameters for spatial database connection to upgrade
	account_authentication = options.account_authentication.upper()
	username = options.User.lower() 
	password = options.Password	
	do_upgrade = options.Upgrade
	database = options.Database.lower()
	database_type = options.Database_type.upper()
	instance = options.Instance
	
	if (database_type == ""):
		print("\nDatabase type must be specified!\n")
		parser.print_help()
		sys.exit(3)
	
	if (database_type == "SQLSERVER"):
		database_type = "SQL_SERVER"
	
	# Get the current product license
	product_license=arcpy.ProductInfo()
	
	# Checks required license level to upgrade
	if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
		print("\n" + product_license + " license found!" + "  Enterprise geodatabase upgrade requires an ArcGIS Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS Server license.")
		sys.exit("Re-authorize ArcGIS before upgrading.")
	else:
		print("\n" + product_license + " license available!  Continuing to upgrade...")
		arcpy.AddMessage("+++++++++")
	
	# Local variables
	instance_temp = instance.replace("\\","_")
	instance_temp = instance_temp.replace("/","_")
	instance_temp = instance_temp.replace(":","_")
	Conn_File_NameT = instance_temp + "_" + database + "_" + username     
	
	if os.environ.get("TEMP") == None:
		temp = "c:\\temp"	
	else:
		temp = os.environ.get("TEMP")
	
	if os.environ.get("TMP") == None:
		temp = "/usr/tmp"		
	else:
		temp = os.environ.get("TMP")  
	
	Connection_File_Name = Conn_File_NameT + ".sde"
	Connection_File_Name_full_path = temp + os.sep + Conn_File_NameT + ".sde"
	
	# Check for the .sde file and delete it if present
	arcpy.env.overwriteOutput=True
	if os.path.exists(Connection_File_Name_full_path):
		os.remove(Connection_File_Name_full_path)
	
	print("\nCreating Database Connection File...\n")
	# Process: Create Database Connection File...
	# Usage:  out_file_location, out_file_name, DBMS_TYPE, instnace, database, account_authentication, username, password, save_username_password(must be true)
	arcpy.CreateDatabaseConnection_management(out_folder_path=temp, out_name=Connection_File_Name, database_platform=database_type, instance=instance, database=database, account_authentication=account_authentication, username=username, password=password, save_user_pass="TRUE")
        for i in range(arcpy.GetMessageCount()):
		if "000565" in arcpy.GetMessage(i):   #Check if database connection was successful
			arcpy.AddReturnMessage(i)
			arcpy.AddMessage("\n+++++++++")
			arcpy.AddMessage("Exiting!!")
			arcpy.AddMessage("+++++++++\n")
			sys.exit(3)            
		else:
			arcpy.AddReturnMessage(i)
			arcpy.AddMessage("+++++++++\n")
			
	# Check whether geodatabase needs upgrade
	isCurrent = arcpy.Describe(Connection_File_Name_full_path).currentRelease
	
	if isCurrent == True:
		print("The geodatabase is already at the current release and cannot be upgraded!")
		sys.exit("Upgrade did not run.")
	
	
	# Process: Upgrade geodatabase...
	try:
		if do_upgrade.lower() == "true":
			print("Upgrading Geodatabase...\n")
			arcpy.UpgradeGDB_management(input_workspace=Connection_File_Name_full_path, input_prerequisite_check="PREREQUISITE_CHECK", input_upgradegdb_check="UPGRADE")
			for i in range(arcpy.GetMessageCount()):
				arcpy.AddReturnMessage(i)
			arcpy.AddMessage("+++++++++\n")
	
		else:
			print("Running Pre-Requisite Check...\n")
			arcpy.UpgradeGDB_management(input_workspace=Connection_File_Name_full_path, input_prerequisite_check="PREREQUISITE_CHECK", input_upgradegdb_check="NO_UPGRADE")
			for i in range(arcpy.GetMessageCount()):
				arcpy.AddReturnMessage(i)
			arcpy.AddMessage("+++++++++\n")
		
	        
	except:
		for i in range(arcpy.GetMessageCount()):
			arcpy.AddReturnMessage(i)
		
	if os.path.exists(Connection_File_Name_full_path):
		os.remove(Connection_File_Name_full_path)
	
#Check if no value entered for option	
except SystemExit as e:
	if e.code == 2:
		parser.usage = ""
		print("\n")
		parser.print_help()
		parser.exit(2)

许可信息

  • Basic: 是
  • Standard: 是
  • Advanced: 是

相关主题