Create a geodatabase in PostgreSQL on Linux

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.

When you create a geodatabase from ArcGIS Pro 3.3, the geodatabase version is 11.3.0.

Start by reading the prerequisites below, and follow the instructions that apply to your situation.

These instructions apply to PostgreSQL installations on a Linux server. If you have PostgreSQL installed on a Microsoft Windows server, see Create a geodatabase in PostgreSQL on Windows.

Prerequisites

To create a geodatabase in PostgreSQL, do the following:

  1. Confirm the ArcGIS, PostgreSQL, and operating system combinations you want to use are supported.
  2. 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.
  3. If you will create or enable the geodatabase in an existing PostgreSQL database, ensure that the public schema exists.

    One of the geodatabase system tables is created in the public schema.

  4. Determine who will create the geodatabase, as that affects who creates the database and which tool you use. Follow the instructions that apply to your situation:

You are the PostgreSQL and geodatabase administrator

If you perform the role of both the database administrator and geodatabase administrator and 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. 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.

    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 the public. After the geodatabase is created, you can increase security on the geodatabase by revoking usage on the sde schema from the 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:

  1. Obtain and install a supported release of PostgreSQL and configure the database cluster.

    See the PostgreSQL documentation for instructions to install and configure PostgreSQL.

  2. Configure the database cluster to accept connections.

    This includes altering the pg_hba.conf file to allow the database cluster to accept remote connections.

  3. Create a tablespace in the database cluster in which to store the 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 the 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.so file in the PostgreSQL lib directory. The location of the lib directory on Linux can vary depending on how you installed PostgreSQL. To determine the correct location for the PostgreSQL installation, run pg_config as the postgres user. The value that is returned for PKGLIBDIR is the lib directory where you need to place the st_geometry library.

You can download the st_geometry.so file from My Esri.

As the root user, place the st_geometry.so library file specific to the PostgreSQL version in the PostgreSQL lib directory. If you do not place the correct st_geometry.so library in the PostgreSQL lib directory, you cannot create a geodatabase.

The database cluster and ArcGIS client are now ready for you to create a geodatabase.

PostGIS

To use PostGIS spatial types in the geodatabase, install PostGIS on the PostgreSQL database cluster. Ensure that 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:

  1. Start ArcGIS Pro.
  2. 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.

  3. Choose PostgreSQL from the Database Platform drop-down list.
  4. Type the name of the PostgreSQL server in the Instance text box.
  5. In the Database text box, type the name of the database you want to create to contain the geodatabase.
    Note:

    Type the database name in lowercase; uppercase and mixed-case object names are not supported for geodatabases in PostgreSQL. If you type a database name in uppercase or mixed case, ArcGIS converts it to lowercase.

  6. 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 superuser has a different name, type that name in the Database Administrator text box.

    You cannot use an operating system-authenticated postgres superuser login at this release.

  7. Type the password for the postgres superuser in the Database Administrator Password text box.
  8. The geodatabase administrator must be named sde in PostgreSQL, so the Geodatabase Administrator text box is prepopulated with sde.
  9. 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:

    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 grant the group role to all login roles that need to access the geodatabase.

  10. 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.

  11. 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.

  12. Use the Spatial Type drop-down list to choose the spatial type the geodatabase will use: either ST_Geometry or PostGIS.
  13. 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.

  1. 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)
  2. Save the file with a .py extension.
  3. Run the script, providing options and information specific to your site.

    In the following example, run from a Windows machine, the create_gdb.py file is run for a database cluster named pgprod as the postgres superuser with the 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 login role named sde that has superuser status.
  • 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.

  1. Obtain and install a supported release of PostgreSQL and configure the database cluster.

    See the PostgreSQL documentation for instructions to install and configure PostgreSQL.

  2. Configure the database cluster to accept connections.

    This includes altering the pg_hba.conf file to allow the database cluster to accept remote connections.

  3. Set the following environment variables for the postgres user if they are not already set properly:

    • PGDATA—This should have been set by the PostgreSQL installation. If not, set it to the location of the PostgreSQL data directory. (This is located in the PostgreSQL installation directory.)
    • PATH—Set the PATH variable to contain postgresql/bin.
    • LD_LIBRARY_PATH—If you will configure the ST_Geometry type for the geodatabase, set the LD_LIBRARY_PATH variable to the PostgreSQL lib directory. The location of the lib directory varies depending on how you installed PostgreSQL. To determine the correct location for the PostgreSQLinstallation, run pg_config as the postgres user. Set LD_LIBRARY_PATH to the value that is returned for PKGLIBDIR.

  4. Optionally, create a tablespace in the database cluster in which to store the database.
  5. 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.

  6. Create the database to store the geodatabase.
  7. Create a schema named sde in the database and give the sde login role authority on the schema.
  8. Enable a spatial data type in the database.
    • To configure PostGIS in the database, see PostGIS documentation for instructions; then proceed to step 10.
    • To configure ST_Geometry, proceed to the next step.
  9. Obtain and place the ST_Geometry library in the PostgreSQL lib directory.
    1. Download the st_geometry.so 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.

      If the option to download is not present, contact your ArcGIS organization administrator.

    2. Sign in as the root user to the server where PostgreSQL is installed.
    3. Place the st_geometry.so file in the PostgreSQL lib directory.

      The location of the lib directory on Linux can vary depending on how you installed PostgreSQL. To determine the correct location for the PostgreSQL installation, run pg_config as the postgres user. The value that is returned for PKGLIBDIR is the lib directory where you need to place the st_geometry library.

  10. 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 the 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:

  1. Start ArcGIS Pro.
  2. Connect to the PostgreSQL database as the sde user.

    If the sde user is a database-authenticated user, you must save the sde user's password in the database connection.

  3. Open the Enable Enterprise Geodatabase tool.
  4. Drag the new connection file into the Input Database field.
  5. To specify an Authorization File value, 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.

  6. 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 and matching schemas for users who will create, edit, and view data and create login roles for editors and data viewers.

Run a Python script from an ArcGIS client machine

To create the geodatabase by running a script from an ArcGIS Pro (Desktop Standard or Desktop Advanced) or ArcGIS Server machine, you can use the script provided here.

Follow these steps to run a Python script to create a geodatabase in a PostgreSQL database:

  1. 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)

  2. Save the file with a .py extension.
  3. 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 the 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 and matching schemas for users who will create, edit, and view data and create login roles for editors and data viewers.