摘要
创建企业级地理数据库工具根据所使用的数据库管理系统 (DBMS) 来创建数据库、存储位置,以及作为地理数据库管理员和地理数据库所有者的数据库用户。它授予地理数据库管理员创建地理数据库、以及在数据库中创建地理数据库所需的权限。
用法
-
下表指示对每种类型的 DBMS 该工具可实现的功能:
功能
DBMS
创建数据库
PostgreSQL 和 Microsoft SQL Server
创建表空间
Oracle
在数据库中创建地理数据库管理员用户
Oracle、PostgreSQL 和 SQL Server(如果创建 sde 方案地理数据库)
授予地理数据库管理员创建地理数据库、升级地理数据库和取消数据库连接所需的权限
Oracle 和 PostgreSQL
授予地理数据库管理员创建地理数据库和取消数据库连接所需的权限
SQL Server(如果创建 sde 方案地理数据库)
在指定数据库中创建地理数据库
Oracle、PostgreSQL 和 SQL Server
-
ArcGIS for Server(标准版或高级版)。您必须能够直连到 DBMS,以创建数据库对象和地理数据库。这需要您在安装 ArcGIS 客户端的计算机上安装和配置 DBMS 客户端。
语法
| 参数 | 说明 | 数据类型 |
|
database_platform
[database_platform,...]
|
指定要连接以创建地理数据库的数据库管理系统的类型。
|
String |
|
instance_name
|
对于 SQL Server,提供 SQL Server 的实例名。对于 Oracle,提供 TNS 名称或 Oracle Easy Connection 字符串。对于 PostgreSQL,提供安装 PostgreSQL 的服务器的名称。 |
String |
|
database_name
(可选)
|
该参数只对 PostgreSQL 和 SQL Server DBMS 类型有效。输入现有的、预先配置的数据库名称,或输入要创建的数据库名称。如果要使该工具在 SQL Server 中创建数据库,文件大小可与为 SQL Server 模型数据库定义的大小相同,或者对于 MDF 文件为 500 MB,对于 LDF 文件为 125 MB,取较大值。MDF 文件和 LDF 文件均可在数据库服务器上的默认 SQL Server 位置创建。如果要使该工具在 PostgreSQL 中创建数据库,则 template1 数据库将用作您数据库的模板。 |
String |
|
account_authentication
(可选)
|
指定数据库连接要使用的授权类型。
|
Boolean |
|
database_admin
(可选)
|
如果使用数据库身份验证,则必须指定数据库管理员用户。对于 Oracle,数据库管理员为 sys。对于 Postgres,为 postgres 超级用户。对于 SQL Server,为 sysadmin 固定服务器角色的成员。 |
String |
|
database_admin_password
(可选)
|
输入数据库管理员的密码。如果使用的是数据库身份验证,则必须指定数据库管理员用户密码。 |
Encrypted String |
|
sde_schema
(可选)
|
该参数只与 SQL Server 相关,并指示地理数据库是在名为 sde 的用户方案中创建还是在数据库的 dbo 方案中创建。如果创建的是一个 dbo 方案地理数据库,连接的用户必须是 SQL Server 实例中的 dbo。因此,如果使用的是操作系统身份验证,所使用的登录用户必须是 SQL Server 实例中的 dbo。
|
Boolean |
|
gdb_admin_name
(可选)
|
如果使用的是 PostgreSQL,该值必须为 sde。如果 sde 登录角色不存在,此工具将创建 sde 登录角色并授予其超级用户权限。同时还会在数据库中创建 sde 方案。如果 sde 登录角色已存在,当其没有超级用户权限时,此工具将对其授予这一权限。 创建企业级地理数据库工具将创建用户并授予其创建和升级地理数据库以及删除用户与 DBMS 之间连接所需的权限。如果用户已经存在,则该工具将向此用户授予所需的权限。 如果使用的是 SQL Server 并指定了一个 sde 方案地理数据库,则该值必须为 sde。此工具将创建 sde 登录、数据库用户和方案,并授予其创建地理数据库以及删除与 SQL Server 实例之间连接所需的权限。如果指定了 dbo 方案,则不要为该参数提供值。 |
String |
|
gdb_admin_password
(可选)
|
为地理数据库管理员用户提供密码。如果地理数据库管理员用户已经存在于 DBMS 中,输入的密码必须与现有密码相匹配。如果地理数据库管理员用户尚未存在,则为新用户输入一个有效的数据库密码。该密码必须符合 DBMS 强制的密码策略。 密码是一个地理处理加密字符串。 |
Encrypted String |
|
tablespace_name
(可选)
|
该参数只对 Oracle 和 PostgreSQL DBMS 类型有效。对于 Oracle,请执行以下某项操作:
对于 PostgreSQL,必须为数据库提供用作默认表空间的现有表空间名称,或将此参数留空。此工具不会在 PostgreSQL 中创建表空间。如果没有为此参数提供值,则将在 PostgreSQL 的 pg_default 表空间中创建数据库。 |
String |
|
authorization_file
|
创建此文件。 |
File |
代码实例
以下脚本可在 Oracle 数据库中创建地理数据库。它创建 sde 用户并为该 sde 用户创建默认表空间 sdetbs。密钥代码文件位于远程 Linux 服务器上。
#Import arcpy module
import arcpy
arcpy.CreateEnterpriseGeodatabase("ORACLE", "ora11g:1521/elf", "", "DATABASE_AUTH", "sys", "manager", "", "sde", "supersecret", "sdetbs", "//myserver/mymounteddrive/arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License10.1/sysgen/keycodes")
该脚本连接到 SQL Server 实例 (tor\ssinstance),在其中创建一个名为 sp_data 的数据库和一个 sde 方案数据库。使用操作系统身份验证建立连接。密钥代码文件位于远程 Windows 服务器上。
#Import arcpy module
import arcpy
arcpy.CreateEnterpriseGeodatabase("SQLSERVER", "tor\ssinstance1", "sp_data", "OPERATING_SYSTEM_AUTH", "", "", "SDE_SCHEMA", "sde", "sde", "", "//myserver/Program Files/ESRI/License10.1/sysgen/keycodes")
该脚本连接到服务器上名为 feldspar 的 PostgreSQL 数据库群集。如同在现有表空间 gdbspace 中创建数据库 pggdb 那样来创建 sde 用户。密钥代码文件位于本地 Linux 服务器上。
#Import arcpy module
import arcpy
arcpy.CreateEnterpriseGeodatabase("POSTGRESQL", "feldspar", "pggdb", "DATABASE_AUTH", "postgres", "averturis", "", "sde", "nomira", "gdbspace", "/arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License10.1/sysgen/keycodes")
以下独立 Python 脚本可以提供特定于使用选项的站点的信息。
"""
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
Author: Esri
"""
# Import system modules
import arcpy, os, optparse, sys
# Define usage and version
parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0 for 10.1 release")
#Define help and options
parser.add_option ("--DBMS", dest="Database_type", type="choice", choices=['SQLSERVER', 'ORACLE', 'POSTGRESQL', ''], 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 ("-D", dest="Database", type="string", default="none", help="Database name: Not required 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 for SQL Server geodatabase, SDE or DBO. Default=SDE_SCHEMA")
parser.add_option ("-u", dest="Gdb_admin", type="string", default="", help="Geodatabase administrator user name")
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")
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
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 == "SQLSERVER"):
database_type = "SQL_SERVER"
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"
sys.exit(3)
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 for Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS for 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)