升级 PostgreSQL 中的地理数据库

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

升级企业级地理数据库的目标是更新地理数据库系统表、存储过程、类型和函数,以利用新功能和漏洞修复。

安装新版本的 ArcGIS 客户端,或将补丁包、修补程序或热修复程序应用到现有安装并升级地理数据库。

完成升级前的必需步骤,然后使用升级地理数据库地理处理工具Python 脚本升级地理数据库。

在升级之前

在升级包括地理数据库在内的任何企业系统时,必须事前进行规划。 在开发或测试服务器上测试新版本,以确保其能够与所有客户端应用程序配合使用。

当您确定新系统可如预期运行时,即可安排升级;请确保有必要员工可以执行升级,并且他们具有完成分配的任务所需的权限。

注意以下事项:

  • 不支持对软件的测试版本或预发行版本进行升级。
  • 如果 PostgreSQL 数据库为受支持的版本,则可从 10.6.1、10.7.x、10.8.x 或 10.9.x 版本的地理数据库直接升级。
  • 不提供将地理数据库降级到先前版本的正式机制。 升级到较新版本后,如果要降级地理数据库,则可以从包含较旧地理数据库版本的备份文件中恢复数据库。

以下是升级地理数据库之前需要完成的步骤清单:

  1. 请阅读 ArcGIS 的 PostgreSQL 数据库要求以确认 Esri 支持要使用的 PostgreSQL 和 ArcGIS 版本组合。

    如果需要升级 PostgreSQL 数据库,有关数据库管理系统中的新功能及升级方式的信息,请参阅 PostgreSQL 文档。 请记住升级后的数据库的名称和所有者必须与以前相同。 同时将数据库的 search_path 变量设置为 "$user"publicsde

  2. 确认地理数据库可以升级。

    要执行此操作,需将要移动到的 ArcGIS 客户端版本安装到计算机上。 如果安装 ArcGIS Pro,可连接至地理数据库并打开数据库属性对话框确定该地理数据库是否可以升级。 如果安装 ArcGIS Server(企业版),可使用 ArcPy Describe 函数来确定该地理数据库是否可以升级,如下所示。

    # Open Python.
    cd /arcgis/server/tools
    ./python
    
    # Create a connection to the geodatabase.
    arcpy.CreateDatabaseConnection_management("/tmp/",
                                              "egdb_connection.sde",
                                              "POSTGRESQL",
                                              "mypgdbcluster",
                                              "DATABASE_AUTH",
                                              "sde",
                                              "mysdepassword",
                                              "SAVE_USERNAME",
                                              "mypgdb")
    
    # Import ArcPy and check the geodatabase release.
    import arcpy
    
    isCurrent = arcpy.Describe('/tmp/egdb_connection.sde').currentRelease
    
    print isCurrent

    如果返回 False,则可升级地理数据库。 如果返回 True,则无需升级地理数据库。 请勿继续执行后续步骤。

  3. 创建数据库的备份。
  4. 移除任何您可能已添加到 ArcGIS 外部的地理数据库系统表中的自定义功能,例如触发器或其他索引。

    升级程序无法兼容对系统表的自定义修改。 如果类似的自定义修改禁止更改系统表方案,升级将失败。

  5. 为 sde 用户授予升级地理数据库所需的权限。

    有关所需权限,请参阅 PostgreSQL 中的地理数据库权限

  6. 确保没有与正在升级的地理数据库的连接。

    查看当前连接到地理数据库的用户列表,请转至 ArcGIS Pro 中的地理数据库管理对话框。

  7. 如果地理数据库使用 ST_Geometry 类型,请完成下一步。 否则,可以继续升级地理数据库

    如果您不确定地理数据库是否使用 ST_Geometry 类型,请以 sde 用户或超级用户身份从 SQL 客户端连接到数据库,然后检查 sde 用户方案中是否存在 ST_Geometry 函数。

  8. My Esri 下载 st_geometry 文件,并将其放置在 PostgreSQL 服务器上的 %PostgreSQL%\lib 目录 (Microsoft Windows) 或 PostgreSQL lib 目录 (Linux) 中。

    对于在 Linux 上安装 PostgreSQL,通过以 postgres 用户的身份运行 pg_config 实用程序,您可以确定 lib 目录的确切位置。 lib 位置通过 PGPKGLIBDIR 参数表示。

    确保使用适合 PostgreSQL 版本和服务器操作系统的库。 已使用 PostgreSQL 库版本对文件夹进行了标注。

    • 如果在 Linux 上运行 PostgreSQL 服务器,则作为超级用户登录到服务器并使用 FTP 将 st_geometry.so 文件传输到 PostgreSQL lib 目录下。
    • 如果要在 Windows 上运行 PostgreSQL 服务器,请将 st_geometry.dll 文件复制到 PostgreSQL 安装目录下的 lib 文件夹。

