ETLMCPData Conveyance Works
Log in Start free
Guides

Connect etlmcp to Railway Postgres: turn on public access and use the TCP proxy

Railway Postgres is private until you add Public Access. Which host and port from DATABASE_PUBLIC_URL to give etlmcp, and why it is not 5432.

A Railway Postgres database cannot be reached from outside Railway until you turn on Public Access for it. Open the database service, go to Settings, then Networking, and add Public Access. Railway then creates a TCP Proxy and fills a variable called DATABASE_PUBLIC_URL. Give etlmcp the host and the port from that variable, not the ones from PGHOST or DATABASE_URL. The proxy port is a generated number, so replace the standard Postgres port that etlmcp's Port field starts with.

Why the usual variables do not work

Railway's Postgres template sets PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE and DATABASE_URL for your other services in the same project. Those values point at the database over Railway's private network, where each service is reached by a name of the form SERVICE_NAME.railway.internal. That network belongs to one Railway environment, and the public internet cannot reach it. etlmcp runs outside Railway, so it can never use these names.

Before it connects, etlmcp looks up the host you entered. It refuses a host that cannot be resolved and a host that resolves to a private or otherwise non-public address, and the destination then fails with host not allowed. A .railway.internal name fails this way. If you see that message right after pasting a value from Railway, check that it came from DATABASE_PUBLIC_URL.

Reading DATABASE_PUBLIC_URL

The TCP Proxy gives your database a generated domain and port, written as domain:port. Railway's own example is shuttle.proxy.rlwy.net:15140. Your public URL has the same shape, with the user and password before the @ and the database name after the last slash.

Split the URL into etlmcp's fields:

etlmcp field What to enter
Host the proxy domain only, such as shuttle.proxy.rlwy.net
Port the number after the colon, such as 15140
Database the part after the last slash
User and password the two values before the @

Keep the port out of the Host field. etlmcp's host check accepts a bare host name or IP address only; a host with :15140 on the end, or a whole URL with @ and / in it, is refused with the same host not allowed message.

SSL

etlmcp connects to Postgres with sslmode=require by default. Railway's Postgres service runs an SSL-enabled image built on the official Postgres image, so you have nothing to change. See Postgres SSL modes for what each mode checks.

Costs and access

Railway's Postgres page says traffic through the TCP Proxy is billed as Network Egress, so keep other heavy readers on the private network.

Once Public Access is on, anyone with the URL's credentials can try to connect. Railway's Postgres page names only the PGUSER user, so create a separate user for etlmcp with only the rights it needs; Postgres privileges lists them.

Related

Sources

  1. PostgreSQL — docs.railway.com, checked
  2. TCP Proxy — docs.railway.com, checked
  3. Private Networking — docs.railway.com, checked