在 Windows 上的 PostgreSQL 中创建地理数据库

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

要在 PostgreSQL 数据库中创建地理数据库,请从 ArcGIS 客户端运行地理处理工具或 Python 脚本。 首先阅读先决条件,然后按照适合实际情况的说明进行操作。

请注意,本主题适用于 Microsoft Windows 服务器上的 PostgreSQL 安装程序。 如果已在 Linux 服务器上安装了 PostgreSQL,请参阅Linux 上的 PostgreSQL 中创建地理数据库

先决条件

要在 PostgreSQL 中创建地理数据库,需要执行以下操作:

  1. 确认您想使用的 ArcGIS、PostgreSQL 和操作系统组合相互兼容
  2. 获取 ArcGIS Server 密钥代码文件,并将其放置到用于创建地理数据库的 ArcGIS 客户端可访问的位置。
  3. 确定将创建地理数据库的人员(这会影响创建数据库的人员),以及运行哪个工具来创建地理数据库。 按照适合实际情况的说明进行操作:

您是 PostgreSQL 和地理数据库管理员

如果您行使数据库管理员和地理数据库管理员的角色,并知晓这两个登录角色的密码,则可以使用创建企业级地理数据库地理处理工具或 Python 脚本在 PostgreSQL 中创建地理数据库。

创建企业级地理数据库工具可令您轻松创建地理数据库,因为此工具可创建数据库对象并授予您所需的权限。 要达到此目的,应使用特定的默认设置。 下面介绍了创建企业级地理数据库工具的用途和所使用的设置:

  • 该工具使用 PostgreSQL 默认模板 (template1) 创建数据库。

    如果需要使用其他模板创建数据库,例如,要使用 postgis 模板,则必须在运行此工具前创建数据库。 然后便可以运行创建企业级地理数据库工具或脚本,并指定预先创建的数据库的名称。

  • 该工具在数据库集群中创建 sde 登录角色并授予其超级用户身份。

    sde 用户必须是超级用户才能创建地理数据库。

  • 还会在数据库中创建 sde 方案。

    地理数据库系统表、视图、函数和过程均存储在 sde 方案中。

  • 将 sde 用户设置为 sde 方案的所有者并向公共角色授予 sde 方案的使用权限。

    使用地理数据库的登录角色必须能够访问 sde 方案。 地理数据库登录角色可能尚不存在,因此,该工具将向公共角色授予使用权限。 创建地理数据库后,可以对该地理数据库的安全性进行加强,方法为撤消公共角色的 sde 方案使用权限并只向需要访问地理数据库的登录组和登录角色授予使用权限。

  • 该工具可创建地理数据库。

首先,您必须安装 PostgreSQL 并配置数据库集群。

安装并配置 PostgreSQL

按以下步骤设置 PostgreSQL 数据库集群以在 Windows 服务器上存储地理数据库:

  1. 获取并安装受支持的 PostgreSQL 版本并配置数据库集群。

    可从 My Esri 下载 PostgreSQL 安装程序。 如果使用此安装程序,则无需特定的非默认设置即可通过 ArcGIS 使用 PostgreSQL。 如果不想使用默认设置,则只需确保更改区域设置和位置设置即可。 或者,也可以自行获取 PostgreSQL 安装程序。

    有关安装和配置 PostgreSQL 的说明,请参阅 PostgreSQL 文档

  2. 将数据库集群配置为接受连接。

    其中包括更改 pg_hba.conf 文件以允许数据库集群接受远程连接。

  3. 安装用于创建地理数据库的 ArcGIS 客户端。

    通常,您可通过 ArcGIS ServerArcGIS DesktopDesktop StandardDesktop Advanced)创建地理数据库。 这些客户端通常安装在独立于 PostgreSQL 数据库集群的计算机上,但是不必一定采取此种安装方式。 请注意,虽然您可将 ArcGIS ServerPostgreSQL 安装在同一计算机上,但不建议您采用这种方式,因为数据库管理系统是内存密集型应用程序并将与 ArcGIS Server 争夺资源。

  4. 在用于存储数据库的数据库集群中创建表空间。 如果不创建表空间,则将使用 pg_default 表空间。

