# Postgres Database Connection - "Error: Connection terminated due to connection timeout"

**URL:** <https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827>\
**Category:** General\
**Tags:** database\
**Created:** [23 April 2023 00:38 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827 "2023-04-23T00:38:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![HB\_1](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@HB\_1](https://discourse.nodered.org/u/HB_1)\
**Post date:** [23 April 2023 00:38 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827/1 "2023-04-23T00:38:49Z")

</div>

Hi All,

I am trying to connect to a postgres database using the node "node-red-contrib-postgresql".  
A bit of context about my config :

1. Node-red is run on an ubuntu virtual machine
2. Postgres SQL is run on the SAME ubuntu virtual machine, and file pg\_hba & postgresql.conf have been modified to accept connections from all hosts
3. I can connect to the database through Dbeaver

Here is the simple node I am trying to execute (took from the node's documentation) :

```auto
[
    {
        "id": "82b7c689d6682f72",
        "type": "postgresql",
        "z": "42e818e1032fede2",
        "name": "ADD COLUMN",
        "query": "ALTER TABLE iot.device_data\n DROP COLUMN IF EXISTS validity;\n\nALTER TABLE iot.device_data\n ADD COLUMN validity BOOLEAN;\n",
        "postgreSQLConfig": "20ae1e52d1eef983",
        "split": false,
        "rowsPerMsg": "10",
        "outputs": 1,
        "x": 280,
        "y": 180,
        "wires": [
            [
                "c5f0b4b2442e3137"
            ]
        ]
    },
    {
        "id": "20ae1e52d1eef983",
        "type": "postgreSQLConfig",
        "name": "dbtestiotstore",
        "host": "20.199.13.132",
        "hostFieldType": "str",
        "port": "5432",
        "portFieldType": "num",
        "database": "iotstore",
        "databaseFieldType": "str",
        "ssl": "false",
        "sslFieldType": "bool",
        "applicationName": "",
        "applicationNameType": "str",
        "max": "10",
        "maxFieldType": "num",
        "idle": "1000",
        "idleFieldType": "num",
        "connectionTimeout": "10000",
        "connectionTimeoutFieldType": "num",
        "user": "hamza",
        "userFieldType": "str",
        "password": "HBmdp123456789*",
        "passwordFieldType": "str"
    }
]

```

here is the error I get :  
 ![Screen Shot 2023-04-23 at 12.38.08 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d4a27929a61a9edaa265b907816161814d802ad.png)

I have tried changing the host to localhost & 127.0.0.1, but still without luck.

Happy to get your insights

Thanks,  
HB

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 April 2023 06:58 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827/2 "2023-04-23T06:58:55Z")

</div>

> [@HB\_1](#):
>
> I can connect to the database through Dbeaver

What connection parameters do you use for that?

How did you you install node red?

---

<div class="post-metadata">

**Author:** ![HB\_1](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@HB\_1](https://discourse.nodered.org/u/HB_1)\
**Post date:** [23 April 2023 08:34 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827/3 "2023-04-23T08:34:30Z")

</div>

Hi,

To connect to dBeaver, I use the same parameters as the one I inputted in the node settings. The host being the IP address of my VM, port 5432, No SSL, name of my db & username + password.

I installed node-red following this guide : [Running on Microsoft Azure : Node-RED](https://nodered.org/docs/getting-started/azure)

@Colin If you want I can give you access to the VM & Databse in private message, as this is a test setup for now, so nothing critical in there for the moment.

Thanks,  
HB

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 April 2023 08:54 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827/4 "2023-04-23T08:54:04Z")

</div>

> [@HB\_1](#):
>
> I use the same parameters as the one I inputted in the node settings

Please tell us what they are (not by looking at the node config but by looking at what you do in dBeaver). Typos are a very common problem in such cases. Don't tell us the user and pwd obviously.  
Are you running dBeaver in the vm?

In the vm can you not use localhost to access the db?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 April 2023 09:20 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827/6 "2023-04-23T09:20:37Z")

</div>

> [@HB\_1](#):
>
> In the vm I can also connect to the db.

How?

Does it work if you use localhost?

Does it work if you connect from your desktop using node-red?

---

<div class="post-metadata">

**Author:** ![HB\_1](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@HB\_1](https://discourse.nodered.org/u/HB_1)\
**Post date:** [23 April 2023 09:23 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827/7 "2023-04-23T09:23:10Z")

</div>

Yes in the configuration file I allowed it to listen to all "\*" for test purposes.  
You can connect using localhost if in the same network yes  
Does it work if you connect from your desktop using node-red? don't understand what you mean

---

<div class="post-metadata">

**Author:** ![HB\_1](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@HB\_1](https://discourse.nodered.org/u/HB_1)\
**Post date:** [23 April 2023 09:37 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827/8 "2023-04-23T09:37:30Z")

</div>

Managed to make it work, the typo was in the config file 😅

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 May 2023 09:37 UTC](https://discourse.nodered.org/t/postgres-database-connection-error-connection-terminated-due-to-connection-timeout/77827/9 "2023-05-07T09:37:36Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
