# Connection Node-RED to postgreSQL server!

**URL:** <https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620>\
**Category:** General\
**Created:** [3 April 2021 22:14 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620 "2021-04-03T22:14:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [3 April 2021 22:14 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/1 "2021-04-03T22:14:22Z")

</div>

**Hello everyone,**

_This will be my very first post!_  
I want to connect Node-RED to a PostgreSQL server and for test reasons just create a table into the database. However, after configuration, I am not able to create a table. It doesn't show anything. The output on the right of the picture is from the first msg.payload. After the PostgreSQL node there is no output.

_In the pictures below I will show you the configurations:_  
**Node-RED view:**

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/94909f73571645a5e99d2a39df047c4b291fa91f.png)

**Inject node:**

```auto
msg.payload = CREATE TABLE student(intCarrierId INT PRIMARY KEY, intBatchId INT);

```

**Function:**

```auto
msg.queryParameters = msg.payload;
return msg;

```

**Localhost PostgreSQL Server**  
Password: 1205

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13b4dfb8e231fa91ee46ac19fa68e5e500707f4d.png)

Please, help me to find the **solution**!  
Thanks in advance.

Tim

---

<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:** [4 April 2021 08:05 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/2 "2021-04-04T08:05:59Z")

</div>

Please tell us which postrgres node you are using as there are a number of them. If you look in the menu in Manage Palette you will see which one you have installed.

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 08:08 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/3 "2021-04-04T08:08:36Z")

</div>

Thanks for the reply.

I am using node-red-contrib-re-postgres.

---

<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:** [4 April 2021 08:20 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/4 "2021-04-04T08:20:47Z")

</div>

It is not clear to me from the node description that it is capable of creating tables. Have you tried a simple query to see if that works?  
First try adding a Catch node to see if that catches an error from it. Also watch the node-red log to see if there is anything relevant there.

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 08:33 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/5 "2021-04-04T08:33:45Z")

</div>

I have simplified it to just insert one column.

**Inject node:**

```auto
msg.payload = { "carrier_id": 50 }

```

**Template node:**

```auto
INSERT INTO public.tbltracking(carrier_id) VALUES ({{{payload}}});

```

Without any success..

**Node-RED View:**

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a800c80252e9c676f06af22063e27311a81aab83.png)

---

<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:** [4 April 2021 08:38 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/6 "2021-04-04T08:38:30Z")

</div>

You have to feed the catch node into a debug node so it displays any errors it catches.  
Try a SELECT operation rather than an Insert. Always best to start with the simplest operation.

---

<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:** [4 April 2021 08:42 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/7 "2021-04-04T08:42:54Z")

</div>

Have you set 'Return message on error' in the config?

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 08:46 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/8 "2021-04-04T08:46:31Z")

</div>

Okay thank you for your help so far.

Return message on error is on.  
Just tryed a simple SELECT statement. Dont get a output whatsoever.  
Query is tested in PgAdmin4.

---

<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:** [4 April 2021 08:54 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/9 "2021-04-04T08:54:14Z")

</div>

What OS are you running on?  
Can you start node red in a terminal and run it as far as trying the select operation please. Then copy/paste the log here (not screenshot please). When posting a log use the `</>` button at the top of the forum entry window and paste it in.

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 09:09 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/10 "2021-04-04T09:09:52Z")

</div>

Running Windows 10.  
64-bit operation system, x64-based processor.

```auto
4 Apr 11:09:00 - [info] Loading palette nodes
4 Apr 11:09:02 - [info] Dashboard version 2.28.2 started at /ui
4 Apr 11:09:02 - [warn] ------------------------------------------------------
4 Apr 11:09:02 - [warn] [node-red-contrib-postgres/PostgreSql] Type already registered
4 Apr 11:09:02 - [warn] [node-red-contrib-postgres-multi/PostgreSql] Type already registered
4 Apr 11:09:02 - [warn] [node-red-contrib-postgres-variable/PostgreSql] Type already registered
4 Apr 11:09:02 - [warn] ------------------------------------------------------
4 Apr 11:09:02 - [info] Settings file : C:\Users\timbo\.node-red\settings.js
4 Apr 11:09:02 - [info] Context store : 'default' [module=memory]
4 Apr 11:09:02 - [info] User directory : \Users\timbo\.node-red
4 Apr 11:09:02 - [warn] Projects disabled : editorTheme.projects.enabled=false
4 Apr 11:09:02 - [info] Flows file : \Users\timbo\.node-red\flows_LAPTOP-KD0SFV4F.json
4 Apr 11:09:02 - [info] Server now running at http://127.0.0.1:1880/
4 Apr 11:09:02 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

4 Apr 11:09:02 - [info] Starting flows
4 Apr 11:09:02 - [info] Started flows

```

