# Setting up Postgres for NodeJS \[ Error: "sudo: unknown user: postgres"\]

**URL:** <https://discuss.circleci.com/t/setting-up-postgres-for-nodejs-error-sudo-unknown-user-postgres/20268>\
**Category:** Databases\
**Tags:** postgresql, nodejs\
**Created:** [February 24, 2018, 4:56am UTC](https://discuss.circleci.com/t/setting-up-postgres-for-nodejs-error-sudo-unknown-user-postgres/20268 "2018-02-24T04:56:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Busyreadingsomething](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/busyreadingsomething/32/12196_2.png) [@Busyreadingsomething](https://discuss.circleci.com/u/Busyreadingsomething)\
**Post date:** [February 24, 2018, 4:56am UTC](https://discuss.circleci.com/t/setting-up-postgres-for-nodejs-error-sudo-unknown-user-postgres/20268/1 "2018-02-24T04:56:06Z")

</div>

Hi there,

I’m trying to set up postgres for circleci. Currently I need it to run some tests for my seed data, but I can’t get psql work. I attempted to use sudo -u postgres command from the documentation, but it keeps on saying that there is an error. I tried changing the environment user variable, however, that didn’t help.

Any ideas would be greatly appreciated. Here is the current config of my circle.yml:

> version: 2  
> jobs:  
> build:  
> docker:  
> # specify the version you desire here  
> - image: circleci/node:9.3.0
> 
> ```
> # Specify service dependencies here if necessary
> # CircleCI maintains a library of pre-built images
> # documented at https://circleci.com/docs/2.0/circleci-images/
> - image: circleci/postgres:9.6.2-alpine
> environment:
> - POSTGRES_USER: postgres
> - POSTGRES_DB: thumbnail
> 
> working_directory: ~/repo
> 
> steps:
> - checkout
> 
> # Download and cache dependencies
> - restore_cache:
> keys:
> - v1-dependencies-{{ checksum "package.json" }}
> # fallback to using the latest cache if no exact match is found
> - v1-dependencies-
> 
> - run: npm install
> 
> - save_cache:
> paths:
> - node_modules
> key: v1-dependencies-{{ checksum "package.json" }}
> 
> - run:
> # Add a password to the `ubuntu` user, since Postgres is configured to
> # always ask for a password without sudo, and fails without one.
> command: sudo -u postgres psql -p 5433 -c "create user ubuntu with password 'ubuntu';"
> command: sudo -u postgres psql -p 5433 -c "alter user ubuntu with superuser;"
> 
> # Create a new test database.
> command: sudo -u postgres psql -p 5433 -c "create database test;"
> 
> - run: 
> name: Set Up DB
> command: |
> knex migrate:latest
> knex seed:run
>     
> # run tests!
> - run: npm test
> 
> ```

---

<div class="post-metadata">

**Author:** ![Busyreadingsomething](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/busyreadingsomething/32/12196_2.png) [@Busyreadingsomething](https://discuss.circleci.com/u/Busyreadingsomething)\
**Post date:** [February 25, 2018, 12:24am UTC](https://discuss.circleci.com/t/setting-up-postgres-for-nodejs-error-sudo-unknown-user-postgres/20268/2 "2018-02-25T00:24:55Z")

</div>

Fixed the problem. I was assuming the image wasn’t creating my database, and I wanted to use a script that would have psql create one.

Changed user environment variable:

> ```
> environment:
> - POSTGRES_USER: root // preference change
> - POSTGRES_DB: thumbnail
> 
> ```

Removed:  
- run:  
# Add a password to the `ubuntu` user, since Postgres is configured to  
# always ask for a password without sudo, and fails without one.  
command: sudo -u postgres psql -p 5433 -c “create user ubuntu with password ‘ubuntu’;”  
command: sudo -u postgres psql -p 5433 -c “alter user ubuntu with superuser;”

```
    # Create a new test database.
      command: sudo -u postgres psql -p 5433 -c "create database test;"

  - run: 
      name: Set Up DB
      command: |
        knex migrate:latest
        knex seed:running_man

```

Added the knex commands in a script to start the migration and seeding. The sudo wasn’t needed.

Added the process.env in my scripts where they were asking for the user and db to work locally and etc.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:41am UTC](https://discuss.circleci.com/t/setting-up-postgres-for-nodejs-error-sudo-unknown-user-postgres/20268/3 "2018-06-18T11:41:51Z")

</div>

Closed on June 18, 2018, 11:41am UTC


