PostgreSQL "connection terminated" - quite frustrated :/

Thanks in advance for taking a look - I know this should be a basic thing to do but I can’t get Observable to connect to my local PostgreSQL database.

I installed the observable-database-proxy library, and created a local connection to my database to my localhost on port 5432 (the one I normally use on jupyter notebook & others, where it works well).

When trying to connect, I’m using the url “postgresql://username@127.0.0.1/{database}”.
I then launch on the terminal “observable-database-proxy start {database}”.
However when trying to run a query against the database on an Observable notebook, I always see an “Error: Connection terminated unexpectedly” message.

This is the log I can see in terminal:

Error: Connection terminated unexpectedly
    at Connection.con.once (/usr/local/lib/node_modules/@observablehq/database-proxy/node_modules/pg/lib/client.js:255:9)
    at Object.onceWrapper (events.js:277:13)
    at Connection.emit (events.js:189:13)
    at Connection.EventEmitter.emit (domain.js:441:20)
    at Socket.<anonymous> (/usr/local/lib/node_modules/@observablehq/database-proxy/node_modules/pg/lib/connection.js:139:10)
    at Socket.emit (events.js:194:15)
    at Socket.EventEmitter.emit (domain.js:441:20)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Any help will be hugely welcome, I’ve been blocked on this for over an hour, trying different combinations of ports, username… yet nothing. :sweat:

In case it helps, this is the message that I see when trying to test the connection in Observable’s Settings:Message

Hey, JP.

If your DB is in a VPS, you should change your configuration to that IP address.

My DB is running in a VPS, so my proxy is running at http://MY_IP:2899 (I see “Database proxy my-db-name (postgres) running at http://MY_IP:2899” in my server) and my database connection string is postgresql://user:password@127.0.0.1:5432/my-db-name (I can confirm that this works by running this from the server psql <MY CONNECTION STRING>).

If I go to http://MY_IP:2899 on the browser I see a 401 error (as I should), but when I run the “Test connection” from Observable, I don’t see any connection attempt in the log, just this error “Connection terminated unexpectedly”:

@visnup Any suggestions on how to debug this?

1 Like

I was finally able to get it to work in a notebook, but the “Test connection” still says it doesn’t. :man_shrugging: