laptop icon indicating copy to clipboard operation
laptop copied to clipboard

Fix: Error if the user/role with Postres already exists

Open liamstevens111 opened this issue 2 years ago • 0 comments

Issue

There is an issue with postgresql installation, more specifically creating the user role postgres if the user role already exists.

The part of the script with the issue:

setup_postgres:

pg_ctl -D "$HOMEBREW_PREFIX/var/postgres" start
  "$HOMEBREW_PREFIX/opt/postgres/bin/createuser" -s postgres
  pg_ctl -D "$HOMEBREW_PREFIX/var/postgres" stop

I already had a postgres role/user installed so this caused the following error:

server started
2022-07-22 16:48:40.978 +07 [42818] ERROR: role "postgres" already exists
2022-07-22 16:48:40.978 +07 [42818] STATEMENT: CREATE ROLE postgres SUPERUSER CREATED CREATEROLE INHERIT LOGIN;
createuser: error: creation of new role failed: ERROR: role"postgres" already exists 
failed

Would this also cause a problem if although the role didn't exist but the service was also already running, ie from installation outside of brew, such as via Postgres.app?

I had to manually remove the above part so I could continue to the asdf installation step.

Should the postgres setup and role creation be optional? Or shouldhave pre-checks if postgres is already running or the user role already exists?

Expected

I expected that it would not cause errors if the script was ran multiple times.

Steps to reproduce

  1. Have Postgres already installed with a user/role postgres
  2. Run the script

liamstevens111 avatar Jul 22 '22 11:07 liamstevens111