升级 PostgreSQL 中的地理数据库

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

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

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

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

在升级之前

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

在确定了新系统会按预期进行工作后,请计划升级;确保必要的工作人员均可执行升级并且他们拥有完成指派的任务所必需的权限。

注意如下事项:

  • 不支持对软件的测试版本或预发行版本进行升级。
  • 如果您的数据库是支持的版本,则可从 10.6.x、10.7.x、10.8.x 或 10.9.x 版本的地理数据库直接升级。
  • 不提供将地理数据库降级到先前版本的正式机制。 如果升级到较新版本后想要降级该地理数据库,则必须从备份文件中恢复旧数据库。
  • ST_Raster 存储不再受支持。 您必须在升级之前将现有 ST_Raster 数据转换为其他格式

以下为升级地理数据库之前应完成的步骤一览表:

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

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

  6. 在数据库中授予 sde 用户超级用户状态。

    要升级地理数据库,需要执行该操作。

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

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

  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 脚本升级地理数据库。

使用升级地理数据库工具

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

  • 数据管理工具箱中的地理数据库管理工具集
  • ArcMapArcCatalog数据库属性对话框常规选项卡上的升级地理数据库按钮。
  • 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 or UNIX 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