alwaysApply: true
description: "PostgreSQL command execution guidelines for non-interactive environments"
PostgreSQL command execution rules
When running PostgreSQL commands, always follow these guidelines:
psql commands
- Always use the
--no-psqlrcflag when executing psql commands - Set
PAGER=catenvironment variable to avoid interactive pagers - For kubectl exec scenarios, use
timeoutcommand to prevent hanging in interactive mode - Avoid
-itflags in kubectl exec when running non-interactive queries - For commands that might produce long output, pipe to
| catto ensure non-interactive behavior
Examples
# Correct way to run psql locally
PAGER=cat psql --no-psqlrc -d database_name -c "SELECT * FROM table;"
# For kubectl exec with psql - use timeout to prevent hanging in interactive mode
timeout 10 kubectl exec pod-name -n namespace -- env PAGER=cat psql --no-psqlrc -U user database -c "query"
# When using aliases like pgais
PAGER=cat pgais -c "SELECT version();"
Rationale
--no-psqlrcprevents loading user-specific psql configuration that might interfere with automated scriptsPAGER=catensures output is displayed directly without interactive pagers that would hang in non-interactive environmentstimeoutcommand prevents kubectl exec from hanging when psql tries to enter interactive mode- Avoiding
-itflags in kubectl exec prevents forcing interactive/TTY mode for simple queries - These settings are essential for CI/CD, automated scripts, and remote execution scenarios