# Postgres commands hang in Ubuntu machine

**URL:** <https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514>\
**Category:** Build Environment\
**Tags:** postgresql, config, ubuntu, postgres\
**Created:** [October 12, 2021, 4:59pm UTC](https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514 "2021-10-12T16:59:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cali](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cali](https://discuss.circleci.com/u/cali)\
**Post date:** [October 12, 2021, 4:59pm UTC](https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514/1 "2021-10-12T16:59:33Z")

</div>

I’m creating a CircleCI config file with the following excerpt:

```auto
executors:
    ubuntu:
        machine:
            image: ubuntu-2004:202107-02
jobs:
    build:
        executor: ubuntu
        environment:
            PGUSER: postgres
            DATABASE_URL: postgresql://postgres@localhost:5432/postgres
            TERM: xterm
        steps:
            - checkout
            - run: sudo apt-get update
            - run: sudo apt-get install postgresql
            - run: psql -V
            - run: pg_isready
            - run: |
                psql \
                -d $DATABASE_URL \
                -c "CREATE TABLE test (name char(25));"
            - run: |
                psql \
                -d $DATABASE_URL \
                -c "INSERT INTO test VALUES ('John'), ('Joanna'), ('Jennifer');"
            - run: |
                psql \
                -d $DATABASE_URL \
                -c "SELECT * from test;"

```

All commands prior to and including `pg_isready` exit without error, but no matter what I try the next command (CREATE TABLE) hangs. The CircleCI log displays this with no further output:

```auto
#!/bin/bash -eo pipefail
psql \
-d $DATABASE_URL \
-c "CREATE TABLE test (name char(25));"

```

I’m using code taken from CircleCI’s documentation with minor modifications:  
[https://circleci.com/docs/2.0/databases/](https://circleci.com/docs/2.0/databases/)

This type of work is new to me – I’m hoping it’s an obvious missing command – thanks in advance!

---

<div class="post-metadata">

**Author:** ![JCi](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jci/32/27318_2.png) [@JCi](https://discuss.circleci.com/u/JCi)\
**Post date:** [October 12, 2021, 5:32pm UTC](https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514/2 "2021-10-12T17:32:27Z")

</div>

Hello,

Thank you for posting on CircleCI Discuss!

I was able to replicate your build and once I reached the CREATE TABLE step, I noticed the job running with the following output:  
`Password for user postgres:`

Are you also seeing this password input message causing the job to run indefinitely?

If not, we can also try [rerunning the build with SSH](https://circleci.com/docs/2.0/ssh-access-jobs/#steps) to see if we can replicate the behavior.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![cali](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cali](https://discuss.circleci.com/u/cali)\
**Post date:** [October 12, 2021, 5:45pm UTC](https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514/3 "2021-10-12T17:45:29Z")

</div>

> [@JCi](#):
>
> Are you also seeing this password input message causing the job to run indefinitely?

Thanks for your response! The password input message is not visible, the CircleCI process indicator just spins with no indication. However – this time I let it time-out, and sure enough there was a password input message. (The process time-out error said something like “no activity for 10min”.)

Thanks for pointing me in the right direction. My question now is should the CircleCI GUI be showing this password request message, or is that expected behavior to show nothing? Being new at this, it stumped me for a while! I’m on Firefox, in case that makes a difference.

(And bonus points, if you have a tip on how to allow the flow to continue non-interactively! Thanks though for figuring out what’s going on)

---

<div class="post-metadata">

**Author:** ![JCi](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jci/32/27318_2.png) [@JCi](https://discuss.circleci.com/u/JCi)\
**Post date:** [October 12, 2021, 6:52pm UTC](https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514/4 "2021-10-12T18:52:41Z")

</div>

So glad to hear we’re heading in the right direction!

I was able to see the request for a password in the GUI by clicking on the job while it was running without waiting for our default timeout (which is 10 minutes but can be changed).

To avoid this you can leverage [contexts](https://circleci.com/docs/2.0/contexts/#) which allows for securing and sharing environment variables. You can create a context by navigating to your organization’s settings.

It is also worth noting you can add [environment variables](https://circleci.com/docs/2.0/env-vars/#example-configuration-of-environment-variables) to your project under the project settings. An example of using either looks something like this:

```auto
    docker:
      - image: circleci/ruby:2.4.1-node
        auth:
          username: mydockerhub-user
          password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
        environment:
          RAILS_ENV: test
          PGHOST: 127.0.0.1
          PGUSER: root

```

You might also find [this documentation](https://circleci.com/docs/2.0/postgres-config/#) helpful for further information about database configurations. 🙂

---

<div class="post-metadata">

**Author:** ![cali](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cali](https://discuss.circleci.com/u/cali)\
**Post date:** [October 12, 2021, 7:23pm UTC](https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514/5 "2021-10-12T19:23:01Z")

</div>

Interesting! I’ve tested Mac Firefox and Chrome but neither show me the output… When I click on “Open step output in new tab”, it looks the same as the step on the job page. When I click “Open raw step output” it displays a blank page… Am I clicking/looking at the wrong spot?

 ![Screen Shot 2021-10-12 at 12.16.10 PM](https://global.discourse-cdn.com/circleci/original/3X/4/3/4381a34a85faac5ca40e8a9521b967ce84f8d2f9.png)

Regardless, I will certainly update the default timeout, thanks.

---

<div class="post-metadata">

**Author:** ![cali](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cali](https://discuss.circleci.com/u/cali)\
**Post date:** [October 13, 2021, 6:30am UTC](https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514/6 "2021-10-13T06:30:42Z")

</div>

Following up in case any others encounter this: My specific issue was that psql kept going into interactive mode. This occurred for any psql commands – not just password request. I was able to solve the issue for CircleCI by piping my command to `cat`. For example:

```auto
            - run:
                name: Create test database
                command: sudo -u postgres createdb testdb | cat

```

Additionally, turning off the page option worked as well, but was a bit more verbose: `psql -P pager=off`

Please add to this thread if you find a better way! (I tried environment vars but couldn’t get them to stick.)

---

<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:** [October 23, 2021, 6:31am UTC](https://discuss.circleci.com/t/postgres-commands-hang-in-ubuntu-machine/41514/7 "2021-10-23T06:31:18Z")

</div>

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