Linux
initdb:不能以 root 身份執行
我想在 CentOS 上的 PostgSQL 中創建一個數據庫集群。
當我鍵入命令“initdb”時,結果如下所示:
[root@cll agensgraph]# initdb initdb: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.
[root@cll ~]# sudo chown jessica:jessica /usr/local/agdata/ [root@cll ~]# cd /usr/local/ [root@cll local]# ll total 8 drwxr-xr-x. 2 jessica jessica 6 Feb 26 18:06 agdata drwxr-xr-x. 6 root root 56 Feb 26 03:31 agensgraph drwxr-xr-x. 2 root root 4096 Feb 24 21:01 bin drwxr-xr-x. 2 root root 6 Nov 5 2016 etc drwxr-xr-x. 2 root root 6 Nov 5 2016 games drwxr-xr-x. 4 root root 160 Feb 24 21:01 include drwxr-xr-x. 6 root root 4096 Feb 24 21:01 lib drwxr-xr-x. 2 root root 6 Nov 5 2016 lib64 drwxr-xr-x. 2 root root 6 Nov 5 2016 libexec drwxr-xr-x. 2 root root 6 Nov 5 2016 sbin drwxr-xr-x. 13 root root 169 Feb 24 21:01 share drwxr-xr-x. 2 root root 6 Nov 5 2016 src [root@cll local]# cd agdata/ [root@cll agdata]# initdb initdb: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process. [root@cll agdata]# su -l jessica Last login: Mon Feb 26 23:31:29 CST 2018 from 192.168.109.1 on pts/2 [jessica@cll ~]$ cd /usr/local/agensgraph/ [jessica@cll agensgraph]$ initdb The files belonging to this database system will be owned by user "jessica". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /usr/local/agdata ... 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: ag_ctl -D /usr/local/agdata -l logfile start [jessica@cll agensgraph]$
解釋
PostgreSQL 數據庫要求以實際執行數據庫程序的使用者身份進行初始化。該使用者不是您
postgres
,而是類似或類似的系統使用者帳戶postgresql
。在 CentOS 上,按照PostgreSQL Wiki 中的說明,您可以以 root 身份執行以下任一操作
service postgresql-9.6 initdb
或者
/usr/pgsql-9.6/bin/postgresql96-setup initdb
(假設您正在設置的是 PostgreSQL 9.6)。
sudo postgresql-setup initdb
如果您機器上的 PostgreSQL 軟體包附帶文件(它一定會這樣做),那麼該文件將準確解釋應該如何初始化數據庫的版本。