# Can to create database using node-red?

**URL:** <https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528>\
**Category:** General\
**Created:** [29 September 2020 21:55 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528 "2020-09-29T21:55:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [29 September 2020 21:55 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/1 "2020-09-29T21:55:35Z")

</div>

Hi,  
I would like to `create database` of **PostgreSQL** using Node-RED, but when searching with "_postgre_" keyword, all nodes need to configure **database name**.

I tried to use the exec node but don't know what the input command is right.  
Can I create the database using node-red?

Any idea will be great.  
Thanks.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [29 September 2020 22:16 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/2 "2020-09-29T22:16:33Z")

</div>

If the nodes don't support it, you will need to read up on the command line usage of PostgreSQL.

> **[Startpage.com Search results](https://www.startpage.com/do/dsearch?query=postges%2Bcommand%2Bline&cat=web&pl=opensearch&language=english_uk)**

Once you can run the command from the command line, you can then translate that to the exec node.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [29 September 2020 22:33 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/3 "2020-09-29T22:33:06Z")

</div>

Normally to `create database` PostgreSQL from command-line I execute a script like below:

```auto
psql -U postgres
input password
CREATE DATABASE mydb;

```

In `exec` node, I enter **psql -U postgres** , the password entry line appears on the cmd side, after I enter password, the node-red side is still connected and not finished.

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

The translation of command-line to the `exec` node is how can you specify it to help me get it?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [29 September 2020 22:37 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/4 "2020-09-29T22:37:10Z")

</div>

maybe look at the psql manual for ways to not have to pass the password

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [30 September 2020 00:30 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/5 "2020-09-30T00:30:25Z")

</div>

> <https://stackoverflow.com/questions/6523019/postgresql-scripting-psql-execution-with-password/6524167#6524167>

> <https://stackoverflow.com/questions/6405127/how-do-i-specify-a-password-to-psql-non-interactively/6405162#6405162>

Internet searches should always be your first port of call.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [30 September 2020 01:39 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/6 "2020-09-30T01:39:09Z")

</div>

> [@dceejay](#):
>
> maybe look at the psql manual for ways to not have to pass the password

> [@TotallyInformation](#):
>
> Internet searches should always be your first port of call.

@dceejay, @TotallyInformation The input password to login is necessary for security reasons, so I did not think that can set to bypass the password input so I did not ask google first, it bothers you @@.  
Thanks for the instructions!

> [@TotallyInformation](#):
>
> Once you can run the command from the command line, you can then translate that to the exec node.

After setting up bypass password when executing command "_psql -U postgres_". I input the following command in the **Command** of `exec` node:

```auto
psql -U postgres;CREATE DATABASE dbTest;

```

![node-exec-1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d905c30b07847bed6c2c1e11bac2d791c32082f.png)  
...but still start entering the **password of CREATE** on the cmd side, I tried to enter the password of the _postgres_ user and it got an error:

 ![node-exec-2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/8824d707f73adb2043b369ed7ec326872e255d8b.png)

I did a google search but I don't know why entering this password.  
Did I enter the command of PostgreSQL in **Command** of `exec` node correctly?  
Thanks!

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [30 September 2020 06:45 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/7 "2020-09-30T06:45:53Z")

</div>

You probably don't want to append the payload in the exec node. Untick that option.

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [30 September 2020 08:46 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/8 "2020-09-30T08:46:42Z")

</div>

I have untick that option but the result still does not change,  
still need to enter password of CREATE on the cmd side. 😐

---

<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:** [29 November 2020 08:46 UTC](https://discourse.nodered.org/t/can-to-create-database-using-node-red/33528/9 "2020-11-29T08:46:51Z")

</div>

Closed on 29 November 2020 08:46 UTC

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