Create a geodatabase in PostgreSQL on Linux

Available with Standard or Advanced license.

To create a geodatabase in a PostgreSQL database, you run a geoprocessing tool or Python script from an ArcGIS client. Start by reading the prerequisites, then follow the instructions that apply to your situation.

Note that this topic applies 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 compatible.
  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. Determine who will create the geodatabase, as that affects who creates the database, and which tool you run to create the geodatabase. 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, therefore, know the password for both login roles, you can use the Create Enterprise Geodatabase geoprocessing tool or Python script to create a geodatabase in PostgreSQL.

The Create Enterprise Geodatabase tool makes it easy to set up a geodatabase because it creates the database objects 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. Then you can run the Create Enterprise Geodatabase tool or script, and specify the name of your precreated database.

  • It creates an 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. Since 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 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 on a Linux server:

  1. 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 nondefault settings are needed to use PostgreSQL with ArcGIS. Just be sure to change the locale and location settings if you want to use those other than the default. Alternatively, you can obtain the PostgreSQL installation yourself.

    See PostgreSQL documentation for instructions on installing and configuring 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.)
    • LD_LIBRARY_PATH: 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 your PostgreSQLinstallation, execute pg_config as the postgres user. Set LD_LIBRARY_PATH to the value that is returned for PKGLIBDIR.
    • PATH: Set the PATH variable to contain postgresql/bin.

  4. Create a tablespace in the database cluster in which to store your database. If you do not create a tablespace, the pg_default tablespace will be used.

Next, install and configure an ArcGIS client.

Install an ArcGIS client

You can install ArcGIS Desktop (Desktop Standard or Desktop Advanced) or ArcGIS Server (enterprise edition) and run a Python script to create a geodatabase. If you want to run the Create Enterprise Geodatabase geoprocessing tool instead of a script, install ArcGIS Desktop.

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 to a location the Create Enterprise Geodatabase geoprocessing tool can access.

ArcGIS Desktop is only supported on Windows operating systems and, therefore, is installed on a different machine than PostgreSQL. You can install ArcGIS Server on the same machine as PostgreSQL; however, because database management systems are memory-intensive applications, this is not recommended.

  1. Install the ArcGIS client from which you will create the geodatabase.

    Typically, you create a geodatabase from either an ArcGIS Server installation or ArcGIS Desktop (Standard or Advanced).

  2. If you will be using ArcGIS Server with your geodatabase in PostgreSQL, set or alter the following variables for the ArcGIS account:

    • SDEHOME: Set this variable to the ArcGIS Server installation directory.

      For example, if ArcGIS Server is installed in the default location on a Linux server, set export SDEHOME=/home/ags/arcgis/server.

    • PG_HOME: Set PG_HOME to /opt/PostgreSQL/<version>.

      In this example, PG_HOME is set for a PostgreSQL 11.2 installation: export PG_HOME=/opt/PostgreSQL/11.2.

    • If ArcGIS Server is installed on a Windows server, add PG_HOME\bin and SDEHOME\bin locations to the PATH variable.

      For example, on Linux set export PATH=$PATH:$PG_HOME/bin:$SDEHOME/bin.

    • If ArcGIS Server is installed on a Linux server, add $PG_HOME/lib and $SDEHOME/lib to the LD_LIBRARY_PATH variable.

      For example, set export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PG_HOME/lib:$SDEHOME/lib.

Now that ArcGIS is installed, you have access to the st_geometry.so file, which must be placed on the PostgreSQL server.

Place the st_geometry.so file

You must place the st_geometry.so file in the PostgreSQL lib directory before you can create a geodatabase. The location of the lib directory on Linux can vary depending on how you installed PostgreSQL. To determine the correct location for your PostgreSQL installation, execute 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 get the st_geometry.so file from My Esri or from your ArcGIS Server installation. The following table lists where in the installation directory to find each version of the st_geometry.so library.

PostgreSQL versionArcGIS client installation directory

PostgreSQL 9.6.x

DatabaseSupport/PostgreSQL/9.6/Linux64

PostgreSQL 10.x

DatabaseSupport/PostgreSQL/10/Linux64

PostgreSQL 11.x

DatabaseSupport/PostgreSQL/11/Linux64

PostgreSQL 12.x (10.8.1 and ArcGIS Pro 2.6 only)

DatabaseSupport/PostgreSQL/12/Linux64

Caution:

The ArcGIS Server DatabaseSupport directory is created with permissions set to 700. If you use the file installed with ArcGIS Server, change the permissions on the file to 755 when you log in as root to move the st_geometry.so file to the PostgreSQL lib directory. If you do not, the sde user will not be able to access it to create a geodatabase.

