initdb in Postgres.app does not create postgres &template1 database

402 Views Asked by At

I installed postgres.app 2.4.2 on macos(big sur 11.4).

I wanted to initdb with locale=C, so run the command initdb -D "/Users/xxx/Library/Application Support/Postgres/var-131" -U postgres --encoding=UTF-8 --locale=C --auth-local=trust and the logging

(base) > $ initdb -D "/Users/xxx/Library/Application Support/Postgres/var-13_1" -U postgres --encoding=UTF-8 --locale=C --auth-local=trust
The files belonging to this database system will be owned by user "yy".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /Users/xxx/Library/Application Support/Postgres/var-13_1 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Hongkong
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D '/Users/xxx/Library/Application Support/Postgres/var-13_1' -l logfile start

In PG document(https://www.postgresql.org/docs/13/app-initdb.html), it said:

generating the shared catalog tables (tables that belong to 
the whole cluster rather than to any particular database), 
and creating the template1 and postgres databases

It was wired that there was no postgres and template1 database by default.

I tried to login using psql and it displayed role "username" does not exist.

I also tried createuser -U postgres -s $USER and it showed the error

(base) > $ createuser -U postgres -s $USER                          
createuser: error: could not connect to database template1: FATAL:  Peer authentication failed for user "postgres"

I was very confused, and how can I got to solved the question or should I switch to homebrew version?

0

There are 0 best solutions below