Back to App Store
App Store/ Data & Storage/ PostgreSQL

PostgreSQL

Pilot Protocol · io.pilot.postgres
Run and query PostgreSQL from an agent — local server lifecycle + psql, any libpq target.
Data & Storage Live on catalogue
Install
pilotctl appstore install io.pilot.postgres
v17.5.0
Version
13
Methods
Size
guarded
Sandbox
macOS · Linux
Platforms

About PostgreSQL

This app installs the official PostgreSQL 17.5.0 toolchain on the host and fronts it as typed methods. The bundle is a relocatable build of PostgreSQL 17.5.0 (from conda-forge, compiled from the upstream PostgreSQL sources) carrying the complete client + server suite: psql, initdb, pg_ctl, postgres, createdb, dropdb, pg_isready, pg_dump, pg_restore, pg_dumpall, vacuumdb, pg_basebackup. Every binary is sha-pinned and staged at install; a tiny pg dispatcher in the bundle routes each method to the right tool.

Two ways to use it

A) Talk to an existing PostgreSQL server. Point the query methods at any reachable server with a libpq uri (or PG* env) — no local server needed: - postgres.query / postgres.query_csv — run SQL, get an aligned table or CSV. - postgres.command — backslash introspection (\dt, \d table, \du, \l, …). - postgres.list — list databases. postgres.version / postgres.psql_help — client version and full --help.

B) Run a database locally on this machine. The app can provision and manage its own cluster — useful for an agent that needs a throwaway or embedded Postgres:

1. Configure (one-time): postgres.initdb { "datadir": "/path/to/pgdata" } — creates the cluster (superuser postgres, local trust auth). 2. Start: postgres.start { "datadir": "/path/to/pgdata", "port": "5599" } — boots the server on 127.0.0.1:5599 (+ a Unix socket in the datadir), waits until ready, logs to <datadir>/postgres.log. 3. Create a database: postgres.createdb { "port": "5599", "dbname": "appdb" }. 4. Use it: postgres.query with uri = "host=127.0.0.1 port=5599 user=postgres dbname=appdb". 5. Health / teardown: postgres.ready { "port": "5599" }, postgres.status { "datadir": "..." }, postgres.stop { "datadir": "..." }.

Configuration

PostgreSQL is configuration-rich; the knobs this app exposes:

  • datadir — where the cluster lives. Pick a writable absolute path (e.g. $HOME/.pilot/pgdata or a tmp dir). One cluster can hold many databases.
  • port — TCP port for the local server (default convention 5599). The server also listens on a Unix socket inside datadir.
  • Auth — local clusters are initialized with trust (no password) for convenience; for any networked use, set a password (postgres.execpsql ... -c "ALTER ROLE postgres PASSWORD '...'") and supply it via the uri or PGPASSWORD.
  • Non-root for the serverpostgres.initdb/postgres.start run the PostgreSQL server, which refuses to run as the OS root user (a PostgreSQL safety rule). On a normal host the pilot daemon runs as your user, so this just works; only fully-root environments (e.g. some containers) need a non-root user. The query methods against a remote server are unaffected and run anywhere.
  • uri — a full libpq connection string, either postgresql://user:secret@host:5432/dbname?sslmode=require or host=... port=... dbname=... user=... sslmode=....
  • PG* envPGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE, PGSSLMODE, PGOPTIONS, PGCONNECT_TIMEOUT, PGAPPNAME, PGCLIENTENCODING are passed through to the child, so postgres.exec can connect with no inline credentials.
  • Anything else — full postgresql.conf/server flags are reachable via postgres.exec (e.g. pg_ctl ... -o "-c shared_buffers=256MB"), and per-session settings via SQL SET.

Good to know

  • Output returns verbatim where it is already clean; on a non-zero exit (SQL error, server down) the reply is {stdout, stderr, exit} so the caller sees everything the tool produced.
  • Runs on macOS and Linux (arm64 + amd64); binaries are fetched from the Pilot artifact registry and sha-pinned on install. Free and open source under the PostgreSQL License.
  • postgres.help lists every method with its latency class; this is the self-describing discovery contract.

## psql --help ``` psql is the PostgreSQL interactive terminal.

Usage: psql [OPTION]... [DBNAME [USERNAME]]

General options: -c, --command=COMMAND run only single command (SQL or internal) and exit -d, --dbname=DBNAME database name to connect to -f, --file=FILENAME execute commands from file, then exit -l, --list list available databases, then exit -v, --set=, --variable=NAME=VALUE set psql variable NAME to VALUE (e.g., -v ON_ERROR_STOP=1) -V, --version output version information, then exit -X, --no-psqlrc do not read startup file (~/.psqlrc) -1 ("one"), --single-transaction execute as a single transaction (if non-interactive) -?, --help[=options] show this help, then exit --help=commands list backslash commands, then exit --help=variables list special variables, then exit

Input and output options: -a, --echo-all echo all input from script -b, --echo-errors echo failed commands -e, --echo-queries echo commands sent to server -E, --echo-hidden display queries that internal commands generate -L, --log-file=FILENAME send session log to file -n, --no-readline disable enhanced command line editing (readline) -o, --output=FILENAME send query results to file (or |pipe) -q, --quiet run quietly (no messages, only query output) -s, --single-step single-step mode (confirm each query) -S, --single-line single-line mode (end of line terminates SQL command)