接下来,安装并配置 ArcGIS 客户端。

安装 ArcGIS 客户端

可安装 ArcGIS DesktopDesktop StandardDesktop Advanced)、具有 Geodatabase Update 扩展模块的 ArcGIS Engine Runtime 或 ArcGIS Server,然后运行 Python 脚本来创建地理数据库。 如果您想要运行创建企业级地理数据库地理处理工具,而非脚本,请安装 ArcGIS Desktop

注:

您需要一个 ArcGIS Server(企业版)密钥代码文件,以便在下一部分中授权地理数据库。 即使不在 ArcGIS Server 计算机上运行 Python 脚本来创建地理数据库,也必须安装和授权 ArcGIS Server 才能获取密钥代码文件。 可能需要将 ArcGIS Server 计算机中的密钥代码文件复制到可使用创建企业级地理数据库地理处理工具访问的位置。

安装用于创建地理数据库的 ArcGIS 客户端。 通常,您可通过 ArcGIS Server 安装程序或 ArcGIS DesktopDesktop StandardDesktop Advanced)创建地理数据库。

放置 st_geometry.dll 文件

必须将 st_geometry.dll 文件放置在 PostgreSQL lib 目录下,然后才能创建地理数据库。

可从 My Esri 获取 st_geometry.dll 文件。

注:

st_geometry.dll 需要使用 Microsoft Visual C++ Redistributable Package (x64)。 有关所需的软件包版本,请参阅 PostgreSQL 数据库要求。 如果 PostgreSQL 服务器上没有此软件包,可从 Microsoft 站点下载该包并安装。

将特定于正在使用的 PostgreSQL 版本的 st_geometry.dll 文件放置在 PostgreSQL lib 目录下。 如果未将正确的 st_geometry 库放置在 PostgreSQL lib 目录下,将无法创建地理数据库。

现在,您可以通过数据库集群和 ArcGIS 客户端创建地理数据库。

创建地理数据库

您可以运行 ArcGIS Desktop 中的创建企业级地理数据库工具或运行 ArcGIS DesktopArcGIS ServerArcGIS Engine 客户端的 Python 脚本来创建地理数据库。

运行创建企业级地理数据库工具

您可以运行 ArcGIS DesktopDesktop StandardDesktop Advanced)中的创建企业级地理数据库工具以在 PostgreSQL 数据库集群中创建数据库,并在数据库中创建地理数据库。

请遵照以下步骤在 ArcGIS Pro 中使用创建企业级地理数据库工具创建地理数据库:

  1. 启动 ArcGIS Pro
  2. 打开创建企业级地理数据库工具。

    您可以搜索或浏览到此工具,它位于“数据管理”工具箱的“地理数据库管理”工具集中。

  3. 数据库平台下拉列表中选择 PostgreSQL
  4. 实例文本框中输入 PostgreSQL 服务器的名称。
  5. 数据库文本框中,输入要创建的数据库(用来包含地理数据库)的名称。
    注:

    输入小写的数据库名称;PostgreSQL 中的地理数据库不支持大写和大小写混合的对象名称。如果您输入的数据库名称为大写形式或大小写混合形式,则 ArcGIS 会将其转换为小写形式。

  6. 您必须以 postgres 超级用户身份连接到数据库集群以创建数据库和其他对象;因此,数据库管理员文本框的默认值为 postgres。如果 postgres 超级用户具有其他名称,则在数据库管理员文本框中输入该名称。
  7. 数据库管理员密码文本框中输入 postgres 超级用户的密码。
  8. PostgreSQL 中,地理数据库管理员必须以 sde 命名;因此,地理数据库管理员文本框的值预填充为 sde
  9. 地理数据库管理员密码文本框中输入 sde 用户的密码。

    如果 sde 用户已存在于数据库集群中,则输入现有用户的密码即会在数据库中创建 sde 方案。如果用户尚不存在,则会在数据库集群中创建名为 sde 的用户(密码为指定的密码),并会在数据库中创建相应的方案。向公共组角色授予对 sde 方案的使用权限。

    提示:

    如果要在创建地理数据库后增强方案安全性,可撤消公共组角色的使用权限、创建新的组角色,并向该角色授予 sde 方案使用权限,然后将该组角色授予需要访问地理数据库的所有登录角色。

  10. 如果拥有想用于数据库的默认表空间的预配置表空间,则在表空间名称文本框中输入其名称。

    此工具不创建表空间;您必须指定一个现有表空间或将此文本框留空。如果不指定表空间,则在 pg_default 中创建数据库。

  11. 要指定授权文件,请浏览到在授权 ArcGIS Server Enterprise 时创建的密钥代码文件,并选择该文件。

    将此文件写入 Windows 服务器的 \\Program Files\ESRI\License<release#>\sysgen 文件夹和 Linux 的 /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen 中。将此文件复制到客户端(可通过该客户端创建地理数据库)的访问位置。如果尚未执行此操作,则立即授权 ArcGIS Server 创建此文件。

  12. 单击运行

    可在 sde_setup.log 文件中查找创建地理数据库的相关消息,该文件是在为运行工具的计算机上的 %TEMP% 变量指定的目录中创建的。如果在创建地理数据库时出现任何问题,可查看此文件以解决这些问题。

