Create Enterprise Geodatabase (Data Management)

License Level:BasicStandardAdvanced

Summary

The Create Enterprise Geodatabase tool creates a database, storage locations, and a database user to be used as the geodatabase administrator and owner of the geodatabase depending on the database management system (DBMS) used. It grants the geodatabase administrator privileges required to create a geodatabase, then creates a geodatabase in the database.

Usage

Syntax

CreateEnterpriseGeodatabase_management (database_platform, instance_name, {database_name}, {account_authentication}, {database_admin}, {database_admin_password}, {sde_schema}, {gdb_admin_name}, {gdb_admin_password}, {tablespace_name}, authorization_file)
ParameterExplanationData Type
database_platform
[database_platform,...]

Specify the type of database management system to which you will connect to create a geodatabase.

  • OracleIndicates you are connecting to an Oracle instance
  • PostgreSQLIndicates you are connecting to a PostgreSQL database cluster
  • SQL_ServerIndicates you are connecting to a SQL Server instance
String
instance_name

For SQL Server, provide the SQL Server instance name. For Oracle, provide either the TNS name or Oracle Easy Connection string. For PostgreSQL, provide the name of the server where PostgreSQL is installed.

String
database_name
(Optional)

This parameter is valid only for PostgreSQL and SQL Server DBMS types. Either type the name of an existing, preconfigured database, or type a name for a database to be created. If you let the tool create the database in SQL Server, the file sizes will either be the same as you have defined for the SQL Server model database or 500 MB for the MDF file and 125 MB for the LDF file, whichever is greater. Both the MDF and LDF files will be created in the default SQL Server location on the database server. If you let the tool create the database in PostgreSQL, the template1 database will be used as the template for your database.

String
account_authentication
(Optional)

Specify what type of authorization to use for the database connection.

  • OPERATING_SYSTEM_AUTHThe login information you provided when you logged in to the computer from which you are running the tool will be used to authenticate your database connection. If your DBMS is not configured to allow operating system authentication, authentication will fail.
  • DATABASE_AUTHYou must provide a valid database user name and password for authentication in the database. This is the default authentication method. If your DBMS is not configured to allow database authentication, authentication will fail.
Boolean
database_admin
(Optional)

If you use database authentication, you must specify a database administrator user. For Oracle, the database administrator is sys. For Postgres, it is the postgres superuser. For SQL Server, it is a member of the sysadmin fixed server role.

String
database_admin_password
(Optional)

Type the password for the database administrator. If you use database authentication, you must specify the database administrator user password.

Encrypted String
sde_schema
(Optional)

This parameter is only relevant for SQL Server and indicates whether the geodatabase is to be created in the schema of a user named sde or in the dbo schema in the database. If creating a dbo-schema geodatabase, you must connect as a user who is dbo in the SQL Server instance. Therefore, if you use operating system authentication, the login used must be dbo in the SQL Server instance.

  • SDE_SCHEMAThe geodatabase repository is owned by and stored in the schema of a user named sde. This is the default.
  • DBO_SCHEMAThe geodatabase repository is stored in the dbo schema in the database.
Boolean
gdb_admin_name
(Optional)

If you are using PostgreSQL, this value must be sde. If the sde login role does not exist, this tool creates it and grants it superuser privileges. It also creates an sde schema in the database. If the sde login role exists, this tool will grant it superuser privileges if it does not already have them.

If you are using Oracle, the default value is sde. However, if you are creating a user-schema geodatabase inside a master sde geodatabase, specify the name of the user who will own the geodatabase. If the user does not exist in the DBMS, the Create Enterprise Geodatabase tool creates the user and grants it the privileges required to create and upgrade a geodatabase and kill user connections to the DBMS. If the user already exists, the tool will grant the required privileges to the user.

If you are using SQL Server and specified an sde-schema geodatabase, this value must be sde. The tool will create an sde login, database user, and schema and grant it privileges to create a geodatabase and kill connections to the SQL Server instance. If you specified a dbo schema, do not provide a value for this parameter.

String
gdb_admin_password
(Optional)

Provide the password for the geodatabase administrator user. If the geodatabase administrator user already exists in the DBMS, the password you type must match the existing password. If the geodatabase administrator user does not already exist, type a valid database password for the new user. The password must meet the password policy enforced by your DBMS.

The password is a geoprocessing-encrypted string.

Encrypted String
tablespace_name
(Optional)

This parameter is only valid for Oracle and PostgreSQL DBMS types. For Oracle, do one of the following:

  • Provide the name of an existing tablespace to be used as the default tablespace for the sde user.
  • Type a valid name and a 400 MB tablespace will be created in the Oracle default storage location and set as the sde user's default tablespace.
  • Leave the tablespace blank, and tablespace SDE_TBS (400 MB) will be created and set as the default tablespace for the sde user.

For PostgreSQL, you must either provide the name of an existing tablespace to be used as the default tablespace for the database or leave this parameter blank. This tool does not create a tablespace in PostgreSQL. If you do not provide a value for this parameter, the database is created in the pg_default tablespace in PostgreSQL.

String
authorization_file

Provide the path and file name of the keycodes file that was created when you authorized ArcGIS for Server Enterprise. This file is in the \\Program Files\ESRI\License<release#>\sysgen folder on Windows and /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen directory on Linux. If you have not already done so, authorize ArcGIS for Server to create this file.

File

Code Sample

CreateGeodatabase example 1

The following script creates a geodatabase in an Oracle database. It creates an sde user and a default tablespace, sdetbs, for the sde user. The keycodes file is on a remote Linux server.

#Import arcpy module
import arcpy

arcpy.CreateEnterpriseGeodatabase_management("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")
CreateGeodatabase example 2

This script connects to a SQL Server instance (tor\ssinstance), to create a database named sp_data and an sde-schema geodatabase in it. The connection is made using operating system authentication. The keycodes file is on a remote Windows server.

#Import arcpy module
import arcpy

arcpy.CreateEnterpriseGeodatabase_management("SQLSERVER", "tor\ssinstance1", "sp_data", "OPERATING_SYSTEM_AUTH", "", "", "SDE_SCHEMA", "sde", "sde", "", "//myserver/Program Files/ESRI/License10.1/sysgen/keycodes")
CreateGeodatabase example 3

This script connects to a PostgreSQL database cluster on a server named feldspar. An sde user is created as is a database, pggdb, in the existing tablespace, gdbspace. The keycodes file is on the local Linux server.

#Import arcpy module
import arcpy

arcpy.CreateEnterpriseGeodatabase_management("POSTGRESQL", "feldspar", "pggdb", "DATABASE_AUTH", "postgres", "averturis", "", "sde", "nomira", "gdbspace", "//arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License10.1/sysgen/keycodes")
CreateGeodatabase stand-alone script

The following stand-alone Python script allows you to provide information specific to your site using options.

"""
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)

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: No
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
11/18/2013