Output format options: -A, --no-align unaligned table output mode --csv CSV (Comma-Separated Values) table output mode -F, --field-separator=STRING field separator for unaligned output (default: "|") -H, --html HTML table output mode -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \pset command) -R, --record-separator=STRING record separator for unaligned output (default: newline) -t, --tuples-only print rows only -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border) -x, --expanded turn on expanded table output -z, --field-separator-zero set field separator for unaligned output to zero byte -0, --record-separator-zero set record separator for unaligned output to zero byte

Connection options: -h, --host=HOSTNAME database server host or socket directory -p, --port=PORT database server port -U, --username=USERNAME database user name -w, --no-password never prompt for password -W, --password force password prompt (should happen automatically)

For more information, type "\?" (for internal commands) or "\help" (for SQL commands) from within psql, or consult the psql section in the PostgreSQL documentation.

Report bugs to <pgsql-bugs@lists.postgresql.org>. PostgreSQL home page: <https://www.postgresql.org/> ```

Methods · 13

postgres.initdb
Create (configure) a brand-new PostgreSQL data directory / cluster on this host — the one-time setup before a local server can start. Initializes `datadir` with superuser `postgres` and `trust` local auth (no password for local connections). Run once per cluster; `start` then brings it up. This is `initdb -D <datadir> -U postgres -A trust --encoding=UTF8`.
postgres.start
Start a local PostgreSQL server from an initialized `datadir`, listening on 127.0.0.1:`port` and on a Unix socket in `datadir`. Backgrounds the server and waits until it accepts connections; logs go to `<datadir>/postgres.log`. After this, connect with uri `host=127.0.0.1 port=<port> user=postgres dbname=postgres`. This is `pg_ctl -D <datadir> -o '-p <port> -k <datadir> -h 127.0.0.1' -l <datadir>/postgres.log -w start`.
postgres.stop
Stop a running local server (fast shutdown) for the given `datadir`. This is `pg_ctl -D <datadir> -m fast -w stop`.
postgres.status
Report whether the server for `datadir` is running, with its PID and command line. This is `pg_ctl -D <datadir> status`.
postgres.ready
Connection preflight: check whether a server is accepting connections on 127.0.0.1:`port`. This is `pg_isready -h 127.0.0.1 -p <port>`.
postgres.createdb
Create a new database named `dbname` on the local server at 127.0.0.1:`port` (owner postgres). This is `createdb -h 127.0.0.1 -p <port> -U postgres <dbname>`.
postgres.query
Run a single SQL statement (or semicolon-separated batch) against a PostgreSQL server and return an aligned text table. Works against the local cluster or any remote server. Runs with ON_ERROR_STOP=1 so a SQL error is a non-zero exit with the server message in stderr. This is `psql -d <uri> -c <sql>`.
postgres.query_csv
Same as postgres.query but returns the result set as CSV (header + rows) — the right shape when an agent needs to parse output. This is `psql -d <uri> --csv -c <sql>`. ON_ERROR_STOP=1 is set.
postgres.command
Run a single psql backslash meta-command for schema introspection. Pass it in `command`, e.g. `\dt` (tables), `\dn` (schemas), `\du` (roles), `\l` (databases), `\df` (functions), `\d tablename` (describe a relation). Plain SQL works here too. This is `psql -d <uri> -c <command>`.
postgres.list
List the databases on the server (owner, encoding, collation, access privileges) as an aligned table — a quick connectivity + inventory check. This is `psql -d <uri> -l`.
postgres.exec
Run any PostgreSQL client/server tool shipped in this bundle with a verbatim argv — the full surface beyond the curated methods. Payload is {"args":[<tool>, ...]} where the first element is the tool name (psql, initdb, pg_ctl, createdb, dropdb, pg_isready, pg_dump, pg_restore, pg_dumpall, vacuumdb, pg_basebackup, postgres) and the rest are its flags; optional {"stdin":"..."} is piped to the tool. Examples: {"args":["psql","-d","postgresql://127.0.0.1:5599/postgres","-A","-t","-c","select 1"]}; {"args":["pg_dump","-h","127.0.0.1","-p","5599","-U","postgres","mydb"]}; {"args":["psql","-d","<uri>"],"stdin":"select 1;\nselect 2;"}. Connection can also come from PG* env vars passed through to the child.
postgres.psql_help
Return the complete `psql --help` text (all options of the PostgreSQL interactive terminal) straight from the delivered binary. The full reference for what postgres.query/postgres.exec accept. This is `psql --help`.
postgres.version
Print the delivered client version, e.g. "psql (PostgreSQL) 17.10". Needs no server. This is `psql --version`.

What’s New

v17.5.0 Latest
  • Native-CLI packaging of PostgreSQL 17.5.0 for the Pilot app store

Platform Compatibility

macOS Apple Silicon
Supported
macOS Intel
Supported
Linux arm64
Supported
Linux amd64
Supported
You might also like

More in Data & Storage