Skip to content

Connect PostgreSQL

This page is for Portward in Claude on the web. It covers a PostgreSQL database that the internet can reach, such as one on Supabase, Neon or Amazon RDS. Connect a source has the steps of the form. This page has what is particular to PostgreSQL.

For the Portward gateway in your own cloud, see PostgreSQL on the gateway (Enterprise) instead.

  • The host name, the port (5432 unless yours differs) and the database name, from your provider’s connection details.
  • A login that can only read, with its password. Make one with the script below.
  • The database reachable from the internet. See If your database is behind a firewall.

Give Portward its own login. Don’t reuse your application’s login or your own.

The setup form writes a script for you. Open Need a login that can only read? under the fields: it names the login and the database you typed. This is the script for a database named shop. Replace the password placeholder, then run it as the database’s owner or an administrator:

BEGIN;
CREATE ROLE "portward_ro" LOGIN PASSWORD '<replace with a new password>' NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS NOINHERIT;
ALTER ROLE "portward_ro" SET default_transaction_read_only = on;
GRANT CONNECT ON DATABASE "shop" TO "portward_ro";
GRANT USAGE ON SCHEMA "public" TO "portward_ro";
GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO "portward_ro";
COMMIT;

That login reads every table and view in the public schema. A table made later isn’t readable until you run the last GRANT again.

To keep a column out of the login’s reach as well, grant columns table by table. This is the script Portward writes for a connection named shop, with two tables as the example. Change the database name, the schema, the tables and the columns to yours, and replace the password placeholder first.

BEGIN;
CREATE ROLE "portward_shop" LOGIN PASSWORD '<replace with a new password>' NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS NOINHERIT;
ALTER ROLE "portward_shop" SET default_transaction_read_only = on;
ALTER ROLE "portward_shop" IN DATABASE "shop" SET search_path = "public";
GRANT CONNECT ON DATABASE "shop" TO "portward_shop";
GRANT USAGE ON SCHEMA "public" TO "portward_shop";
GRANT SELECT ("id", "region") ON TABLE "public"."customers" TO "portward_shop";
GRANT SELECT ("id", "customer_id", "ordered_on", "total") ON TABLE "public"."orders" TO "portward_shop";
COMMIT;

What the script does:

  • It makes a login that is not a superuser and can’t create databases or roles.
  • It grants SELECT on named columns only. A column you leave out can’t be read by this login at all, so the database itself keeps it back, whatever happens above it.
  • search_path sets the schema Portward reads. Portward lists the tables in the login’s current schema.
  • default_transaction_read_only is a default, not a lock. The grants are what stop a write.

A password set in SQL can end up in the server’s logs. In psql, \password portward_shop sets it without that.

Once a connection uses levels, Portward writes this script for your own tables (on the web, on Free’s one connection and on Team). Open Your connections, open a connection that uses levels, and copy it from Matching login SQL. It grants exactly the columns and rows your levels and row rules allow. Portward never runs it: you or your database administrator do. On a connection with kept columns instead of levels, write the GRANT SELECT lines yourself from the example.

The check refuses a login that:

  • is a superuser,
  • may create roles or bypass row security,
  • or belongs to an administrator role. That includes pg_write_all_data and pg_database_owner, and the admin roles of managed services: rds_superuser, azure_pg_admin, cloudsqlsuperuser and alloydbsuperuser.

So the admin login a managed database gives you at sign-up is refused. Make the login above.

A login that can insert, update, delete or truncate some table passes with a warning. Every query still runs in a read-only transaction.

  • Portward connects from the internet, with no fixed address. A private address is refused.
  • The connection is always encrypted. Portward checks the server’s certificate and that it matches the host name you typed. A server that offers no encrypted connection is refused.
  • Certificates from the public authorities are accepted. Amazon RDS and Supabase sign their own, and Portward accepts those for their own host names only.
  • If the server limits who may log in by address, allow this login from outside in pg_hba.conf or in your provider’s network rules.
  • The tables, views, materialized views, partitioned tables and foreign tables the login can SELECT, in the login’s current schema. That is usually public. Tables in other schemas are not listed, and a query can’t name another schema.
  • For each table, the columns the login can SELECT.
  • At setup, Portward reads the names of tables and columns and what the login may do. In the form in the chat, it also reads the first 5 rows of a table to show you sample values. See Keep from Claude.

Portward’s rules mean the same thing for every kind of source. For PostgreSQL, each one names this:

RuleWhat it names in PostgreSQL
What Claude can readA table or view the login can read. See What Portward reads.
Kept from ClaudeA column.
Row ruleThe rows that match a condition on a column, such as region = 'EU'.
Totals onlySums, averages and counts of a column. A group of fewer than 5 rows is merged.
ReceiptThe columns sent and the columns kept from Claude, and how many rows Claude got.

The login is the floor. Portward reads with the one login you give it, and what you choose in Portward only narrows from there. Kept columns work on every plan. Levels, with totals only and row rules, work on Free’s one connection and on Team. On Team, which isn’t open yet, an admin can also give one teammate less than everyone gets. See On Team.

  • Each query is one SELECT, in a read-only transaction.
  • A query is stopped after 30 seconds.
  • On Free, a result reads at most 200 rows. See Plans and limits.

Troubleshooting lists each message with its cause and fix.