skip to Main Content

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?

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search