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.
What you need
Section titled “What you need”- 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.
Make a read-only login
Section titled “Make a read-only login”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.
A login that reads only some columns
Section titled “A login that reads only some columns”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
SELECTon 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_pathsets the schema Portward reads. Portward lists the tables in the login’s current schema.default_transaction_read_onlyis 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.
What the Read-only check refuses
Section titled “What the Read-only check refuses”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_dataandpg_database_owner, and the admin roles of managed services:rds_superuser,azure_pg_admin,cloudsqlsuperuserandalloydbsuperuser.
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.
Reachability and encryption
Section titled “Reachability and encryption”- 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.confor in your provider’s network rules.
What Portward reads
Section titled “What Portward reads”- The tables, views, materialized views, partitioned tables and foreign tables the login can
SELECT, in the login’s current schema. That is usuallypublic. 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.
How Portward’s rules apply
Section titled “How Portward’s rules apply”Portward’s rules mean the same thing for every kind of source. For PostgreSQL, each one names this:
| Rule | What it names in PostgreSQL |
|---|---|
| What Claude can read | A table or view the login can read. See What Portward reads. |
| Kept from Claude | A column. |
| Row rule | The rows that match a condition on a column, such as region = 'EU'. |
| Totals only | Sums, averages and counts of a column. A group of fewer than 5 rows is merged. |
| Receipt | The 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.
Limits
Section titled “Limits”- 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.
If a check fails
Section titled “If a check fails”Troubleshooting lists each message with its cause and fix.