Skip To Content

Create geodatabases in PostgreSQL on AWS

If you created an ArcGIS Enterprise on Amazon Web Services (AWS) instance using the Esri AMI that includes PostgreSQL, you can create geodatabases using a Python script that calls the Create Enterprise Geodatabase geoprocessing tool.

When you use ArcGIS Server Cloud Builder on Amazon Web Services to launch your instance, two enterprise geodatabases are created in PostgreSQL. If you want additional geodatabases—for example, if you want to customize the name or location of the geodatabases you use, or you have multiple departments that maintain their own discrete data and require their own geodatabases—you can create additional geodatabases.

When you manually set up your site using the AWS Management Console, no geodatabases are created. If you want to use geodatabases in PostgreSQL with your ArcGIS Enterprise on Amazon Web Services instance, you must create them.

Follow these steps to create a geodatabase in PostgreSQL to use with your ArcGIS Enterprise on Amazon Web Services instance:

  1. Make an SSH connection to your ArcGIS Server site (SITEHOST).

    You must open the SSH port (22) in your security group to do this.

  2. Copy the following script into a text editor:
    #Import arcpy module
    import arcpy
    
    arcpy.CreateEnterpriseGeodatabase("PostgreSQL", "<aws instance name>", "<new geodatabase name>", "DATABASE_AUTH", "postgres", "<postgres password>", "", "sde", "<sde password>", "", "/arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release>/sysgen/keycodes")
  3. Alter the values in brackets (<>) to match the information for your site and save the file with a .py extension.
  4. Open a command shell and set environment variables to point to the script.
  5. Run the script to create the geodatabase.

    If the information you provide is correct, you receive a message indicating the geodatabase was successfully created. If you receive an error message, be sure the information you provided was correct (for example, you used the correct passwords and the database name is valid).

    Tip:

    Check the PostgreSQL log file at data/pg_log for extended error messages.

  6. You now have a new geodatabase. You must add login roles and user schemas to the database.

  7. Copy this script into a text editor to connect to the new geodatabase and create a login role with matching schema. Alternatively, you can specify an existing login role, and a schema for it will be created in the database.
    #Import arcpy module
    import arcpy
    
    arcpy.CreateDatabaseConnection_management("<path to directory where connection file to be created>", "<connection file name>.sde", "POSTGRESQL", "<aws instance name>", "DATABASE_AUTH", "postgres", "<postgres password>", "<geodatabase name>", "SAVE_USERNAME")
    
    arcpy.CreateDatabaseUser_management("<path to directory with connection file>/<connection file name>.sde", "DB", "<login role name>", "<login password>")
  8. Alter the values in brackets (<>) to match the database and login role information for your site and save the file with a .py extension.

    For example, if you want the default login role created with ArcGIS Server Cloud Builder on Amazon Web Services—owner—to create data in your new geodatabase, specify the owner login role in the script.

  9. Open a command shell and set environment variables to point to the script.
  10. Run the script to create a login role and schema (or a schema for an existing login role).

    The script grants usage privileges on the schema to public.

  11. Repeat the previous step for each login role that will be creating data in the new geodatabase.

Related topics