Running Support Queries against Postgres
This Helm repository contains queries to produce output that the LangSmith UI does not currently support directly (e.g. obtaining trace counts for multiple organizations in a single query).
This command takes a postgres connection string that contains an embedded name and password (which can be passed in from a call to a secrets manager) and executes a query from an input file. In the example below, we are using the pg_get_trace_counts_daily.sql
input file in the support_queries/postgres
directory.
Prerequisites
Ensure you have the following tools/items ready.
kubectl
PostgreSQL client
PostgreSQL database connection:
- Host
- Port
- Username
- If using the bundled version, this is
postgres
- If using the bundled version, this is
- Password
- If using the bundled version, this is
postgres
- If using the bundled version, this is
- Database name
- If using the bundled version, this is
postgres
- If using the bundled version, this is
Connectivity to the PostgreSQL database from the machine you will be running the migration script on.
- If you are using the bundled version, you may need to port forward the postgresql service to your local machine.
- Run
kubectl port-forward svc/langsmith-postgres 5432:5432
to port forward the postgresql service to your local machine.
The script to run a support query
- You can download the script from here
Running the query script
Run the following command to run the desired query:
sh run_support_query_pg.sh <postgres_url> --input path/to/query.sql
For example, if you are using the bundled version with port-forwarding, the command might look like:
sh run_support_query_pg.sh "postgres://postgres:postgres@localhost:5432/postgres" --input support_queries/pg_get_trace_counts_daily.sql
which will output the count of daily traces by workspace ID and organization ID. To extract this to a file add the flag --output path/to/file.csv