Available with Standard or Advanced license.
To create a geodatabase in a PostgreSQL database, run a geoprocessing tool or Python script from an ArcGIS client. Start by reading the Prerequisites section below, and follow the instructions that apply to your situation.
These instructions apply to PostgreSQL installations on a Microsoft Windows server. If you have PostgreSQL installed on a Linux server, see Create a geodatabase in PostgreSQL on Linux.
Prerequisites
To create a geodatabase in PostgreSQL, do the following:
- Confirm the ArcGIS, PostgreSQL, and operating system combinations you want to use are supported.
- Obtain an ArcGIS Server keycodes file and place it in a location you can access from the ArcGIS client you'll use to create the geodatabase.
- Determine who will create the geodatabase, because that affects who creates the database and which tool you use. Follow the instructions that apply to your situation:
- If you are the PostgreSQL database administrator and the geodatabase administrator, follow the instructions in the next section.
- If the database administrator and geodatabase administrator are two different people, follow the instructions for the PostgreSQL administrator to create the database and the geodatabase administrator to create the geodatabase.
You are the PostgreSQL and geodatabase administrator
If you perform the role of both the database administrator and geodatabase administrator and, therefore, know the password for both login roles, you can use the Create Enterprise Geodatabase geoprocessing tool or a Python script that calls the tool to create a geodatabase in PostgreSQL.
The Create Enterprise Geodatabase tool creates the database objects necessary for the geodatabase and grants required privileges for you. To achieve this, specific default settings are used. The following describes what the Create Enterprise Geodatabase tool does and the settings it uses:
- It creates a database using the PostgreSQL default template (template1).
If you need to create the database using a different template—for example, if you want to use the postgis template—you must create the database before running this tool. When you run the Create Enterprise Geodatabase tool or script, specify the name of the database you created from a different template.
- It creates a database-authenticated sde login role in the database cluster and grants it superuser status. You cannot use an operating system-authenticated sde login at this release.
The sde user must be a superuser to create the geodatabase.
- It creates an sde schema in the database.
The geodatabase system tables, views, functions, and procedures are stored in the sde schema.
- It sets the sde user as the owner of the sde schema and grants usage on the sde schema to the public role.
Login roles that will use the geodatabase must be able to access the sde schema. Because geodatabase login roles likely do not exist yet, this tool grants usage to public. After the geodatabase is created, you can tighten security on your geodatabase by revoking usage on the sde schema from public and granting usage only to those login groups and roles that need access to the geodatabase.
- It creates a geodatabase.
First, you (or someone in your IT department) must install PostgreSQL and configure the database cluster.
Install and configure PostgreSQL
Follow these steps to set up a PostgreSQL database cluster to store a geodatabase:
- Obtain and install a supported release of PostgreSQL and configure the database cluster.
You can download PostgreSQL installations from My Esri. If you use this installation, no specific settings are needed to use PostgreSQL with ArcGIS unless you want to use locale and location settings other than the default.
Alternatively, you can obtain the PostgreSQL installation from another source.
See PostgreSQL documentation for instructions on installing and configuring PostgreSQL.
- Configure the database cluster to accept connections.
This includes altering the pg_hba.conf file to allow the database cluster to accept remote connections.
- Create a tablespace in the database cluster in which to store your database. If you do not create a tablespace, the pg_default tablespace is used.
Next, install and configure an ArcGIS client.
Install an ArcGIS client
You (or someone in your IT department) must install ArcGIS Pro (Desktop Standard or Desktop Advanced) or ArcGIS Server. You can run a Python script to create a geodatabase from either of these clients. To run the Create Enterprise Geodatabase geoprocessing tool instead of a script, install ArcGIS Pro.
Note:
You need an ArcGIS Server (Enterprise edition) keycodes file to authorize your geodatabase in the next section. Even if you do not run a Python script from an ArcGIS Server machine to create the geodatabase, you must authorize ArcGIS Server to get the keycodes file. You may need to copy the keycodes file from the ArcGIS Server machine to a location that the Create Enterprise Geodatabase geoprocessing tool can access.
Provide access to a spatial type
To store a geodatabase, PostgreSQL must have access to a spatial type. You can provide the database cluster with access to the Esri ST_Geometry spatial type or install PostGIS.
When the database cluster has access to a spatial type, you can create a geodatabase.
ST_Geometry
To use ST_Geometry in the geodatabase, place the st_geometry.dll file in the PostgreSQL lib directory.
You can download the st_geometry.dll file from My Esri.
Note:
The st_geometry.dll requires the Microsoft Visual C++ Redistributable Package (x64). See PostgreSQL database requirements for the package version required. If this package is not present on the PostgreSQL server, download it from the Microsoft site and install it.
Place the st_geometry.dll file specific to your PostgreSQL version in the PostgreSQL lib directory. Ensure that you use the correct file version.
PostGIS
To use PostGIS spatial types in the geodatabase, install PostGIS on the PostgreSQL database cluster. Ensure you install the version of PostGIS supported by ArcGIS.
Create a geodatabase
Run the Create Enterprise Geodatabase tool from ArcGIS Pro, or run a Python script that calls the tool from an ArcGIS Pro or ArcGIS Server machine to create a geodatabase.
Run the Create Enterprise Geodatabase tool
Follow these steps to create a geodatabase using the Create Enterprise Geodatabase tool in ArcGIS Pro:
- Start ArcGIS Pro.
- Open the Create Enterprise Geodatabase tool.
You can search for or browse to this tool, which is located in the Geodatabase Administration toolset of the Data Management toolbox.
- Choose PostgreSQL from the Database Platform drop-down list.
- Type the name of the PostgreSQL server in the Instance text box.
- In the Database text box, type the name of the database you want to create to contain your geodatabase.
Note:
Type the database name in lowercase; upper- and mixed-case object names are not supported for geodatabases in PostgreSQL. If you type a database name in upper or mixed case, ArcGIS converts it to lowercase.
- You must connect to the database cluster as the postgres superuser to create the database and other objects; therefore, the Database Administrator text box defaults to postgres.
If your postgres superuser has a different name, type that name in the Database Administrator text box.
You cannot use an operating system-authenticated superuser login at this release.
- Type the password for the postgres superuser in the Database Administrator Password text box.
- Type a password for the sde user in the Geodatabase Administrator Password text box.
If the sde user already exists in the database cluster, type the existing user's password and an sde schema is created in the database. If the user does not already exist, a user named sde with the password you specify is created in the database cluster and a corresponding schema is created in the database. Usage is granted on the sde schema to the public group role.
Tip:
If you want to make the schema more secure after the geodatabase is created, you can revoke usage from the public group role, create a new group role, grant usage on the sde schema to that role, and then grant the group role to all login roles that need to access the geodatabase.
- If you configured a tablespace to use as the default tablespace for the database, type its name in the Tablespace Name text box.
This tool does not create a tablespace; you must either specify an existing tablespace or leave this text box blank. If you do not specify a tablespace, the database is created in pg_default.
- For Authorization File, browse to and choose the keycodes file that was created when you authorized ArcGIS Server (Enterprise edition).
This file is written to \\Program Files\ESRI\License<release#>\sysgen when you install ArcGIS Server on Windows and to /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen when you install ArcGIS Server on Linux. Copy this file to a location that is accessible to the client from which you will create the geodatabase. If you have not already done so, authorize ArcGIS Server now to create this file.
- Use the Spatial Type drop-down list to choose the spatial type the geodatabase will use: either ST_Geometry or PostGIS.
- Click Run.
You now have a geodatabase in a PostgreSQL database.
You can find messages related to geodatabase creation in the sde_setup.log file, which is created in the directory specified for the TEMP variable on the computer where the script is run. If you have problems creating a geodatabase, see this file to troubleshoot the problem.
Next, you can create a user who can load data into the geodatabase.
Run a Python script from an ArcGIS client machine
You can copy, save, and run the script provided here to create a geodatabase from an ArcGIS Pro (Desktop Standard or Desktop Advanced) or ArcGIS Server machine.
- Create a text file on the ArcGIS client machine and copy the following script into the file:
""" 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 and higher releases") #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") parser.add_option ("--type", dest="Spatial_type", type="choice", choices=['ST_GEOMETRY', 'POSTGIS'], default="ST_GEOMETRY", help="Spatial Type for PostgreSQL geodatabase, ST_GEOMETRY or POSTGIS. Default=ST_GEOMETRY") # 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 spatial_type = options.Spatial_type.upper() 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( 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.management.CreateEnterpriseGeodatabase(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, spatial_type=spatial_type) 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)
- Save the file with a .py extension.
- Run the script, providing options and information specific to your site.
In the following example, run from a Windows machine, the file create_gdb.py is run for a database cluster named pgprod as postgres superuser with password N0pe3king!. It creates a database named entgdb in an existing tablespace named gis and creates the sde login role with the password Tgdbst@rtsh3r3. A keycodes file in the default ArcGIS Server location is specified to authorize the geodatabase.
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'
In this example, the same script is run from a Linux machine:
./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'
Tip:
Type -h or --help at the command prompt for syntax help.
You now have a geodatabase in a PostgreSQL database.
You can find messages related to geodatabase creation in the sde_setup.log file, which is created in the directory specified for the TEMP or TMP variable on the computer where the script is run. If you have problems creating a geodatabase, see this file to troubleshoot the problem.
Next, you can create a user who can load data into the geodatabase.
The PostgreSQL administrator creates the database; the geodatabase administrator creates the geodatabase
If the person creating the geodatabase does not have access to the database administrator's (the postgres superuser) password, the database administrator must create the database, sde login role, and sde schema. Next, the geodatabase administrator can connect to the database using the sde login and create a geodatabase using the Enable Enterprise Geodatabase geoprocessing tool or a Python script that calls the tool.
The Enable Enterprise Geodatabase tool takes a database connection file as input and creates the geodatabase system tables, views, functions, and procedures in the sde schema. The database administrator must set up the following in the PostgreSQL database cluster before the tool can be run:
- A datababase-authenticated login role named sde that has superuser status. You cannot use an operating system-authenticated sde login at this release.
- A database.
- An sde schema in the database to which the sde login has been granted authority.
- A spatial type—Either the st_geometry library must be in the lib folder PostgreSQL installation directory or PostGIS must be configured in the database.
Install and configure PostgreSQL and a spatial type
First, the database administrator must prepare PostgreSQL to store a geodatabase.
To set up the PostgreSQL database cluster as the database administrator, complete the following steps:
Note:
All database object names must use lowercase characters only.
- Obtain and install a supported release of PostgreSQL and configure the database cluster.
You can download PostgreSQL installations from My Esri. Alternatively, you can obtain the PostgreSQL installation from another source.
See PostgreSQL documentation for instructions on installing and configuring PostgreSQL.
- Configure the database cluster to accept connections.
This includes altering the pg_hba.conf file to allow the database cluster to accept remote connections.
- Optionally, create a tablespace in the database cluster in which to store your database.
- Create a login role named sde and grant it superuser status.
Tip:
If the geodatabase administrator will not be removing database connections, you can revoke the superuser status from the sde role after the geodatabase is created.
- Create the database to store the geodatabase.
- Create a schema named sde in the database and give the sde login role authority on the schema.
- Enable a spatial data type in the database.
- To configure PostGIS in the database, see PostGIS documentation for instructions; then proceed to step 9.
- To configure ST_Geometry, proceed to the next step.
- Obtain and place the ST_Geometry library in the PostgreSQL lib directory.
- Download the st_geometry.dll file from My Esri.
Download the correct library for the version of PostgreSQL you are using. If you use the wrong one, geodatabase creation will fail.
Note:
The st_geometry.dll file requires the Microsoft Visual C++ Redistributable Package (x64). See PostgreSQL database requirements for the package version required. If this package is not present on the PostgreSQL server, download it from the Microsoft site and install it.
- Place the st_geometry.dll file in the PostgreSQL lib directory on the machine where PostgreSQL is installed.
- Download the st_geometry.dll file from My Esri.
- Provide the geodatabase administrator with database connection information.
The geodatabase administrator needs to know the database cluster name, database name, and password for the sde login role.
Now that a database exists, the geodatabase administrator can install an ArcGIS client and create a geodatabase.
Install an ArcGIS client
The geodatabase administrator needs an ArcGIS client from which the geodatabase will be created: either ArcGIS Pro (Desktop Standard or Desktop Advanced) or ArcGIS Server.
Note:
You need an ArcGIS Server (Enterprise edition) keycodes file to authorize your geodatabase in the next section. Even if you do not run a Python script from an ArcGIS Server machine to create the geodatabase, you must install and authorize ArcGIS Server to get the keycodes file. You may need to copy the keycodes file from the ArcGIS Server machine to a location that the Enable Enterprise Geodatabase geoprocessing tool can access.
Once an ArcGIS client is installed, you can connect to the database and create a geodatabase.
Create a geodatabase
The geodatabase administrator can either run the Enable Enterprise Geodatabase tool from ArcGIS Pro (Desktop Standard or Desktop Advanced), or run a Python script from ArcGIS Pro or ArcGIS Server that calls the tool to create a geodatabase in the existing database.
Run the Enable Enterprise Geodatabase tool
Follow these steps to create a geodatabase using the Enable Enterprise Geodatabase tool in ArcGIS Pro:
- Start ArcGIS Pro.
- Connect to the PostgreSQL database as the sde user.
Be sure to save the sde user's password on the Database Connection dialog box.
- Open the Enable Enterprise Geodatabase tool.
- Drag your new connection file into the Input Database field.
- To specify an Authorization File, browse to and choose the keycodes file that was created when you authorized ArcGIS Server (Enterprise edition).
This file is written to \\Program Files\ESRI\License<release#>\sysgen when you install ArcGIS Server on Windows and to /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen when you install ArcGIS Server on Linux. Copy this file to a location that is accessible to the client from which you will create the geodatabase. If you have not already done so, authorize ArcGIS Server now to create this file.
- Click Run.
You now have a geodatabase in a PostgreSQL database.
You can find messages related to geodatabase creation in the sde_setup.log file, which is created in the directory specified for the TEMP variable on the computer where the script is run. If you have problems creating a geodatabase, see this file to troubleshoot the problem.
Next, the database administrator can create login roles in the database for users who will create, edit, and view data.
Run a Python script
If you want to create the geodatabase by running a script from an ArcGIS Server, ArcGIS Desktop, or ArcGIS Engine installation on a Windows machine, you can use the script provided here.
Follow these steps to run a Python script for geodatabase creation in PostgreSQL:
- Create a text file on the ArcGIS client machine and copy the following script into the file:
""" 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)
- Save the file with a .py extension.
- Run the script, providing options and information specific to your site.
In the following example, the enable_gdb.py file is run from a Windows machine. The database name is spdata and it exists in a database cluster named pgprod. The connection is made as the sde login with password Tgdbst@rtsh3r3. A keycodes file in the default ArcGIS Server on Windows location is specified to authorize the geodatabase.
enable_gdb.py --DBMS POSTGRESQL -i pgprod --auth DATABASE_AUTH -u sde -p Tgdbst@rtsh3r3 -D spdata -l '\\Program Files\ESRI\License\sysgen\keycodes'
In this example, the same file is run from a Linux machine, and the keycodes file is in the default ArcGIS Server on Linux location.
./enable_gdb.py --DBMS POSTGRESQL -i pgprod --auth DATABASE_AUTH -u sde -p Tgdbst@rtsh3r3 -D spdata -l '/usr/arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License/sysgen/keycodes'
Tip:
Type -h or --help at the command prompt for syntax help.
You now have a geodatabase in a PostgreSQL database.
You can find messages related to geodatabase creation in the sde_setup.log file, which is created in the directory specified for your TEMP or TMP variable on the computer where the script is run. If you have problems creating a geodatabase, see this file to troubleshoot the problem.
Next, the database administrator can create login roles in the database for users who will create, edit, and view data.