Postgres commands hang in Ubuntu machine

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

            image: ubuntu-2004:202107-02
        executor: ubuntu
            PGUSER: postgres
            DATABASE_URL: postgresql://postgres@localhost:5432/postgres
            TERM: xterm
            - 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:

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

I’m using code taken from CircleCI’s documentation with minor modifications:

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


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 to see if we can replicate the behavior.

I hope this helps!

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)

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 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 to your project under the project settings. An example of using either looks something like this:

      - image: circleci/ruby:2.4.1-node
          username: mydockerhub-user
          password: $DOCKERHUB_PASSWORD  # context / project UI env-var reference
          RAILS_ENV: test
          PGUSER: root

You might also find this documentation helpful for further information about database configurations. :slight_smile:

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?

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

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:

            - 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.)

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