initdb:无法以 root 身份运行

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.

答案1

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 包附带了文档(它肯定已经完成了),那么这个文档将准确解释应该如何初始化数据库的版本。

答案2

[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]$ 

解释

在此输入链接描述

相关内容