# Postgres image breaking changes (role postgres not found)

**URL:** <https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024>\
**Category:** Databases\
**Tags:** postgresql, docker\
**Created:** [September 11, 2018, 9:20am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024 "2018-09-11T09:20:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![anzecesar](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/anzecesar/32/211_2.png) [@anzecesar](https://discuss.circleci.com/u/anzecesar)\
**Post date:** [September 11, 2018, 9:20am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/1 "2018-09-11T09:20:51Z")

</div>

Yesterday all our builds suddenly started failing on a project which has postgres:10-alpine-ram set up.

I see new tags were built and published yesterday ([https://hub.docker.com/r/circleci/postgres/tags/](https://hub.docker.com/r/circleci/postgres/tags/)) aligning with when builds started failing.

I don’t see any changes to the postgres Dockerfile, so I’m assuming the breaking change is coming from upstream ([https://github.com/CircleCI-Public/circleci-dockerfiles/commit/54985a27f8eb93725645801983414be1beea792d](https://github.com/CircleCI-Public/circleci-dockerfiles/commit/54985a27f8eb93725645801983414be1beea792d)).

The failure I’m seeing is:

```
2018-09-11 09:07:01.912 UTC [910] FATAL: role "postgres" does not exist

```

which is an odd one, since by default postgres user & db should be set up.

connecting to the db as user `root` fixes it, but I don’t think introducing breaking changes like this to the images is a good practice. I know that the tag 10 is rolling, but I wouldn’t expect such breaking changes.

When there need to be breaking changes, please announce them. Maybe under different tags.

Hopefully someone else will find this solution helpful.

---

<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:** [September 11, 2018, 9:30am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/2 "2018-09-11T09:30:08Z")

</div>

How are you starting this container? I believe there are subkeys to specify a username, and I wonder if you could use this to specify a user you wish to connect through.

---

<div class="post-metadata">

**Author:** ![ShaunGillies](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@ShaunGillies](https://discuss.circleci.com/u/ShaunGillies)\
**Post date:** [September 11, 2018, 9:39am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/3 "2018-09-11T09:39:20Z")

</div>

Having a similar issue, but connecting as root did not solve the issue. Taking a look at the logs between yesterday’s and today’s environments, there is a difference in the “Container circleci/postgres:9.5” step.

Yesterday:

```
...
waiting for server to start....LOG: database system was shut down at 2018-09-10 11:56:48 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
 done
server started
CREATE DATABASE

CREATE ROLE

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
...

```

and today:

```
...
waiting for server to start....LOG: database system was shut down at 2018-09-11 09:07:42 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
 done
server started
CREATE DATABASE

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
...

```

Clearly, the part of this step that is creating the role has been changed or omitted.

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 11, 2018, 9:43am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/4 "2018-09-11T09:43:23Z")

</div>

We automatically build images as they’re pushed from upstream, so the following change to the postgres image, where the username ‘postgres’ was being hardcoded:

`eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"`

To respecting the environment variable:

`eval 'initdb --username="$POSTGRES_USER" --pwfile=<(echo "$POSTGRES_PASSWORD") '"$POSTGRES_INITDB_ARGS"`

Username is now populated with the value of `POSTGRES_USER`, which we set in the CircleCI dockerfile as `root`:

```auto
ENV POSTGRES_USER=root \
    POSTGRES_DB=circle_test

```

For now, connecting as the user `root` should solve the issue, or defining any other username using `POSTGRES_USER`.

The [exact changes to the postgres image can be viewed](https://github.com/docker-library/postgres/commit/3f585c58df93e93b730c09a13e8904b96fa20c58#diff-acde90d7af0c3026a11fb904086b196a) in this github diff. No changes have been made to the [CircleCI dockerfile](https://github.com/CircleCI-Public/circleci-dockerfiles/blob/master/postgres/images/10.5-alpine/Dockerfile). Apologies for any inconvenience caused, but sometimes upstream changes do cause issues we can’t predict due to how we currently handle building convenience images.

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 11, 2018, 9:56am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/5 "2018-09-11T09:56:34Z")

</div>

That’s odd, could you link your build? If it’s closed source it’ll only be visible to CircleCI employees.

---

<div class="post-metadata">

**Author:** ![ShaunGillies](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@ShaunGillies](https://discuss.circleci.com/u/ShaunGillies)\
**Post date:** [September 11, 2018, 10:15am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/6 "2018-09-11T10:15:34Z")

</div>

Sure thing: [https://circleci.com/gh/LumenResearch/viewpoints/890](https://circleci.com/gh/LumenResearch/viewpoints/890)

---

<div class="post-metadata">

**Author:** ![anzecesar](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/anzecesar/32/211_2.png) [@anzecesar](https://discuss.circleci.com/u/anzecesar)\
**Post date:** [September 11, 2018, 10:41am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/7 "2018-09-11T10:41:11Z")

</div>

Thanks for looking into it!

The change is not in line with their (upstream Docker) docs:

> `POSTGRES_USER`  
> This optional environment variable is used in conjunction with `POSTGRES_PASSWORD` to set a user and its password. This variable will create the specified user with superuser power and a database with the same name. If it is not specified, then the default user of `postgres` will be used.

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 11, 2018, 11:10am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/8 "2018-09-11T11:10:36Z")

</div>

The only difference is that we set `POSTGRES_USER` in our dockerfile for the convenience image:

> <https://github.com/CircleCI-Public/circleci-dockerfiles/blob/master/postgres/images/10.2-alpine/Dockerfile>

For this reason it won’t default to `postgres` regardless of whether the user sets the environment variable.

---

<div class="post-metadata">

**Author:** ![ShaunGillies](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@ShaunGillies](https://discuss.circleci.com/u/ShaunGillies)\
**Post date:** [September 11, 2018, 11:17am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/9 "2018-09-11T11:17:28Z")

</div>

I should mention that this is the 9.5 image, but if that’s the only difference, can you think of another reason why the build is failing? Thank you for responding so promptly.

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 11, 2018, 11:21am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/10 "2018-09-11T11:21:18Z")

</div>

Sorry @ShaunGillies, was replying to @anzecesar – do you have any postgres config in his django settings, and if so could you update this as well? To use `root` for username and `circle_test` for the db, although I also can’t see a reason there shouldn’t be a `postgres` database for django to connect to.

---

<div class="post-metadata">

**Author:** ![anzecesar](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/anzecesar/32/211_2.png) [@anzecesar](https://discuss.circleci.com/u/anzecesar)\
**Post date:** [September 11, 2018, 11:36am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/11 "2018-09-11T11:36:10Z")

</div>

It did before yesterday though. Or for whatever reason, before the build yesterday, postgres user was available.

---

<div class="post-metadata">

**Author:** ![Cormac](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cormac/32/18955_2.png) [@Cormac](https://discuss.circleci.com/u/Cormac)\
**Post date:** [September 11, 2018, 11:38am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/12 "2018-09-11T11:38:03Z")

</div>

You could still set it to `postgres` by defining the environment variable `POSTGRES_USER = postgres`, but the dockerfile I linked sets it to `root`. The environment variable wasn’t previously respected – it was set to `postgres` regardless. Now it is respected, so it’s set to `root`.

---

<div class="post-metadata">

**Author:** ![ShaunGillies](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@ShaunGillies](https://discuss.circleci.com/u/ShaunGillies)\
**Post date:** [September 11, 2018, 11:43am UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/13 "2018-09-11T11:43:29Z")

</div>

Ah, yes, it was still being set to another user name in the settings file. Thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [September 11, 2018, 3:47pm UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/14 "2018-09-11T15:47:40Z")

</div>

It looks like the cause and possible solution was already uncovered here, just linking to my response here just in case: [CircleCI Postgres Image suddenly causing problems? "role postgres not found"](https://discuss.circleci.com/t/circleci-postgres-image-suddenly-causing-problems-role-postgres-not-found/25044)

---

<div class="post-metadata">

**Author:** ![rose](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rose/32/7816_2.png) [@rose](https://discuss.circleci.com/u/rose)\
**Post date:** [September 11, 2018, 7:10pm UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/15 "2018-09-11T19:10:18Z")

</div>

We are pushing changes to mitigate this issue—please see [https://discuss.circleci.com/t/convenience-images-update-removing-hardcoded-postgres-user](https://discuss.circleci.com/t/convenience-images-update-removing-hardcoded-postgres-user) 🙏

---

<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:** [December 10, 2018, 7:10pm UTC](https://discuss.circleci.com/t/postgres-image-breaking-changes-role-postgres-not-found/25024/16 "2018-12-10T19:10:20Z")

</div>

Closed on December 10, 2018, 7:10pm UTC

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