NewJobs: scheduled actions created from chat, personal or shared.Learn more
Guides

Postgres and warehouses

Give Memtro a read-only role on a database.

Open Memtro

Connect a Postgres database (a warehouse, a reporting replica, an application database) and the model can read its schema and run read-only SQL. In agent mode it is told to look at the schema first, then query by the identifiers it found elsewhere (an email, an order id, a customer name).

1. Create a read-only role

Memtro runs every query in a READ ONLY transaction with a statement timeout and a row cap, but use a read-only role regardless:

create role memtro_reader login password 'choose-a-long-password';
grant connect on database warehouse to memtro_reader;
grant usage on schema public to memtro_reader;
grant select on all tables in schema public to memtro_reader;
alter default privileges in schema public grant select on tables to memtro_reader;

Repeat the grant usage and grant select lines for each schema you want visible.

2. Allow the connection

Memtro connects from its server's IP address. Allow it in your database firewall or security group, and require TLS where you can (?sslmode=require in the connection string).

3. Connect in Memtro

Dashboard → Connections → Postgres → paste the connection string:

postgresql://memtro_reader:...@db.example.com:5432/warehouse?sslmode=require

Give it a name the model will recognise ("warehouse", "reporting replica"). Optionally list the schemas to expose. Choose personal or shared.

What the model can do

  • postgres_schema: tables and columns, so it can write correct SQL.
  • postgres_query: one read-only SELECT or WITH query, rows capped, 20 second timeout.

Example

"Have a look at Help Scout ticket #2450 and see what you can find in the warehouse." The agent reads the ticket, takes the customer's email and order numbers, calls postgres_schema, then queries orders, shipments and payments for that customer and reports what it found and where.