gpt4 book ai didi

linux - 在引导期间创建 postgres 用户

转载 作者:太空宇宙 更新时间:2023-11-04 10:23:02 24 4
gpt4 key购买 nike

我在启动期间从 monit 运行一个 bash 文件,该 bash 文件启动我的 postgres 服务器。

如果我的数据库目录不存在,我会:

1- initdb (postgresql/data/) su - edge -c '/usr/bin/initdb -D ${DBDIR}'

2- 将修改后的 pg_hba.conf 和 postgresql.conf 文件复制到 (postgresql/data/)

3- 启动我的服务器 su - edge -c "/usr/bin/pg_ctl -w -D ${DBDIR} -l 日志文件开始"

4-postgres createuser - su - $User -c '${DBDIR} -e -s postgres'

bash文件执行后postgresql/data/已创建文件被复制服务器启动,但是没有创建用户所以我不能访问我的数据库

错误:/usr/bin/psql -U postgres psql: FATAL: 角色“postgres”不存在

最佳答案

我无法破译你的第 4 步,但是 postgres 角色不存在的原因是因为第 1 步是由用户 edge < strong>并且它不要求通过-U创建一个postgres角色,所以它创建了一个egde角色作为 super 用户。

根据 initdb 文档:

-U username
--username=username

Selects the user name of the database superuser. This defaults to the name of the effective user running initdb. It is really not important what the superuser's name is, but one might choose to keep the customary name postgres, even if the operating system user's name is different.

要么执行 initdb -U postgres,或者如果您更喜欢名为 edge 的 super 用户,请保持这样,但使用 启动 psql >psql -U edge,或将 PGUSER 环境变量设置为 edge 以避免每次都输入该内容。

关于linux - 在引导期间创建 postgres 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43053840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com