With ArcGIS Pro, I am creating a customized geoprocessing tool with python script and the PostgreSQL database connection is required. I could set four parameters to input string for "host", "username", "password", and "database". But I notice that there is a parameter data type "database connection" and seems I need to input a file path for it. I am not sure what kind of file it is expecting, should I input the file, which contains the connection string?
Can you connect to the DB from ArcGIS Pro through a Database Connection? If so then create that file if you haven't and then use that in your code to connect to it. I will include an example of the first part of what we do for our overnight database maintenance script that loops through a folder and grabs the connection files to complete the work.
import arcpy
import os
sdes = []
sdeconnections = os.listdir("\\\\Server\\FolderWithSDEFiles")
for file in sdeconnections:
if "sde" in file:
sdes.append(file)
for s in sdes:
# SDE file to use
admin_workspace = "\\\\Server\\FolderWithSDEFiles\\" + s
# Compress
arcpy.Compress_management(admin_workspace)
# Analyze Datasets
analyze_contents = []