創建企業級地理數據庫 (Data Management)
摘要
創建企業級地理數據庫工具根據所使用的數據庫管理系統 (DBMS) 來創建數據庫、存儲位置,以及作為地理數據庫管理員和地理數據庫所有者的數據庫用戶。它授予地理數據庫管理員創建地理數據庫、以及在數據庫中創建地理數據庫所需的權限。
用法
-
下表指示對每種類型的 DBMS 該工具可實現的功能:
功能
DBMS
創建數據庫
PostgreSQL 和 Microsoft SQL Server
創建表空間
Oracle
在數據庫中創建地理數據庫管理員用戶
Oracle、PostgreSQL 和 SQL Server(如果創建 sde 方案地理數據庫)
授予地理數據庫管理員創建地理數據庫、升級地理數據庫和取消數據庫連接所需的權限
Oracle 和 PostgreSQL
授予地理數據庫管理員創建地理數據庫和取消數據庫連接所需的權限
SQL Server(如果創建 sde 方案地理數據庫)
在指定數據庫中創建地理數據庫
Oracle、PostgreSQL 和 SQL Server
-
用來創建地理數據庫的計算機上必須安裝有 ArcGIS for Desktop(標准版或高級版)、具有 Geodatabase Update 擴展模塊的 ArcGIS Engine Runtime 或者 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 登錄角色已存在,當其沒有超級用戶權限時,此工具將對其授予這一權限。 如果使用的是 Oracle,則默認值為 sde。然而,如果在主 sde 地理數據庫內創建用戶方案地理數據庫,請指定擁有地理數據庫的用戶名稱。如果 DBMS 中不存在用戶,則創建企業級地理數據庫工具將創建用戶並授予其創建和升級地理數據庫以及刪除用戶與 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
|
提供授權 ArcGIS for Server 企業級時創建的密鑰代碼文件的路徑和文件名。此文件位於 \\Program Files\ESRI\License<release#>\sysgen 文件夾中 (Windows) 和 /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen 目錄下 (Linux)。如果尚未執行此操作,則授權ArcGIS for Server 創建此文件。 |
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)