您现已在 PostgreSQL 中拥有一个地理数据库。

接下来,您可创建能够将数据加载到地理数据库中的用户

在 ArcGIS 客户端计算机中运行 Python 脚本

您可以通过复制、保存和运行此处提供的脚本在 ArcGIS DesktopDesktop StandardDesktop Advanced)、ArcGIS Server 或 ArcGIS Engine Runtime 客户端(具有 Geodatabase Update 扩展模块)中创建地理数据库。

  1. 在 ArcGIS 客户端计算机上创建文本文件,然后将以下脚本复制到该文件中。
    """
    Name: create_enterprise_gdb.py
    Description: Provide connection information to a DBMS instance and create an enterprise geodatabase.
    Type  create_enterprise_gdb.py -h or create_enterprise_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 1.0 for " + arcpy.GetInstallInfo()['Version'] )
    
    #Define help and options
    parser.add_option ("--DBMS", dest="Database_type", type="choice", choices=['SQL_SERVER', 'ORACLE', 'POSTGRESQL', ''], default="", help="Type of enterprise DBMS:  SQL_SERVER, ORACLE, or POSTGRESQL.")                   
    parser.add_option ("-i", dest="Instance", type="string", default="", help="DBMS instance name")
    parser.add_option ("-D", dest="Database", type="string", default="none", help="Database name:  Do not specify for Oracle")
    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="Dbms_admin", type="string", default="", help="DBMS administrator user")
    parser.add_option ("-P", dest="Dbms_admin_pwd", type="string", default="", help="DBMS administrator password")
    parser.add_option ("--schema", dest="Schema_type", type="choice", choices=['SDE_SCHEMA', 'DBO_SCHEMA'], default="SDE_SCHEMA", help="Schema type  applies to geodatabases in SQL Server only. Type SDE_SCHEMA to create geodatabase in SDE schema or type DBO_SCHEMA to create geodatabase in DBO schema. Default=SDE_SCHEMA")
    parser.add_option ("-u", dest="Gdb_admin", type="string", default="", help="Geodatabase administrator user name; Must always be sde for PostgreSQL, sde-schema geodatabases in SQL Server, and sde geodatabase in Oracle")
    parser.add_option ("-p", dest="Gdb_admin_pwd", type="string", default="", help="Geodatabase administrator password")
    parser.add_option ("-t", dest="Tablespace", type="string", default="", help="Tablespace name; For PostgreSQL, type name of existing tablespace in which to store database. If no tablespace name specified, pg_default is used. For Oracle, type name of existing tablespace, or, if tablespace with specified name does not exist, it will be created and set as the default tablespace for the sde user. If no tablespace name is specified, SDE_TBS tablespace is created and set as sde user default. Tablespace name not supported for SQL Server.")
    parser.add_option ("-l", dest="Authorization_file", type="string", default="", help="Full path and name of authorization file; file created when ArcGIS Server Enterprise authorized, and stored in \\Program Files\ESRI\License<release#>\sysgen on Windows or /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen on Linux")
    # 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
    	database_type = options.Database_type.upper()
    	instance = options.Instance
    	database = options.Database.lower()	
    	account_authentication = options.Account_authentication.upper()
    	dbms_admin = options.Dbms_admin
    	dbms_admin_pwd = options.Dbms_admin_pwd
    	schema_type = options.Schema_type.upper()
    	gdb_admin = options.Gdb_admin
    	gdb_admin_pwd = options.Gdb_admin_pwd	
    	tablespace = options.Tablespace
    	license = options.Authorization_file
    
    	
    	if( database_type ==""):	
    		print(" \n%s: error: \n%s\n" % (sys.argv[0], "DBMS type (--DBMS) must be specified."))
    		parser.print_help()
    		sys.exit(3)		
    		
    	if (license == ""):
    		print(" \n%s: error: \n%s\n" % (sys.argv[0], "Authorization file (-l) must be specified."))
    		parser.print_help()
    		sys.exit(3)			
    	
    	if(database_type == "SQL_SERVER"):
    		if(schema_type == "SDE_SCHEMA" and gdb_admin.lower() != "sde"):
    			print("\n%s: error: %s\n" % (sys.argv[0], "To create SDE schema on SQL Server, geodatabase administrator must be SDE."))
    			sys.exit(3)
    		if (schema_type == "DBO_SCHEMA" and gdb_admin != ""):
    			print("\nWarning: %s\n" % ("Ignoring geodatabase administrator specified when creating DBO schema..."))
    		if( account_authentication == "DATABASE_AUTH" and dbms_admin == ""):
    			print("\n%s: error: %s\n" % (sys.argv[0], "DBMS administrator must be specified with database authentication"))
    			sys.exit(3)
    		if( account_authentication == "OPERATING_SYSTEM_AUTH" and dbms_admin != ""):
    			print("\nWarning: %s\n" % ("Ignoring DBMS administrator specified when using operating system authentication..."))
    	else:
    		if (schema_type == "DBO_SCHEMA"):
    			print("\nWarning: %s %s, %s\n" % ("Only SDE schema is supported on", database_type, "switching to SDE schema..." ))
    			
    		if( gdb_admin.lower() == ""):
    			print("\n%s: error: %s\n" % (sys.argv[0], "Geodatabase administrator must be specified."))
    			sys.exit(3)
    
    		if( gdb_admin.lower() != "sde"):
    			if (database_type == "ORACLE"):
    				print("\nGeodatabase admin user is not SDE, creating user schema geodatabase on Oracle...\n")
    			else:
    				print("\n%s: error: %s for %s.\n" % (sys.argv[0], "Geodatabase administrator must be SDE", database_type))
    				sys.exit(3)
    			
    		if( dbms_admin == ""):
    			print("\n%s: error: %s\n" % (sys.argv[0], "DBMS administrator must be specified!"))
    			sys.exit(3)
    
    		if (account_authentication == "OPERATING_SYSTEM_AUTH"):
    			print("Warning: %s %s, %s\n" % ("Only database authentication is supported on", database_type, "switching to database authentication..." ))
    
    	# Get the current product license
    	product_license=arcpy.ProductInfo()
    	
    	
    	# Checks required license level
    	if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
    		print("\n" + product_license + " license found!" + " Creating an enterprise geodatabase requires an ArcGIS Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS Server license.")
    		sys.exit("Re-authorize ArcGIS before creating enterprise geodatabase.")
    	else:
    		print("\n" + product_license + " license available!  Continuing to create...")
    		arcpy.AddMessage("+++++++++")
    	
    	
    	try:
    		print("Creating enterprise geodatabase...\n")
    		arcpy.CreateEnterpriseGeodatabase_management(database_platform=database_type,instance_name=instance, database_name=database, account_authentication=account_authentication, database_admin=dbms_admin, database_admin_password=dbms_admin_pwd, sde_schema=schema_type, gdb_admin_name=gdb_admin, gdb_admin_password=gdb_admin_pwd, tablespace_name=tablespace, authorization_file=license)
    		for i in range(arcpy.GetMessageCount()):
    			arcpy.AddReturnMessage(i)
    		arcpy.AddMessage("+++++++++\n")
    	except:
    		for i in range(arcpy.GetMessageCount()):
    			arcpy.AddReturnMessage(i)
    			
    #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)
  2. .py 扩展名保存该文件。
  3. 运行脚本,同时提供特定于您的站点的选项和信息。

    在下列通过 Windows 计算机运行的示例中,以 postgres 超级用户(密码为 N0pe3king!)身份针对名为 pgprod 的数据库集群运行文件 create_gdb.py。 在名为 gis 的现有表空间中创建名为 entgdb 的数据库,并创建 sde 登录角色(密码为 Tgdbst@rtsh3r3)。 默认 ArcGIS Server 位置中指定的密钥代码文件用于授权地理数据库。

    create_gdb.py --DBMS POSTGRESQL -i pgprod -D entgdb --auth DATABASE_AUTH 
    -U postgres -P N0pe3king! -u sde -p Tgdbst@rtsh3r3 -t gis -l '\\Program Files\ESRI\License\sysgen\keycodes'

    在此示例中,在 Linux 计算机中运行相同的脚本:

    ./create_gdb.py --DBMS POSTGRESQL -i pgprod -D entgdb --auth DATABASE_AUTH 
    -U postgres -P N0pe3king! -u sde -p Tgdbst@rtsh3r3 -t gis -l '/usr/arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License/sysgen/keycodes'
    提示:

    Type -h or --help at the command prompt to get syntax help.

您现已在 PostgreSQL 中拥有一个地理数据库。

可在 sde_setup.log 文件中查找创建地理数据库的相关消息,该文件是在为运行脚本的计算机上的 TEMP 或 TMP 变量指定的目录中创建的。 如果在创建地理数据库时出现问题,可查看此文件以解决这些问题。

接下来,您可创建能够将数据加载到地理数据库中的用户

PostgreSQL 管理员创建数据库;地理数据库管理员创建地理数据库

如果地理数据库的创建人员无法获得数据库管理员(postgres 超级用户)的密码,数据库管理员可对数据库进行设置,然后地理数据库管理员可以 sde 登录角色连接到数据库并使用启用企业级地理数据库地理处理工具或 Python 脚本在数据库中创建地理数据库。

启用企业级地理数据库工具以数据库连接文件作为输入,并在 sde 方案中创建地理数据库系统表、视图、函数和过程。 要运行此工具,数据库管理员必须在 PostgreSQL 数据库集群中创建以下内容:

  • 名为 sde 并具有超级用户身份的登录角色
  • 数据库
  • 数据库中的 sde 方案,所有者为 sde 登录角色
  • st_geometry 库必须位于 PostgreSQL 安装目录下
请注意,所有数据库对象名称仅可以使用小写字母。

按照说明针对安装有 PostgreSQL 的操作系统创建地理数据库。

安装和配置 PostgreSQL 和 st_geometry

首先,数据库管理员必须准备 PostgreSQL 以用于存储地理数据库。

数据库管理员应按照以下说明在 Windows 服务器上创建 PostgreSQL 数据库集群。 请注意,所有数据库对象名称(数据库、方案和登录角色)仅可以使用小写字母。

  1. 获取并安装受支持的 PostgreSQL 版本并配置数据库集群。

    可从 My Esri 下载 PostgreSQL 安装程序。 如果使用此安装程序,则无需特定的非默认设置即可通过 ArcGIS 使用 PostgreSQL。 如果不想使用默认设置,则只需确保更改区域设置和位置设置即可。 或者,也可以自行获取 PostgreSQL 安装程序。

    有关安装和配置 PostgreSQL 的说明,请参阅 PostgreSQL 文档

  2. 将数据库集群配置为接受连接。

    其中包括更改 pg_hba.conf 文件以允许数据库集群接受远程连接。

  3. 或者,可在用于存储数据库的数据库集群中创建表空间。
  4. 创建名为 sde 的登录角色并授予其超级用户身份。

    提示:

    如果地理数据库管理员不移除数据库连接,您可以在创建地理数据库后取消 sde 角色的超级用户身份。

  5. 创建用于存储地理数据库的数据库。
  6. 在数据库中创建名为 sde 的方案并向 sde 登录角色授予该方案的权限。
  7. 您还必须将 st_geometry.dll 文件放置在 PostgreSQL lib 目录下。 可从 My Esri 中下载 st_geometry.dll 文件。 确保为正在使用的 PostgreSQL 版本下载正确的库。 如果使用错误的库,则地理数据库的创建将会失败。
    注:

    st_geometry.dll 需要使用 Microsoft Visual C++ Redistributable Package (x64)。 有关所需的软件包版本,请参阅 PostgreSQL 数据库要求。 如果 PostgreSQL 服务器上没有此软件包,可从 Microsoft 站点下载该包并安装。

  8. 为地理数据库管理员提供数据库连接信息。

    地理数据库管理员需要知道 sde 登录角色的数据库集群名称、数据库名称和密码。

现已存在数据库,地理数据库管理员可安装 ArcGIS 客户端并创建地理数据库。

安装 ArcGIS 客户端

地理数据库管理员应安装用于创建地理数据库的 ArcGIS 客户端。 通常,您可通过 ArcGIS ServerArcGIS DesktopDesktop StandardDesktop Advanced)创建地理数据库。

注:

您需要一个 ArcGIS Server(企业版)密钥代码文件,以便在下一部分中授权地理数据库。 即使不在 ArcGIS Server 计算机上运行 Python 脚本来创建地理数据库,也必须安装和授权 ArcGIS Server 才能获取密钥代码文件。 可能需要将 ArcGIS Server 计算机中的密钥代码文件复制到可使用启用企业级地理数据库地理处理工具访问的位置。

安装 ArcGIS 客户端后,可连接到数据库并创建地理数据库。

创建地理数据库

地理数据库管理员可以从 ArcGIS DesktopDesktop StandardDesktop Advanced)中运行启用企业级地理数据库工具,或从 ArcGIS DesktopArcGIS Server 或 ArcGIS Engine 客户端中运行 Python 脚本在现有数据库中创建地理数据库。

运行启用企业级地理数据库工具

您可以在 ArcGIS Desktop 中运行启用企业级地理数据库工具以在 PostgreSQL 数据库中创建地理数据库。

请遵照以下步骤使用 ArcGIS Pro 中的启用企业级地理数据库工具创建地理数据库:

  1. 启动 ArcGIS Pro
  2. 以 sde 用户身份连接到 PostgreSQL 数据库

    确保将 sde 用户密码保存在数据库连接对话框中。

  3. 打开启用企业级地理数据库工具。
  4. 将新的连接文件拖动到输入数据库字段中。
  5. 要指定授权文件,请浏览到在授权 ArcGIS Server Enterprise 时创建的密钥代码文件,并选择该文件。

    将此文件写入 Windows 服务器的 \\Program Files\ESRI\License<release#>\sysgen 文件夹和 Linux 的 /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen 中。将此文件复制到客户端(可通过该客户端创建地理数据库)的访问位置。如果尚未执行此操作,则立即授权 ArcGIS Server 创建此文件。

  6. 单击运行

将在数据库中创建地理数据库。

可在 sde_setup.log 文件中查找创建地理数据库的相关消息,该文件是在为运行工具的计算机上的 %TEMP% 变量指定的目录中创建的。如果在创建地理数据库时出现任何问题,可查看此文件以解决这些问题。

接下来,数据库管理员可以在数据库中创建登录角色。

ArcGIS Server Windows 计算机中运行 Python 脚本

如果想要通过从 Windows 计算机上的 ArcGIS ServerArcGIS DesktopArcGIS Engine 安装程序运行脚本来创建地理数据库,则可使用此处提供的脚本。

按照这些步骤运行 Python 脚本以在 PostgreSQL 中创建地理数据库:

  1. 在 ArcGIS 客户端计算机上创建文本文件,然后将以下脚本复制到该文件中。

    """
    Name: enable_enterprise_gdb.py
    Description: Provide connection information to an enterprise database
    and enable enterprise geodatabase.
    Type enable_enterprise_gdb.py -h or enable_enterprise_gdb.py --help for usage
    """
    
    # Import system modules
    import arcpy, os, optparse, sys
    
    
    # Define usage and version
    parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0 for " + arcpy.GetInstallInfo()['Version'] )
    
    #Define help and options
    parser.add_option ("--DBMS", dest="Database_type", type="choice", choices=['SQL_SERVER', 'ORACLE', 'POSTGRESQL', 'DB2','INFORMIX','DB2ZOS', ''], default="", help="Type of enterprise DBMS:  SQL_SERVER, ORACLE, POSTGRESQL, DB2, INFORMIX, or DB2ZOS.")
    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 ("-D", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")
    parser.add_option ("-l", dest="Authorization_file", type="string", default="", help="Full path and name of authorization file")
    
    
    # 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
    	database_type = options.Database_type.upper()
    	instance = options.Instance
    	account_authentication = options.account_authentication.upper()
    	username = options.User.lower() 
    	password = options.Password	
    	database = options.Database.lower()
    	license = options.Authorization_file
    
    
    	if( database_type ==""):	
    		print " \n%s: error: \n%s\n" % (sys.argv[0], "DBMS type (--DBMS) must be specified.")
    		parser.print_help()
    		sys.exit(3)		
    		
    	if (license == ""):
    		print " \n%s: error: \n%s\n" % (sys.argv[0], "Authorization file (-l) must be specified.")
    		parser.print_help()
    		sys.exit(3)
    
    		
    	# Get the current product license
    	product_license=arcpy.ProductInfo()
    	
    	if (license == ""):
    		print " \n%s: error: %s\n" % (sys.argv[0], "Authorization file (-l) must be specified.")
    		parser.print_help()
    		sys.exit(3)
    	
    	# Checks required license level
    	if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
    		print "\n" + product_license + " license found!" + "  Enabling enterprise geodatabase functionality requires an ArcGIS Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS Server license."
    		sys.exit("Re-authorize ArcGIS before enabling an enterprise geodatabase.")
    	else:
    		print "\n" + product_license + " license available!  Continuing to enable..."
    		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")
    	
    	
    	# Process: Enable geodatabase...
    	try:
    		print "Enabling Enterprise Geodatabase...\n"
    		arcpy.EnableEnterpriseGeodatabase_management(input_database=Connection_File_Name_full_path, authorization_file=license)
    		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)

  2. .py 扩展名保存该文件。
  3. 运行脚本,同时提供特定于您的站点的选项和信息。

    在以下示例中,将针对数据库集群 pgprod 上的数据库 spdata 运行文件 enable_gdb.py。 使用 sde 登录帐户通过密码 Tgdbst@rtsh3r3 进行连接。 默认 ArcGIS Server 位置中指定的密钥代码文件用于授权地理数据库。

    enable_gdb.py --DBMS POSTGRESQL -i pgprod --auth DATABASE_AUTH 
    -u sde -p Tgdbst@rtsh3r3 -D spdata -l '\\Program Files\ESRI\License\sysgen\keycodes'
    提示:

    Type -h or --help at the command prompt to get syntax help.

您现已在 PostgreSQL 中拥有一个地理数据库。

可在 sde_setup.log 文件中查找创建地理数据库的相关消息,该文件是在为运行脚本的计算机上的 TEMP 或 TMP 变量指定的目录中创建的。 如果在创建地理数据库时出现问题,可查看此文件以解决这些问题。

接下来,数据库管理员可以在数据库中创建登录角色。