0
我想創建一個PostgreSQL數據庫,並能夠以創建時指定的用戶身份進行連接。因此我使用initdb
和createdb
。然而,initdb --user
/-U
選項似乎被忽略:如何指定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
因爲user1
是不具備的postgres
命令啓動服務器後createdb
的連接失敗。 richter
是執行該命令的用戶。
我在Ubuntu 17.04上使用PostgreSQL 9.6。
謝謝。我認爲長選項中的轉義用戶名是困難的 - 我沒有系統地調查所有不包含單引號和雙引號的組合,但是使用沒有引號的'-U'對我來說工作得很好。 –
這裏有一個忠告:對於數據庫對象名稱(包括用戶),始終只使用小寫ASCII字符,數字和下劃線。你會爲自己節省很多麻煩,而且你永遠不需要引用或逃避任何事情。 –