您现在可以升级地理数据库。

升级地理数据

可以使用 ArcGIS Desktop 中的升级地理数据库工具或使用在 ArcGIS 客户端计算机上运行的 Python 脚本升级地理数据库。

使用升级地理数据库工具

可通过以下任一方式打开升级地理数据库地理处理工具:

  • 数据管理工具箱中的地理数据库管理工具集
  • ArcGIS Pro数据库属性对话框内常规选项卡上的运行升级按钮

如果打开了数据库属性中的工具,则将使用地理数据库连接信息预填充输入地理数据库文本框。

Esri 建议选中先行检查升级地理数据库选项。 这样,在继续地理数据库升级之前,该工具将确认是否满足升级的先决条件。

先行检查将检测到地理数据库的其他活动连接、确定连接用户是否具有升级地理数据库所需的足够权限、确保数据库可支持 XML 列、确保所有数据集均可打开,以及确认数据库与库的版本相同。 如果未满足任意先决条件,则工具将终止。 再次运行升级过程之前,必须修正所有问题。

此检查的结果在地理处理工具对话框中报告。 如果检查(或升级)失败,其结果还将写入 c:\Users\<user name>\AppData\Local\ESRI\<ArcGIS product> 文件夹的 GDBUpgrade.log 文件中。

如果通过了所有检查,该工具将继续进行升级。 先行检查和升级的状态将在地理处理工具进度对话框中显示。 如果升级失败,则信息将写入 GDBUpgrade.log 文件。 其他信息将写入系统 TEMP 目录的 sde_setup.log 文件中。

运行脚本

要想升级地理数据库,请将这些示例脚本中的一个脚本复制到文本编辑器中。 更改任何变量值来与您的站点信息相匹配。

  • 如果具有作为 sde 用户身份进行连接的现有数据库连接文件,则应复制适用于您的操作系统的脚本,将其粘贴到文本编辑器中,并根据站点的具体信息来更改脚本,保存并关闭该文件,然后运行该脚本:
    # Name: upgradesdegdb_example.py
    # Description: Connect from a Windows computer 
    # with an existing database connection file 
    # and upgrade an enterprise geodatabase in PostgreSQL
    
    # Import arcpy module
    import arcpy
     
    # Local variables:
    Output_Workspace = "C:\\ArcGIS\connection_files\<Connection file>"
    Default_gdb = "C:\\ArcGIS\connection_files\<Connection file>"
    
    # Process: Upgrade Geodatabase
    arcpy.UpgradeGDB_management(Default_gdb, "PREREQUISITE_CHECK", "UPGRADE")
    # Name: upgradesdegdb_example.py
    # Description: Connect from a Linux computer 
    # with an existing database connection file 
    # and upgrade an enterprise geodatabase in PostgreSQL
    
    # Import arcpy module
    import arcpy
     
    # Local variables:
    Output_Workspace = "<user>/connections/<Connection_file>"
    Default_gdb = "<user>/connections/<Connection_file>"
    
    # Process: Upgrade Geodatabase
    arcpy.UpgradeGDB_management(Default_gdb, "PREREQUISITE_CHECK", "UPGRADE")
  • 如果计算机上没有用于编写升级脚本的数据库连接文件,则可复制以下脚本并在命令行中提供特定于您的站点的信息:
    """
    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)
    例如,如果将文本文件另存为 gdbupgrade,数据库群集为 mypgdbcluster 且数据库为 mypgdb,则应在命令提示符处输入以下内容:

    gdbupgrade --DBMS POSTGRESQL -i mypgdbcluster --auth DATABASE_AUTH -u sde -p mysdepassword --upgrade TRUE -D mypgdb