---

<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:** [4 April 2021 09:14 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/11 "2021-04-04T09:14:31Z")

</div>

You appear to have multiple postres nodes installed. Remove all of them except re-postrges.

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 09:29 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/12 "2021-04-04T09:29:01Z")

</div>

Fixed. But the same issue as before..

```auto
4 Apr 11:28:06 - [info] Node-RED version: v1.2.9
4 Apr 11:28:06 - [info] Node.js version: v15.13.0
4 Apr 11:28:06 - [info] Windows_NT 10.0.18363 x64 LE
4 Apr 11:28:07 - [info] Loading palette nodes
4 Apr 11:28:08 - [info] Dashboard version 2.28.2 started at /ui
4 Apr 11:28:08 - [info] Settings file : C:\Users\timbo\.node-red\settings.js
4 Apr 11:28:08 - [info] Context store : 'default' [module=memory]
4 Apr 11:28:08 - [info] User directory : \Users\timbo\.node-red
4 Apr 11:28:08 - [warn] Projects disabled : editorTheme.projects.enabled=false
4 Apr 11:28:08 - [info] Flows file : \Users\timbo\.node-red\flows_LAPTOP-KD0SFV4F.json
4 Apr 11:28:08 - [info] Server now running at http://127.0.0.1:1880/
4 Apr 11:28:08 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

4 Apr 11:28:08 - [info] Starting flows
4 Apr 11:28:08 - [info] Started flows

```

It looks like I am doing every step right, but there is just no connection to the database? Is there a way to check if the configuration is solid?

---

<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:** [4 April 2021 09:35 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/13 "2021-04-04T09:35:51Z")

</div>

If you configure the db connection incorrectly does it show that it is not connected?

Edit: Also you are using an unsupported version of nodejs. I advise going back to 14 in case that is the issue. After you downgrade nodejs you will need to re-install node-red and go into your .node-red folder and run `npm install`.

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 09:37 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/14 "2021-04-04T09:37:04Z")

</div>

No doesn't show. But it is almost impossible that it is wrong.

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 09:39 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/15 "2021-04-04T09:39:46Z")

</div>

Mmm okay. I will go back to version 14. I will let you know if that was indeed the issue. Thanks for your help so far.

---

<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:** [4 April 2021 09:44 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/16 "2021-04-04T09:44:17Z")

</div>

> [@tboekhorst](#):
>
> No doesn't show.

You are right, if it is unable to connect there is no error or anything. That is not very clever of it.

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 10:02 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/17 "2021-04-04T10:02:23Z")

</div>

> [@Colin](#):
>
> Edit: Also you are using an unsupported version of nodejs. I advise going back to 14 in case that is the issue. After you downgrade nodejs you will need to re-install node-red and go into your .node-red folder and run `npm install` .

Unfortunately, no success with version 14.

---

<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:** [4 April 2021 10:10 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/18 "2021-04-04T10:10:12Z")

</div>

Sorry, I am out of ideas. Perhaps someone with more experience of the node can help.

---

<div class="post-metadata">

**Author:** ![tboekhorst](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tboekhorst](https://discourse.nodered.org/u/tboekhorst)\
**Post date:** [4 April 2021 10:11 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/19 "2021-04-04T10:11:15Z")

</div>

Ok, thanks anyways! I will post again, if I am able to crack this puzzle 😉

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2021 10:18 UTC](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620/20 "2021-04-04T10:18:39Z")

</div>

@tboekhorst

both `node-red-contrib-postgrestor-next` and `@digitaloak/node-red-contrib-digitaloak-postgresql` work on my RPi with node v14.15.1

I prefer `node-red-contrib-postgrestor-next`

[Next page](https://discourse.nodered.org/t/connection-node-red-to-postgresql-server/43620.md?page=2)
