私はPostgreSQLデータベースを作成し、作成時に指定されたユーザーとして接続できるようにしたいと考えています。したがって、私はinitdb
とcreatedb
を使用しています。しかしinitdb --user
/-U
オプションは無視しているようだ:user1
が利用できないため、PostgreSQLデータベースのスーパーユーザを指定するには?
> 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
postgres
コマンドを使用してサーバを起動した後createdb
との接続は失敗します。 richter
は、コマンドを実行しているユーザーです。
私はUbuntuの17.04でPostgreSQL 9.6を使用しています。
ありがとうございます。私は、長いオプションの中でエスケープするユーザ名は難しいと思っていました - 私はシステム化されていない、一重引用符と二重引用符のすべての組み合わせを調査しませんでしたが、引用符なしで '-U'を使うとうまくいきました。 –
ここには1つのアドバイスがあります。データベースオブジェクト名(ユーザーを含む)には常に小文字のASCII文字、数字、アンダースコアのみを使用してください。あなたは多くのトラブルを救ってくれるでしょうし、何かを引用したりエスケープする必要はありません。 –