# Can't connect to postgres 9.6 instance in macos executor

**URL:** <https://discuss.circleci.com/t/cant-connect-to-postgres-9-6-instance-in-macos-executor/29961>\
**Category:** Databases\
**Tags:** 2.0, support-team\
**Created:** [April 23, 2019, 11:10pm UTC](https://discuss.circleci.com/t/cant-connect-to-postgres-9-6-instance-in-macos-executor/29961 "2019-04-23T23:10:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![treble37](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/treble37/32/21409_2.png) [@treble37](https://discuss.circleci.com/u/treble37)\
**Post date:** [April 23, 2019, 11:10pm UTC](https://discuss.circleci.com/t/cant-connect-to-postgres-9-6-instance-in-macos-executor/29961/1 "2019-04-23T23:10:12Z")

</div>

Hello,

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.

```
  ios:
    macos:
      xcode: "10.0.0"
    <<: *app-environment
    <<: *ios-environment
    steps:
      #- 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=127.0.0.1 --command="CREATE ROLE postgres;"
      - run: |
          /usr/local/Cellar/postgresql@9.6/9.6.11/bin/psql --host=127.0.0.1 --command="\du"
        #- run: brew services stop postgresql@9.6
        #- run: brew services start postgresql@9.6
      - checkout
```

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [April 24, 2019, 5:39pm UTC](https://discuss.circleci.com/t/cant-connect-to-postgres-9-6-instance-in-macos-executor/29961/2 "2019-04-24T17:39:44Z")

</div>

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.

> [@treble37](#):
>
> I had to edit the pg\_hba.conf, but that seems like impossible in a circle ci build configuration

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.
