PostgreSQL
PostgreSQL
Connect agents to a PostgreSQL database so they can answer questions from your data with SQL.
Explore your data
- Look up records, join tables, and summarize results.
- Inspect tables and columns to find the data a question needs.
- Read JSON columns as structured data.
Make changes when you allow it
With Write access, agents can also insert, update, and delete rows or change the schema. With Read access, every statement runs in a read-only transaction, so data and schema cannot change. Your database user's permissions always apply.
Setup instructions
Setup instructions
Connect PostgreSQL
-
Create a database user with only the permissions agents need. For read-only access to existing tables:
CREATE ROLE houston LOGIN PASSWORD 'choose-a-strong-password'; GRANT CONNECT ON DATABASE app TO houston; GRANT USAGE ON SCHEMA public TO houston; GRANT SELECT ON ALL TABLES IN SCHEMA public TO houston; -
Make the server reachable from Houston with TLS enabled.
-
Enter Host, Port, Database, Username and Password in Houston.
-
Choose Read or Write for Access, keep TLS mode on Verify certificate and host name (recommended), and select Add connection. For a private certificate, see Self-signed and private certificates.
Advanced
Self-signed and private certificates
For a private authority, paste its PEM certificate into CA certificate. For a
self-signed certificate, use the server certificate named by PostgreSQL's
ssl_cert_file. Include -----BEGIN CERTIFICATE----- and
-----END CERTIFICATE-----; never paste a private key. Houston then trusts only
that authority for this connection.
| TLS mode | Verification |
|---|---|
| Verify certificate and host name (recommended) | Trusted authority and matching host |
| Verify certificate only | Trusted authority; does not check the host |
| Encrypted, but doesn't check who the server is | Encryption only; use solely for disposable test data |
Without server verification, someone intercepting the connection can read your password and data. For an IP host, full verification requires that IP in the certificate's subject alternative names.
Troubleshooting
Check the host, port and firewall, and enable ssl = on in PostgreSQL. For an
untrusted certificate, supply the right CA and configure the server's intermediate
certificates. For a host mismatch, use the host named by the certificate.
Files
Files
connector.luau
-- PostgreSQL over Houston's TLS connection in the configured TLS mode. Credentials stay on Houston. type Params = {string | number | boolean} type Result = {columns: {string}, rows: {{[string]: any}}, truncated: boolean, affectedRows: number?} local MAX_ROWS = 10000 local help = { text = "postgres: SQL on one PostgreSQL database. Each call is one statement on its own connection; your database grants still apply.", functions = {} :: {[string]: any}, } local exports: {[string]: any} = {help = help} -- Both operations bind the same parameter types and return the same row format. local parameterSchema = { type = "array", items = {type = {"string", "number", "boolean"}}, description = "Bound values in SQL placeholder order.", } local resultSchema = { type = "object", properties = { columns = {type = "array", items = {type = "string"}}, rows = {type = "array", items = {type = "object", additionalProperties = true}}, truncated = {type = "boolean", description = "More rows exist; narrow the query or page with SQL."}, affectedRows = {type = "integer"}, }, required = {"columns", "rows", "truncated"}, additionalProperties = false, } help.functions.query = { description = [[Runs one statement in a read-only transaction. Bind values with $1, $2, ... in sql and pass them in order as params (strings, numbers, booleans). Parameters take their type from context; cast where needed, as in $1::jsonb. rows are objects keyed by column name, in columns order; NULL columns are absent. Booleans, integers, floats and json/jsonb columns become Lua values; integers beyond 2^53 and every other type keep PostgreSQL's text form, such as '2026-01-31 09:30:00+00' for timestamptz or '\x0102' for bytea. At most 10,000 rows or 4 MiB are returned; truncated tells when more exist, so add LIMIT, filters or aggregation. Give duplicate column names an alias.]], args = {"sql", "params"}, inputSchema = { type = "object", properties = { sql = {type = "string", minLength = 1, description = "One SQL statement; use bound parameters for values."}, params = parameterSchema, }, required = {"sql"}, additionalProperties = false, examples = {{sql = "SELECT id FROM users WHERE team = $1", params = {"core"}}}, }, outputSchema = resultSchema, annotations = {readOnlyHint = true, openWorldHint = true}, } function exports.query(sql: string, params: Params?): Result return await(db.query({sql = sql, params = params, maxRows = MAX_ROWS, readOnly = true})) end if houston.allows("data:write") then help.functions.execute = { description = [[Runs one statement that may change data, outside any transaction, with the same parameters as query. affectedRows counts the inserted, updated or deleted rows; rows hold any RETURNING values. A failed or interrupted call may already have applied its change, so check before running it again.]], args = {"sql", "params"}, inputSchema = { type = "object", properties = { sql = {type = "string", minLength = 1, description = "One SQL statement; use bound parameters for values."}, params = parameterSchema, }, required = {"sql"}, additionalProperties = false, examples = {{sql = "UPDATE tasks SET done = true WHERE id = $1 RETURNING id", params = {42}}}, }, outputSchema = resultSchema, annotations = {readOnlyHint = false, openWorldHint = true}, } function exports.execute(sql: string, params: Params?): Result return await(db.query({sql = sql, params = params, maxRows = MAX_ROWS, readOnly = false})) end end return exportshouston.json
{ "schema_version": 2, "name": "PostgreSQL", "files": [ "connector.luau" ], "icon": "icon.svg", "access": [ { "name": "data", "label": "Access", "levels": [ { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" } ], "config": { "host": { "label": "Host", "order": 2, "required": true, "type": "string" }, "port": { "default": 5432, "label": "Port", "maximum": 65535, "minimum": 1, "order": 3, "type": "integer" }, "database": { "label": "Database", "order": 4, "required": true, "type": "string" }, "username": { "label": "Username", "order": 5, "required": true, "type": "string" }, "password": { "label": "Password", "order": 6, "required": true, "type": "secret" }, "tls_mode": { "default": "verify-full", "description": "How Houston checks who the server is. Every mode encrypts the connection. Use the recommended mode for production data.", "label": "TLS mode", "options": [ { "label": "Verify certificate and host name (recommended)", "value": "verify-full" }, { "label": "Verify certificate only: doesn't check the host name", "value": "verify-ca" }, { "label": "Encrypted, but doesn't check who the server is", "value": "require" } ], "order": 7, "required": true, "type": "string" }, "ca_certificate": { "description": "The PEM certificate of the authority that signed your server's certificate, or the server's own self-signed certificate. Required with “Verify certificate only”. With the recommended mode, Houston then trusts only this authority instead of public ones.", "format": "pem", "label": "CA certificate", "max_length": 65536, "multiline": true, "order": 8, "placeholder": "-----BEGIN CERTIFICATE-----", "type": "string" } }, "proxy": [ { "match": { "protocol": "postgres" }, "action": { "connection": { "host": "{{config.host}}", "port": "{{config.port}}", "database": "{{config.database}}", "user": "{{config.username}}", "password": "{{config.password}}", "tls": { "mode": "{{config.tls_mode}}", "ca": "{{config.ca_certificate}}" } } } } ] }icon.svg
README.md
--- description: Give agents SQL access to a PostgreSQL database, read-only unless you allow changes. --- # PostgreSQL Connect agents to a PostgreSQL database so they can answer questions from your data with SQL. ## Explore your data - Look up records, join tables, and summarize results. - Inspect tables and columns to find the data a question needs. - Read JSON columns as structured data. ## Make changes when you allow it With **Write** access, agents can also insert, update, and delete rows or change the schema. With **Read** access, every statement runs in a read-only transaction, so data and schema cannot change. Your database user's permissions always apply.SETUP.md
# Connect PostgreSQL 1. Create a database user with only the permissions agents need. For read-only access to existing tables: ```sql CREATE ROLE houston LOGIN PASSWORD 'choose-a-strong-password'; GRANT CONNECT ON DATABASE app TO houston; GRANT USAGE ON SCHEMA public TO houston; GRANT SELECT ON ALL TABLES IN SCHEMA public TO houston; ``` 2. Make the server reachable from Houston with TLS enabled. 3. Enter **Host**, **Port**, **Database**, **Username** and **Password** in Houston. 4. Choose **Read** or **Write** for **Access**, keep **TLS mode** on **Verify certificate and host name (recommended)**, and select **Add connection**. For a private certificate, see [Self-signed and private certificates](#self-signed-and-private-certificates). ## Advanced ### Self-signed and private certificates For a private authority, paste its PEM certificate into **CA certificate**. For a self-signed certificate, use the server certificate named by PostgreSQL's `ssl_cert_file`. Include `-----BEGIN CERTIFICATE-----` and `-----END CERTIFICATE-----`; never paste a private key. Houston then trusts only that authority for this connection. | TLS mode | Verification | | --- | --- | | **Verify certificate and host name (recommended)** | Trusted authority and matching host | | **Verify certificate only** | Trusted authority; does not check the host | | **Encrypted, but doesn't check who the server is** | Encryption only; use solely for disposable test data | > Without server verification, someone intercepting the connection can read your > password and data. For an IP host, full verification requires that IP in the > certificate's subject alternative names. ### Troubleshooting Check the host, port and firewall, and enable `ssl = on` in PostgreSQL. For an untrusted certificate, supply the right CA and configure the server's intermediate certificates. For a host mismatch, use the host named by the certificate.tests
authentication.luau
return { contract = function(m) m.authentication({ { auth = {}, config = { database = "sample", host = "database.example.com", password = "synthetic-root-secret", username = "reader", }, method = "", native = true, publisher = {}, }, }) end, }read_only.luau
-- Read access exposes query alone, and it always asks for a read-only statement. return { scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "db.example.com", database = "app", username = "reader", password = "fixture-password"}}, access = {data = "read"}, configure = function() requests = {} db = {query = function(request) table.insert(requests, request) return fixture.operation({columns = {"id"}, rows = {{id = 7}}, truncated = false}) end} end, run = function(exports) assert(exports.execute == nil, "read access must not expose execute") local result = fixture.example("query") assert(result.rows[1].id == 7 and result.truncated == false) local request = requests[1] assert(request.sql == "SELECT id FROM users WHERE team = $1" and request.params[1] == "core") assert(request.readOnly == true and request.maxRows == 10000) end, }read_write.luau
-- Write access adds execute, which sends a statement allowed to write. return { scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "db.example.com", database = "app", username = "writer", password = "fixture-password"}}, access = {data = "write"}, configure = function() requests = {} db = {query = function(request) table.insert(requests, request) return fixture.operation({columns = {"id"}, rows = {{id = 42}}, truncated = false, affectedRows = 1}) end} end, run = function(exports) local result = fixture.example("execute") assert(result.affectedRows == 1 and result.rows[1].id == 42) assert(requests[1].readOnly == false and requests[1].params[1] == 42) local read = fixture.example("query") assert(read.rows[1].id == 42 and read.truncated == false) assert(#requests == 2 and requests[2].readOnly == true and requests[2].params[1] == "core") end, }tls_bad_ca.luau
-- A CA certificate that isn't PEM is rejected when the connection is set up. return { scenario = { publisher = {}, auth_method = "", auth_config = {}, config = {host = "203.0.113.7", database = "app", username = "reader", password = "fixture-password", tls_mode = "verify-ca", ca_certificate = "MIIBizCCATGgAwIBAgIU"}, settings_error = "config.ca_certificate: must be PEM certificates", }, }tls_private_ca.luau
-- TLS mode verify-full with a CA certificate checks the host name against a private authority. local CA = [[-----BEGIN CERTIFICATE----- MIIBizCCATGgAwIBAgIUUZi7NGCxGbSs3OHB4dQS1a9pUi0wCgYIKoZIzj0EAwIw GjEYMBYGA1UEAwwPRXhhbXBsZSBEZW1vIENBMCAXDTI2MTEwMzA2MDY0MFoYDzIx MjYxMDEwMDYwNjQwWjAaMRgwFgYDVQQDDA9FeGFtcGxlIERlbW8gQ0EwWTATBgcq hkjOPQIBBggqhkjOPQMBBwNCAATI/yE1WYWuNPmmIUj261YB2ev1y5LpGyLo/gaN a29K66kUvWKNSDZsHkDrrEXHNHpYPk5h4QP8G8hMP/4BZIEuo1MwUTAdBgNVHQ4E FgQU5s3Uplu6j/FgCEkbvbrWWgHDF8MwHwYDVR0jBBgwFoAU5s3Uplu6j/FgCEkb vbrWWgHDF8MwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNIADBFAiBj6IfJ VlQ/taNheI/sn4McmVv1/0P924pHrGmKDe0/8QIhAKbtQpz1q8WUpaglTkdSdvXx Q89QH7BqdNjwVmDoqTu8 -----END CERTIFICATE----- ]] return { scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "db.internal.example.com", database = "app", username = "reader", password = "fixture-password", tls_mode = "verify-full", ca_certificate = CA}}, configure = function() requests = {} db = {query = function(request) table.insert(requests, request) return fixture.operation({columns = {"ok"}, rows = {{ok = 1}}, truncated = false}) end} end, run = function(exports) assert(exports.query("SELECT 1 AS ok").rows[1].ok == 1 and #requests == 1) end, }tls_require.luau
-- TLS mode require encrypts without checking the certificate, so it needs no CA certificate. return { scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "203.0.113.7", database = "app", username = "reader", password = "fixture-password", tls_mode = "require"}}, configure = function() requests = {} db = {query = function(request) table.insert(requests, request) return fixture.operation({columns = {"ok"}, rows = {{ok = 1}}, truncated = false}) end} end, run = function(exports) assert(exports.query("SELECT 1 AS ok").rows[1].ok == 1 and #requests == 1) end, }tls_verify_ca.luau
-- TLS mode verify-ca trusts only the pasted CA certificate and skips the host name check. local CA = [[-----BEGIN CERTIFICATE----- MIIBizCCATGgAwIBAgIUUZi7NGCxGbSs3OHB4dQS1a9pUi0wCgYIKoZIzj0EAwIw GjEYMBYGA1UEAwwPRXhhbXBsZSBEZW1vIENBMCAXDTI2MTEwMzA2MDY0MFoYDzIx MjYxMDEwMDYwNjQwWjAaMRgwFgYDVQQDDA9FeGFtcGxlIERlbW8gQ0EwWTATBgcq hkjOPQIBBggqhkjOPQMBBwNCAATI/yE1WYWuNPmmIUj261YB2ev1y5LpGyLo/gaN a29K66kUvWKNSDZsHkDrrEXHNHpYPk5h4QP8G8hMP/4BZIEuo1MwUTAdBgNVHQ4E FgQU5s3Uplu6j/FgCEkbvbrWWgHDF8MwHwYDVR0jBBgwFoAU5s3Uplu6j/FgCEkb vbrWWgHDF8MwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNIADBFAiBj6IfJ VlQ/taNheI/sn4McmVv1/0P924pHrGmKDe0/8QIhAKbtQpz1q8WUpaglTkdSdvXx Q89QH7BqdNjwVmDoqTu8 -----END CERTIFICATE----- ]] return { scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "203.0.113.7", database = "app", username = "reader", password = "fixture-password", tls_mode = "verify-ca", ca_certificate = CA}}, configure = function() requests = {} db = {query = function(request) table.insert(requests, request) return fixture.operation({columns = {"ok"}, rows = {{ok = 1}}, truncated = false}) end} end, run = function(exports) assert(exports.query("SELECT 1 AS ok").rows[1].ok == 1 and #requests == 1) end, }