0

I tried to start my postgresql database after reinstalling WSL, I started the server successfully

nnaemekaxjohn@Nnaemeka:/mnt/c/Users/HP/documents/the_age_project/postgresql-11.17$ bin/pg_ctl -D demo -l logfile start
waiting for server to start....... done
server started
nnaemekaxjohn@Nnaemeka:/mnt/c/Users/HP/documents/the_age_project/postgresql-11.17$ bin/psql --port=5430 demo
psql: FATAL:  role "nnaemekaxjohn" does not exist

But when I try to connect to my demo database I get the Fatal error, I suspect this is as a result of changing my ubuntu username during WSL reinstallation.

How can this error be fixed? I’ve gone through many answers on Stackoverflow and none seemed to help as they were not running Postgres on source code.

2 Answers2

0

run this command first

./createuser --port=5430 --username=postgres --superuser --createdb --createrole --login nnaemekaxjohn 

then reset the cluster using this coommand

./pg_ctl -D demo reset -l logfile
  • When I ran the first command, I got the following error; `createuser: could not connect to database template1: FATAL: role "postgres" does not exist` – Nnaemeka Daniel John Jul 18 '23 at 22:25
0

You can create a new user with necessary privileges granted.

First check for the existing users:

bin/psql --port=5430 -c "\du"

If your username is not listed then create a new user:

bin/createuser -P myName

Next, grant privileges to the user:

bin/psql --port=5430 -c "GRANT ALL PRIVILEGES ON DATABASE demo TO myName;"

Note: Consider to set name same as your ubuntu username.

Huzaifa
  • 484
  • 4
  • 8