> For the complete documentation index, see [llms.txt](https://docs.fastn.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fastn.ai/connectors/catalog/data-database/postgres.md). Agents can also search and read this documentation through its [MCP server](https://docs.fastn.ai/~gitbook/mcp).

# PostgreSQL

PostgreSQL is an open-source relational database. Run queries, insert and delete rows, describe tables and check database size and activity.

![PostgreSQL logo](https://1255842839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3iSr2Tx8FvvuoLPncziH%2Fuploads%2Fgit-blob-36a12171393b13295a6e953ca184965e13fcb671%2Fpostgres.png?alt=media)

|                    |                                                                                 |
| ------------------ | ------------------------------------------------------------------------------- |
| **Category**       | [Data and databases](https://docs.fastn.ai/connectors/catalog/data-database.md) |
| **Authentication** | Host, username and password                                                     |
| **Slug**           | `postgres`                                                                      |
| **On fastn.ai**    | [Embed PostgreSQL in your product](https://fastn.ai/integrations/postgresql)    |

## Setup

Your customers enter their host, username and password for PostgreSQL when they connect. Nothing else needs setting up.

## Connect in Fastn

Your customers connect PostgreSQL from your widget. To connect an account yourself:

1. Go to **Build → Integrations → Connectors** and search for **PostgreSQL**.
2. Select **Connect** on the PostgreSQL card.

   <figure><img src="https://1255842839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3iSr2Tx8FvvuoLPncziH%2Fuploads%2Fgit-blob-586dd03cdc0c6904263f58928d7a531eae2f85df%2Fconnect-search.png?alt=media" alt="The Connectors page in Fastn with ServiceNow typed in the search box and the ServiceNow card showing a Connect button"><figcaption><p>Search for the connector, then select Connect on its card. ServiceNow is shown here.</p></figcaption></figure>
3. Fill in the fields the form asks for, using the values from [Setup](#setup) above. Then select **Connect**.

   <figure><img src="https://1255842839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3iSr2Tx8FvvuoLPncziH%2Fuploads%2Fgit-blob-51fb88ef328c525b5b11f8d7094bab11efc333b8%2Fconnect-credentials.png?alt=media" alt="The Connect ServiceNow dialog with an optional account name and the Instance, Username and Password fields, and Cancel and Connect buttons"><figcaption><p>A connect form that asks for credentials. Each connector asks for its own fields.</p></figcaption></figure>
4. Check that the connection appears under **Operate → Connections** with the status `Active`. Your workflows can now use PostgreSQL's actions.

For more detail, see [Connect an app](https://docs.fastn.ai/build/integrations/connectors/connect-an-app.md).

## Actions

<table><thead><tr><th width="240">Action</th><th width="260">Slug</th><th>What it does</th></tr></thead><tbody><tr><td>Analyze Table</td><td><code>analyzeTable</code></td><td>Run ANALYZE on a table to refresh planner statistics. Schema and table are injected as identifiers.</td></tr><tr><td>Count Rows</td><td><code>countRows</code></td><td>Count the number of rows in a table. Schema and table names are injected as identifiers (not parametrizable in SQL).</td></tr><tr><td>Current Database</td><td><code>currentDatabase</code></td><td>Return the name of the currently connected database and current user.</td></tr><tr><td>Current User</td><td><code>currentUser</code></td><td>Return the current session user and current user (effective role).</td></tr><tr><td>Delete Rows</td><td><code>deleteRows</code></td><td>Delete rows from a table matching a WHERE clause. Schema/table/whereClause are injected as SQL text; values bind from params via ? placeholders. WHERE clause is required to avoid accidental full-table deletes.</td></tr><tr><td>Describe Table</td><td><code>describeTable</code></td><td>Return a full description of one table: columns (with type, nullability, default), primary key, foreign keys, and indexes, as a single JSON object.</td></tr><tr><td>Explain Query</td><td><code>explainQuery</code></td><td>Return the query plan for a SQL statement using EXPLAIN (does not execute it). Provide the statement in input.sql.</td></tr><tr><td>Get Database Size</td><td><code>getDatabaseSize</code></td><td>Get the on-disk size of a database (defaults to the current database).</td></tr><tr><td>Get Server Version</td><td><code>getServerVersion</code></td><td>Return the PostgreSQL server version string.</td></tr><tr><td>Get Table Size</td><td><code>getTableSize</code></td><td>Get total size (table + indexes + toast) of a table in bytes and human-readable form.</td></tr></tbody></table>

<details>

<summary>View 29 more actions</summary>

<table><thead><tr><th width="240">Action</th><th width="260">Slug</th><th>What it does</th></tr></thead><tbody><tr><td>Insert Rows</td><td><code>insertRows</code></td><td>Insert one or more rows into a table and return them (RETURNING *). Schema/table/columns/valuesClause are injected as SQL text; every value binds from params via ? placeholders, in order. Example: columns "id, name", valuesClause "(?, ?), (?, ?)", params [1,"a",2,"b"]. For bytea columns write hex: valuesClause "(?, decode(?, 'hex'))" and read it back with encode(col, 'hex') via the query action.</td></tr><tr><td>List Active Connections</td><td><code>listActiveConnections</code></td><td>List active backends/connections to the current database (pg_stat_activity).</td></tr><tr><td>List Columns</td><td><code>listColumns</code></td><td>List columns for a table with type, nullability and default.</td></tr><tr><td>List Constraints</td><td><code>listConstraints</code></td><td>List constraints (PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK) on a table.</td></tr><tr><td>List Databases</td><td><code>listDatabases</code></td><td>List all databases on the server (excluding templates).</td></tr><tr><td>List Extensions</td><td><code>listExtensions</code></td><td>List installed extensions in the current database.</td></tr><tr><td>List Foreign Keys</td><td><code>listForeignKeys</code></td><td>List foreign-key relationships for a table including referenced table and column.</td></tr><tr><td>List Functions</td><td><code>listFunctions</code></td><td>List functions in a schema (excludes aggregate and window; defaults to public).</td></tr><tr><td>List Indexes</td><td><code>listIndexes</code></td><td>List indexes defined on a table including their definitions.</td></tr><tr><td>List Locks</td><td><code>listLocks</code></td><td>List current locks held/awaited in the database (pg_locks joined to pg_stat_activity).</td></tr><tr><td>List Materialized Views</td><td><code>listMaterializedViews</code></td><td>List materialized views in a schema (defaults to public).</td></tr><tr><td>List Primary Keys</td><td><code>listPrimaryKeys</code></td><td>List primary key columns for a table.</td></tr><tr><td>List Procedures</td><td><code>listProcedures</code></td><td>List stored procedures in a schema (prokind = 'p'; defaults to public).</td></tr><tr><td>List Roles</td><td><code>listRoles</code></td><td>List database roles with their key attributes.</td></tr><tr><td>List Schemas</td><td><code>listSchemas</code></td><td>List all non-system schemas in the database.</td></tr><tr><td>List Sequences</td><td><code>listSequences</code></td><td>List sequences in a schema (defaults to public).</td></tr><tr><td>List Settings</td><td><code>listSettings</code></td><td>List server configuration parameters (pg_settings). Optionally filter by name prefix.</td></tr><tr><td>List Table Comments</td><td><code>listTableComments</code></td><td>List comments on tables and columns in a schema (defaults to public).</td></tr><tr><td>List Tables</td><td><code>listTables</code></td><td>List base tables in a schema (defaults to public).</td></tr><tr><td>List Tablespaces</td><td><code>listTablespaces</code></td><td>List tablespaces in the cluster.</td></tr><tr><td>List Triggers</td><td><code>listTriggers</code></td><td>List triggers in a schema (defaults to public).</td></tr><tr><td>List Types</td><td><code>listTypes</code></td><td>List user-defined enum and composite types in a schema (defaults to public).</td></tr><tr><td>List Views</td><td><code>listViews</code></td><td>List views in a schema (defaults to public).</td></tr><tr><td>Query</td><td><code>query</code></td><td>Execute any SQL statement (SELECT/INSERT/UPDATE/DELETE/DDL). SQL comes from input.sql; use ? placeholders bound positionally to input.params.</td></tr><tr><td>Select Rows</td><td><code>selectRows</code></td><td>Select rows from a table with an optional WHERE clause, row limit, ordering and paging. Schema/table/whereClause/orderBy/offset are injected as SQL text; use ? placeholders in whereClause bound from params (e.g. "id = ?"). To page a table pass orderBy "ORDER BY id" and offset "OFFSET 100" (include the keyword). Leave both out for the old behaviour.</td></tr><tr><td>Session Info</td><td><code>sessionInfo</code></td><td>Return session info: current user, database, schema, server version and backend pid.</td></tr><tr><td>Table Exists</td><td><code>tableExists</code></td><td>Check whether a table exists in the given schema. Returns a single row with an exists boolean.</td></tr><tr><td>Upsert Rows</td><td><code>upsertRows</code></td><td>Insert rows, or update them when the conflict columns already exist (INSERT... ON CONFLICT DO UPDATE, RETURNING *). Schema/table/columns/valuesClause/conflictColumns/updateClause are injected as SQL text; values bind from params via ? placeholders. Example: columns "id, name", valuesClause "(?, ?)", conflictColumns "id", updateClause "name = EXCLUDED.name", params [1,"a"]. For bytea columns write hex with decode(?, 'hex').</td></tr><tr><td>Vacuum Table</td><td><code>vacuumTable</code></td><td>Run VACUUM on a table to reclaim storage. Schema and table are injected as identifiers. Cannot run inside a transaction block.</td></tr></tbody></table>

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.fastn.ai/connectors/catalog/data-database/postgres.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