As the root user, place the st_geometry.so library file specific to the version of PostgreSQL you are using in the PostgreSQL lib directory. If you do not place the correct st_geometry.so library in the PostgreSQL lib directory, you will not be able to create a geodatabase.

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

Create a geodatabase

You can either run the Create Enterprise Geodatabase tool from ArcGIS Desktop (Desktop Standard or Desktop Advanced), or run a Python script from an ArcGIS Desktop (Desktop Standard or Desktop Advanced), ArcGIS Server (enterprise edition) client to create a geodatabase.

Run the Create Enterprise Geodatabase tool

If you have access to ArcGIS Desktop, you can run a geoprocessing tool to create the geodatabase.

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 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 lower case.

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

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

  10. If you have a preconfigured tablespace you want 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. To specify an Authorization File, browse to and choose the keycodes file that was created when you authorized ArcGIS Server Enterprise.

    This file is written to \\Program Files\ESRI\License<release#>\sysgen folder on Windows servers and /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen on Linux. Copy this file to a location that is accessible to the client from which you are creating the geodatabase. If you have not already done so, authorize ArcGIS Server now to create this file.

  12. Click Run.

    You can find messages related to geodatabase creation in the sde_setup.log file, which is created in the directory specified for your %TEMP% variable on the computer where the tool is run. If you have any problems creating a geodatabase, check this file to troubleshoot the problem.

You now have a geodatabase in PostgreSQL.

Next, you can create a user who can load data into the geodatabase.

Run a Python script

