Access for AI agents
Section titled “Access for AI agents”PgStack Access records SQL queries executed by an AI coding agent through a temporary PostgreSQL connection. The session's queries can be reviewed in the project's Access view.
The upstream PostgreSQL user determines the database permissions available to the agent. Sessions can have a short duration and use read-only mode when the task does not require writes.
Start a session
Section titled “Start a session”Sign in interactively with pgstack auth login, then start a session for the agent:
pgstack access start --env production --duration 15m --read-only --reason "ENG-142 Investigate delayed orders" --jsonThe JSON result includes the session's connectionUrl and slug. Keep the URL private and use it only for the intended task. The flag does not grant the agent any additional database permissions.
Example agent instructions
Section titled “Example agent instructions”Adapt this prompt for your project and configured role:
Use PgStack Access whenever you connect to the project database.Start a 15-minute read-only session with --env production and a reasonsummarizing this investigation. Use --json and connect using the returnedconnectionUrl. Keep the URL private; do not include it in commits,shared logs, or your final response. Query only the data needed for the task.Revoke the returned session slug when finished. If access expires,request a new session rather than using permanent database credentials.Events and revocation
Section titled “Events and revocation”Review the recorded queries in the project's Access view. Revoke the session when the agent finishes:
pgstack access revoke <session-slug> --reason "Agent investigation complete"Revocation closes existing connections within one minute.
Copyright © 2026 PgStack
