How to configure postgresql for the first time?

前端 未结 10 876
太阳男子
太阳男子 2020-11-28 16:54

I have just installed postgresql and I specified password x during installation. When I try to do createdb and specify any password I get the message:

10条回答
  •  囚心锁ツ
    2020-11-28 17:34

    If you're running macOS like I am, you may not have the postgres user.

    When trying to run sudo -u postgres psql I was getting the error sudo: unknown user: postgres

    Luckily there are executables that postgres provides.

    createuser -D /var/postgres/var-10-local --superuser --username=nick
    createdb --owner=nick
    

    Then I was able to access psql without issues.

    psql
    psql (10.2)
    Type "help" for help.
    
    nick=#
    

    If you're creating a new postgres instance from scratch, here are the steps I took. I used a non-default port so I could run two instances.

    mkdir /var/postgres/var-10-local
    pg_ctl init -D /var/postgres/var-10-local
    

    Then I edited /var/postgres/var-10-local/postgresql.conf with my preferred port, 5433.

    /Applications/Postgres.app/Contents/Versions/10/bin/postgres -D /Users/nick/Library/Application\ Support/Postgres/var-10-local -p 5433
    
    createuser -D /var/postgres/var-10-local --superuser --username=nick --port=5433
    createdb --owner=nick --port=5433
    

    Done!

提交回复
热议问题