You can copy, save, and run the script provided here to create a geodatabase from ArcGIS Desktop (Desktop Standard or Desktop Advanced) or ArcGIS Server (enterprise edition).

  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
    """
    
    # Import system modules
    import arcpy
    import os
    import optparse
    import 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', ''], default="", help="Type of enterprise DBMS:  SQL_SERVER, 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:  Do not specify 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  applies to geodatabases in SQL Server only. Type SDE_SCHEMA to create geodatabase in SDE schema or type DBO_SCHEMA to create geodatabase in DBO schema. Default=SDE_SCHEMA")
    parser.add_option ("-u", dest="Gdb_admin", type="string", default="", help="Geodatabase administrator user name; Must always be sde for PostgreSQL, sde-schema geodatabases in SQL Server, and master sde geodatabase in Oracle")
    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; For PostgreSQL, type name of existing tablespace in which to store database. If no tablespace name specified, pg_default is used. For Oracle, type name of existing tablespace, or, if tablespace with specified name does not exist, it will be created and set as the default tablespace for the sde user. If no tablespace name is specified, SDE_TBS tablespace is created and set as sde user default. Tablespace name not supported for SQL Server.")
    parser.add_option ("-l", dest="Authorization_file", type="string", default="", help="Full path and name of authorization file; file created when ArcGIS Server Enterprise authorized, and stored in \\Program Files\ESRI\License<release#>\sysgen on Windows or /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen on Linux")
    # 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 ==""):	
    		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")
    			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 Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS 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)
  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 Linux 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 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 '/usr/arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License/sysgen/keycodes'

    In this example, the same script is run from a Windows 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 '\\Program Files\ESRI\License\sysgen\keycodes'
    Tip:

    Type -h or --help at the command prompt to get syntax help.

You now have a geodatabase in PostgreSQL.

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 where this script is run. If you have problems creating a geodatabase, check 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 can set up the database, and then the geodatabase administrator can connect to it with the sde login role and create a geodatabase in the database using the Enable Enterprise Geodatabase geoprocessing tool or Python script.

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, owned by the sde login role
  • The st_geometry library must be in the PostgreSQL installation directory

Note that all database object names must use lowercase characters only.

Install and configure PostgreSQL and st_geometry library

First, the database administrator must prepare PostgreSQL to store a geodatabase.

The following instructions are for the database administrator to set up the PostgreSQL database cluster on a Linux server. Note that all database object names (the database, schema, and login roles) must use lowercase characters only.

  1. 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 nondefault settings are needed to use PostgreSQL with ArcGIS. Just be sure to change the locale and location settings if you want to use those other than the default. Alternatively, you can obtain the PostgreSQL installation yourself.

    See PostgreSQL documentation for instructions on installing and configuring 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.)
    • LD_LIBRARY_PATH: 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 your PostgreSQLinstallation, execute pg_config as the postgres user. Set LD_LIBRARY_PATH to the value that is returned for PKGLIBDIR.
    • PATH: Set the PATH variable to contain postgresql/bin.

  4. Optionally, you can create a tablespace in the database cluster in which to store your 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 that will store the geodatabase.
  7. Create a schema named sde in the database and give the sde login role authority on the schema.
  8. You must also place the st_geometry.so library file in the PostgreSQL lib directory. You can download the st_geometry.so file from My Esri. Be sure to download the correct library for the version of PostgreSQL you are using. If you use the wrong one, geodatabase creation will fail.

    Once you have the correct st_geometry.so file, place it in the PostgreSQL lib directory while logged in as the root user. Be aware that the location of the lib directory on Linux can vary depending on how you installed PostgreSQL. To determine the correct location for your PostgreSQL installation, execute 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.

  9. Be sure permission on the st_geometry.so file is set to 755. If it is not, the sde user will not be able to access the library and create a geodatabase.
  10. Provide the geodatabase administrator with database connection information.

    The geodatabase administrator needs to know the database cluster name, database name, and the password for the sde login role.

Now that a database exists and is configured, the geodatabase administrator can prepare an ArcGIS client and create a geodatabase.

Install an ArcGIS client

The geodatabase administrator should follow these steps to prepare the ArcGIS client to create a geodatabase:

  1. Install the ArcGIS client from which you will create the geodatabase.

    Typically, you would create a geodatabase from either an ArcGIS Server installation or ArcGIS Desktop (Desktop Standard or Desktop Advanced).

  2. If you will be using ArcGIS Server with your geodatabase in PostgreSQL, set or alter the following variables for the ArcGIS account:

    • SDEHOME: Set this variable to the ArcGIS Server installation directory.

      For example, if ArcGIS Server is installed in the default location on a Linux server, set export SDEHOME=/home/ags/arcgis/server.

    • PG_HOME: Set PG_HOME to /opt/PostgreSQL/<version>.

      In this example, PG_HOME is set for a PostgreSQL 10.3 installation: export PG_HOME=/opt/PostgreSQL/10.3.

    • If ArcGIS Server is installed on a Windows server, add PG_HOME\bin and SDEHOME\bin locations to the PATH variable.

      For example, on Linux set export PATH=$PATH:$PG_HOME/bin:$SDEHOME/bin.

    • If ArcGIS Server is installed on a Linux server, add $PG_HOME/lib and $SDEHOME/lib to the LD_LIBRARY_PATH variable.

      For example, set export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PG_HOME/lib:$SDEHOME/lib.

Your ArcGIS client is ready to connect to the database and create a geodatabase.

Create a geodatabase

The geodatabase administrator can run either the Enable Enterprise Geodatabase tool from ArcGIS Desktop (Desktop Standard or Desktop Advanced), or a Python script from an ArcGIS Desktop, ArcGIS Server, client to create a geodatabase in the existing database.

Run the Enable Enterprise Geodatabase tool

If you have access to ArcGIS Desktop, you can run a geoprocessing tool to create the geodatabase.

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.

    Be sure to save the sde user's password on the Database Connection dialog box.

  3. Open the Enable Enterprise Geodatabase tool.
  4. Drag your new connection file into the Input Database field.
  5. Browse to the ArcGIS Server authorization file that was created when you authorized ArcGIS Server and add it to the Authorization File text box.

    When you use the wizard to authorize ArcGIS Server, a keycodes file is written to the server where the software is installed. If you authorized ArcGIS Server on a Linux box, the keycodes file was created in /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release>/sysgen. If you authorized on a Windows server, the file was created in Program Files\ESRI\License<release>\sysgen. If you have not already done so, authorize ArcGIS Server to create this file.

  6. Click Run.

A geodatabase is created in the 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% variable on the computer where the tool is run. If you have any problems creating a geodatabase, check this file to troubleshoot the problem.

Next, the database administrator can create login roles in the database.

Run a Python script

If you want to create the geodatabase by running a script from an ArcGIS Server or ArcGIS Desktop (Desktop Standard or Desktop Advanced) installation, you can use the script provided here.

  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 file enable_gdb.py is run for database spdata on database cluster pgprod. The connection is made as the sde login with password Tgdbst@rtsh3r3. A keycodes file in the default ArcGIS Server 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 '/usr/arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License/sysgen/keycodes'
    Tip:

    Type -h or --help at the command prompt to get syntax help.

You now have a geodatabase in PostgreSQL.

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. Check this log file if you have problems creating a geodatabase to troubleshoot the problem.

Next, the database administrator can create login roles in the database.