# PostgreSQL "connection terminated" - quite frustrated :/

**URL:** <https://talk.observablehq.com/t/postgresql-connection-terminated-quite-frustrated/3287>\
**Category:** Help\
**Created:** [May 14, 2020, 4:28am UTC](https://talk.observablehq.com/t/postgresql-connection-terminated-quite-frustrated/3287 "2020-05-14T04:28:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![javpascal](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/javpascal/32/8498_2.png) [@javpascal](https://talk.observablehq.com/u/javpascal)\
**Post date:** [May 14, 2020, 4:28am UTC](https://talk.observablehq.com/t/postgresql-connection-terminated-quite-frustrated/3287/1 "2020-05-14T04:28:11Z")

</div>

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. 😓

---

<div class="post-metadata">

**Author:** ![javpascal](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/javpascal/32/8498_2.png) [@javpascal](https://talk.observablehq.com/u/javpascal)\
**Post date:** [May 14, 2020, 6:02am UTC](https://talk.observablehq.com/t/postgresql-connection-terminated-quite-frustrated/3287/2 "2020-05-14T06:02:25Z")

</div>

In case it helps, this is the message that I see when trying to test the connection in Observable’s Settings: ![Message](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/9/94dd277a63346532449eff351603603df50a6839.png)

---

<div class="post-metadata">

**Author:** ![nachocab](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nachocab/32/2426_2.png) [@nachocab](https://talk.observablehq.com/u/nachocab)\
**Post date:** [January 16, 2021, 8:11pm UTC](https://talk.observablehq.com/t/postgresql-connection-terminated-quite-frustrated/3287/3 "2021-01-16T20:11:14Z")

</div>

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”:

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/3/3a623cdd23a97d4dab259f3afad4e8fe1d9b2f00.png)

@visnup Any suggestions on how to debug this?

---

<div class="post-metadata">

**Author:** ![nachocab](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nachocab/32/2426_2.png) [@nachocab](https://talk.observablehq.com/u/nachocab)\
**Post date:** [January 20, 2021, 12:44pm UTC](https://talk.observablehq.com/t/postgresql-connection-terminated-quite-frustrated/3287/4 "2021-01-20T12:44:58Z")

</div>

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

> [@Can't access proxy database](https://talk.observablehq.com/t/cant-access-proxy-database/4475/5):
>
> You’re right. I used the --sslcert and --sslkey settings (along with the ?sslmode=require in the connection string) and it works! I was almost ready to give up because testing the connection in /settings/databases page kept giving me the same error as above, but when I tried it in the notebook it worked. For the record, I’m running the proxy in a remote server.
