Upgrade Geodatabase (Data Management)

Summary

Upgrades a geodatabase to the latest ArcGIS release to take advantage of new functionality.

The current release of ArcGIS Pro or ArcGIS Server must be installed on the computer that will run the upgrade.

Usage

  • The Upgrade Geodatabase tool accepts a file geodatabase or an enterprise geodatabase connection file as input.

  • You cannot upgrade enterprise geodatabases from ArcGIS Pro with a Basic license.

  • Before you upgrade an enterprise geodatabase, you must perform the preparatory steps needed for the database management system you are using, including creating a backup of the database. For Oracle and for geodatabases in PostgreSQL that use the ST_Geometry type, you must download the DatabaseSupport folder from My Esri to obtain a new ST_Geometry library. For other preparatory steps, see the following topics:

  • You must check the Perform Pre-Requisite Check parameter, the Upgrade Geodatabase parameter, or both. You cannot run the tool until you check at least one of these parameters.

  • Use the prerequisite check before upgrading the geodatabase to determine if it is ready for upgrading. If any prerequisites are not met, an error is logged in the geoprocessing history. This saves you from starting the upgrade only to have it fail due to one of these prerequisites not having been met. If any checks fail, you must correct the problem and restart the upgrade process.

  • Upgrades from beta versions of the geodatabase are not supported.

  • The Perform Pre-Requisite Check parameter runs different checks for each type of geodatabase. For file geodatabases, it determines if any of the following are true:

    • The geodatabase is read-only.
    • There are no other users connected to the geodatabase.
    • The current connection is not editing data in the geodatabase.
    • All the information in the current geodatabase system tables can be opened.
    • For enterprise geodatabases, it determines if the following criteria are met:
      • The connected user has the appropriate privileges to upgrade the geodatabase.
      • The connected user is not editing data in the geodatabase.
      • No other users are connected to the geodatabase.
      • The database is enabled to support XML data types.
      • All the information in the current geodatabase system tables can be opened.
      • For geodatabases in Oracle and for geodatabases in PostgreSQL that use the ST_Geometry type, it detects whether the database can access the current version of the ST_Geometry library.

Parameters

LabelExplanationData Type
Input Geodatabase

The geodatabase to upgrade. When upgrading an enterprise geodatabase, specify a database connection file (.sde) that connects to the geodatabase as the geodatabase administrator.

Workspace
Perform Pre-Requisite Check

Specifies whether the prerequisite check will be run before upgrading the geodatabase.

  • Unchecked—The prerequisite check will not be run. This is the default.
  • Checked—The prerequisite check will be run before upgrading the geodatabase.
Boolean
Upgrade Geodatabase

Specifies whether the input geodatabase will be upgraded to match the release of the ArcGIS client that is running the tool.

  • Unchecked—The geodatabase will not be upgraded. This is the default.
  • Checked—The geodatabase will be upgraded.
Boolean

Derived Output

LabelExplanationData Type
Updated Input Geodatabase

The updated geodatabase.

Workspace

arcpy.management.UpgradeGDB(input_workspace, input_prerequisite_check, input_upgradegdb_check)
NameExplanationData Type
input_workspace

The geodatabase to upgrade. When upgrading an enterprise geodatabase, specify a database connection file (.sde) that connects to the geodatabase as the geodatabase administrator.

Workspace
input_prerequisite_check

Specifies whether the prerequisite check will be run before upgrading the geodatabase.

  • NO_PREREQUISITE_CHECKThe prerequisite check will not be run.
  • PREREQUISITE_CHECKThe prerequisite check will be run before upgrading the geodatabase. This is the default.
Boolean
input_upgradegdb_check

Specifies whether the input geodatabase will be upgraded.

  • NO_UPGRADEThe geodatabase will not be upgraded.
  • UPGRADEThe geodatabase will be upgraded. This is the default.
Boolean

Derived Output

NameExplanationData Type
out_workspace

The updated geodatabase.

Workspace

Code sample

UpgradeGDB example 1 (Python window)

The following Python window script demonstrates how to use the UpgradeGDB function in immediate mode to upgrade a file geodatabase.

import arcpy
default_gdb = "C:/temp/Default.gdb"
arcpy.management.UpgradeGDB(default_gdb, "PREREQUISITE_CHECK", "UPGRADE")
UpgradeGDB example 2 (stand-alone)

The following stand-alone Python script demonstrates how to use the UpgradeGDB function in Python scripting to upgrade a file geodatabase.

 
# 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 example 3 (stand-alone script)

The following stand-alone Python script demonstrates how to use the UpgradeGDB function in Python scripting to upgrade an enterprise geodatabase using an existing .sde connection file:

# 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 example 4 (stand-alone script)

The following stand-alone Python script demonstrates how to use the UpgradeGDB function in Python scripting to upgrade an enterprise geodatabase:

"""
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)

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics