Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Report errors "FATAL: role "XXX" does not exist" when POSTGRES_USER is customized.#1155

Chr15t0pher started this conversation inGeneral
Discussion options

I'm a totally newbie, trying to using a shell script to run postgres image.
Here is my code:

DB_USER="${POSTGRES_USER:=admin}"DB_PASSWORD="${POSTGRES_PASSWORD:=admin}"DB_NAME="${POSTGRES_DB:=scaffold}"DB_PORT="${POSTGRES_PORT:=5432}"DB_HOST="${POSTGRES_HOST:=localhost}"docker run \  --name"postgres_$(date'+%s')" \  -e POSTGRES_USER=${DB_USER} \  -e POSTGRES_PASSWORD=${DB_PASSWORD} \  -e POSTGRES_DB=${DB_NAME} \  -p"${DB_PORT}":5432 \  -d \  postgres -N 1000until PGPASSWORD="${DB_PASSWORD}" psql -h"${DB_HOST}" -U"${DB_USER}" -p"${DB_PORT}" -d"postgres" -c'\q';do>&2echo"Postgres is still unavailable - sleeping"  sleep 1done

The errors I've been able to see are:

psql: error: connection to server at"localhost" (127.0.0.1), port 5432 failed: FATAL:  role"admin" does not exist

What am I missing and how can I fix this so I can actually proceed with Postgres?
When i set DB_USER to the default valuepostgres, it is Ok. But i just don't know the reason.

You must be logged in to vote

Replies: 6 comments 1 reply

Comment options

I just tried this and I was able to connect. Maybe there is an issue with your docker networking. What do you get if you rundocker ps?

You must be logged in to vote
0 replies
Comment options

I just tried this and I was able to connect. Maybe there is an issue with your docker networking. What do you get if you rundocker ps?

I tried to rundocker ps, it worked as i expected, i got the activated containers.

docker ps --filter'name=postgres' --format'{{.ID}}'
CONTAINER ID   IMAGE      COMMAND                   CREATED         STATUS         PORTS                    NAMESbdb2469f4a82   postgres"docker-entrypoint.s…"   4 minutes ago   Up 4 minutes   0.0.0.0:5432->5432/tcp   postgres_1698292090

I thought after running
docker run \ --name "postgres_$(date '+%s')" \ -e POSTGRES_USER=${DB_USER} \ -e POSTGRES_PASSWORD=${DB_PASSWORD} \ -e POSTGRES_DB=${DB_NAME} \ -p "${DB_PORT}":5432 \ -d \ postgres -N 1000, i should manually set $DB_USER. Then, i tried to modify the script like this:

docker run \    --name"${RUNNING_POSTGRES_CONTAINER}" \    -e POSTGRES_USER=${DB_USER} \    -e POSTGRES_PASSWORD=${DB_PASSWORD} \    -e POSTGRES_DB=${DB_NAME} \    -p"${DB_PORT}":5432 \    -d \    postgres -N 1000sleep 5dockerexec -it$RUNNING_POSTGRES_CONTAINER psql -U$DB_USER -d$DB_NAME -c"CREATE USER$DB_USER WITH PASSWORD '$DB_PASSWORD';"

However, it reports :ERROR: role "admin" already exists.

You must be logged in to vote
0 replies
Comment options

I just tried this and I was able to connect. Maybe there is an issue with your docker networking. What do you get if you rundocker ps?

According tohttps://stackoverflow.com/questions/11919391/postgresql-error-fatal-role-username-does-not-exist, maybe i must use the system userpostgres to init database?

You must be logged in to vote
0 replies
Comment options

The user is successfully created. Do you have postgres installed locally as well? I am wondering if your script isn't connecting to your container postgres but another one.

You must be logged in to vote
1 reply
@L0o0p
Comment options

you are right, thank you!, i got the similar problem, and i used"ps aux | grep postgres"to check, and i found another pgsql existed, when i removed it, theproblem was solved.

Comment options

The user is successfully created. Do you have postgres installed locally as well? I am wondering if your script isn't connecting to your container postgres but another one.

Yes, i have installed locally. But i did not start local postgres, i just use thepsql as a tool to connect to the postgres container.

You must be logged in to vote
0 replies
Comment options

File "/home/gridsentry/imgaudit/GAudit/myenv/lib/python3.8/site-packages/psycopg2/init.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: role "gaudit" does not exist

Project

export ENV_HOME=$PWD
export ENV_PROJECT=GAudit
export ENV_DJANGO_SECRET_KEY='xxxxxxxxxxxxxxxxxxxxxxx
export PYTHONPATH=$ENV_HOME/backend
export ENV_SITE=im_gaudit

Database

export ENV_DB_USER=gaudit
export ENV_DB_NAME=imdev
export ENV_DB_PASSWORD="gaudit@123"

Super Admin

export ENV_ADMIN_USER=gsadmin
export ENV_ADMIN_PASSWORD="GS@dm!n24"
export ENV_ADMIN_EMAIL=admin@gmail.com

Server

export ENV_SERVER_TYPE=dev
export DEBUG=1

How to fix this issue?

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
4 participants
@Chr15t0pher@LaurentGoderre@yogeshuh@L0o0p
Converted from issue

This discussion was converted from issue #1138 on November 30, 2023 23:31.


[8]ページ先頭

©2009-2025 Movatter.jp