Can't connect to postgres 9.6 instance in macos executor


I’m trying to setup a postgres instance in a macos environment, so I’m using the macos executor with homebrew. Unfortunately, I end up with psql: could not connect to server: Connection refused when trying to create a postgres role (or sometimes I’ll get psql: FATAL: role "ubuntu" does not exist which is baffling as I do not set the POSTGRES_USER to ubuntu in any the yaml merge key environment settings. The commented out lines are things I’ve tried to no avail (I set POSTGRES_USER to distiller)

Some preliminary searching revealed I had to edit the pg_hba.conf, but that seems like impossible in a circle ci build configuration, so I opted to add this line run: /usr/local/Cellar/postgresql@9.6/9.6.11/bin/initdb /usr/local/var/postgres --auth=trust --auth-host=trust --auth-local=trust. Can anyone point out a solution? The whole point of this is to spin up postgres in a MacOS environment that can then be used with a web application.

      xcode: "10.0.0"
    <<: *app-environment
    <<: *ios-environment
      #- run: brew install elixir
      - run: brew install postgresql@9.6
      - run: brew services start postgresql@9.6
      - run:
          name: "echo v"
          command: |
            V=$(ls /usr/local/Cellar/postgresql@9.6)
            echo $V
      - run: whoami
      - run: echo $POSTGRES_USER
      - run: /usr/local/Cellar/postgresql@9.6/9.6.11/bin/initdb /usr/local/var/postgres --auth=trust --auth-host=trust --auth-local=trust
        #- run: /usr/local/Cellar/postgresql@9.6/9.6.11/bin/pg_ctl -D /usr/local/var/postgres -l logfile start
      - run: /usr/local/Cellar/postgresql@9.6/9.6.11/bin/createuser -U $POSTGRES_USER
      - run: /usr/local/Cellar/postgresql@9.6/9.6.11/bin/createuser -s $POSTGRES_USER
      - run: |
          /usr/local/Cellar/postgresql@9.6/9.6.11/bin/psql --host= --command="CREATE ROLE postgres;"
      - run: |
          /usr/local/Cellar/postgresql@9.6/9.6.11/bin/psql --host= --command="\du"
        #- run: brew services stop postgresql@9.6
        #- run: brew services start postgresql@9.6
      - checkout

I don’t have much experience with MacOS, but if I were faced with this problem, I’d get a post-build SSH session, and see if the database server is running. There should also be some database server logs that may indicate what trouble it is having, e.g. opening a server listener.

You can’t do manual edits, but you can automate them. A good approach is to install server software, make changes to config (e.g. with Sed search-and-replace commands) and then start the server.