1

I am trying to connect to my postgres database via Docker. I have confirmed that it is running (port 5432) along with my database manager tool called Adminer (port 8080). So far so good!

Next, I attempt to make my database migrations. (Here's the Makefile) by running the following command:

FYI, migrate is a database migration tool for Golang

migrate -source file://migrations -database postgres://postgres:secret@localhost:5432/syndicate?sslmode=disable up

My database URL checks out: dbdriver://username:password@host:port/dbname?param1=true&param2=false

But receive this error:

error: pq: role "postgres" does not exist

Here's what I know:

Why would the default postgres user require a role?

I created this issue and have been narrating it as I receive feedback from various platforms. Here's my full repo

One last thing...

The only thing i could find that was similar to my issue is this documentation, PostgreSQL 1.3. Creating a Database stating:

Another response could be this:

createdb: could not connect to database postgres: FATAL: role "joe" does not exist

where your own login name is mentioned. This will happen if the administrator has not created a PostgreSQL user account for you. (PostgreSQL user accounts are distinct from operating system user accounts.) If you are the administrator, see Chapter 18 for help creating accounts. You will need to become the operating system user under which PostgreSQL was installed (usually postgres) to create the first user account

That is all, thank you!

Edit: As suggested, I added a POSTGRES_USER to database.env:

POSTGRES_PASSWORD=secret
POSTGRES_DB=syndicate
POSTGRES_USER=user

database.env is referred to in docker-compose.yml:

version: '3.1'
services:
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
  db:
    image: "postgres"
    env_file:
      - database.env # configure postgres
    ports:
      - 5432:5432

Now receiving error: error: pq: role "user" does not exist

8
  • "go" and "golang-migrate" are irrelevant tags. Commented Jan 12, 2021 at 1:25
  • I removed the tags, thanks Commented Jan 12, 2021 at 1:29
  • Can you connect with psql? Try psql -h localhost -U user -d syndicate Commented Jan 12, 2021 at 2:13
  • Received the same error, its as if the database doesn't exist. I can confirm that I have a local image running Commented Jan 12, 2021 at 2:34
  • Please paste the output of the following: a) docker-compose ps b) docker ps c) ps -ef | grep postgres d) docker inspect <container id> Commented Jan 12, 2021 at 8:49

1 Answer 1

1

In PostgreSQL, a user is a type of role. If role "postgres" does not exist then it means that you don't have a "postgres" user in the DB.

Look into the Docker container settings. The official builds require you to provide the name of the default user. Check what user the gave it as the default.

Sign up to request clarification or add additional context in comments.

6 Comments

"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." - hub.docker.com/_/postgres
Am I looking at the correct documentation?
@ConnorCantrell yes that's it
Yeah, I tried defining a user. I continued to have the same error
@ConnorCantrell what user did you define? Please attach the docker-compose.yml contents in your question.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.