I'd like to create a PostgreSQL database and be able to connect as a user which is specified at creation. Therefore I'm using initdb and createdb. However the initdb --user/-U option seems to be ignored:
> cd `mktemp -d`
> /usr/lib/postgresql/9.6/bin/initdb --user=user1 test1
The files belonging to this database system will be owned by user "richter".
This user must also own the server process.
The database cluster will be initialized with locale "de_DE.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "german".
Data page checksums are disabled.
creating directory test1 ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
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:
/usr/lib/postgresql/9.6/bin/pg_ctl -D test1 -l logfile start
The connection with createdb after starting the server with the postgres command fails because user1 isn't available. richter is the user executing the command.
I'm using PostgreSQL 9.6 on Ubuntu 17.04.