Reputation: 119
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¶m2=false
But receive this error:
error: pq: role "postgres" does not exist
Here's what I know:
syndicate
(database.env)postgres
(database.env)secret
(database.env)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
Upvotes: 1
Views: 485
Reputation: 1518
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.
Upvotes: 1