I get the error "(psycopg2.OperationalError) FATAL: role "wsb" does not exist", but the user does exits



  • I am trying connect to my postgress database using SQLAlchemy. I was working fine yesterday (01/27/22). Now I get the following error:

    sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: role "wsb" does not exist

    Only the user does exist.

                                       List of roles
     Role name |                         Attributes                         | Member of 
    -----------+------------------------------------------------------------+-----------
     wsb       | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
     wsb2      |                                                            | {}
    

    As you can see I tried making another user "wsb2", but that didn't work either. Below is my script:

    db_string = "postgresql://wsb:wsb@localhost:5432/wsb"
    

    db = create_engine(db_string)
    meta = MetaData()

    submissions_table = Table('wsb_submissions', meta,
    Column('index', INTEGER),
    Column('submission_id', TEXT),
    Column('title', TEXT),
    Column('created', TIMESTAMP),
    Column('author', TEXT),
    Column('ticker_mentioned', TEXT),
    Column('subreddit', TEXT),
    Column('emotes', ARRAY(TEXT)),
    Column('rocket_emotes', INTEGER)
    )

    comments_table = Table('wsb_comments', meta,
    Column('index', INTEGER),
    Column('comment_id', INTEGER),
    Column('body', TEXT),
    Column('created', TIMESTAMP),
    Column('author', TEXT),
    Column('rocket_emotes', INTEGER),
    Column('subreddit', TEXT),
    Column('emotes', ARRAY(TEXT)),
    Column('submission_key', TEXT)
    )
    db.connect()

    also here is my Dockerfile:

    FROM postgres:13.2
    

    ENV POSTGRES_PASSWORD=wsb
    ENV POSTGRES_USER=wsb
    ENV POSTGRES_DB=wsb

    COPY wsb.sql /docker-entrypoint-initdb.d/
    EXPOSE 5432



  • So this worked for me. I am relatively new to operating systems, so idk if there are any consequences that I'm unaware of.

    my solution: in terminal run:

    lsof -i:5432
    sudo kill [PID]
    

    then rebuild the image and restart the container.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2