微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql – 授予postgres超级用户到linux帐户

在我的开发(Ubuntu linux)笔记本电脑上,我有一个postgres操作系统帐户,它拥有Postgres安装.

当我想执行任何postgres活动,创建/删除数据库等时,我必须首先su到postgres帐户.

$sudo su postgres

如何更改自己的操作系统帐户以获得操作系统级别的postgres特权,所以我不需要su?

解决方法:

在OS上创建用户

# Identify yourself as root
su - 

# Create the user who will have access to a postgres database
useradd mypostgresuser

# Add a password
passwd mypostgresuser

授予本地用户访问postgres的权限

您需要找到postgresql安装的数据目录,即您已创建数据库文件的位置.它们通常位于/ var / lib / pgsql / data中
安装的值可能在环境变量$PGDATA中可用

# Make sure that local users can access postgres
cat /${PGDATA}/pg_hba.conf

# this was the default setting on my 8.4 install
# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all

如果你做了任何改变,重新加载postgres将是必要的

/etc/init.d/postgresql reload

或者作为postgres

pg_ctl reload -D ${PGDATA}

现在连接到psql作为postgres

# Create the user in postgres
postgres=# create user mypostgresuser;
CREATE ROLE

# Give that user access to a database
postgres=# grant all privileges on database mytestdb to mypostgresuser;
GRANT

测试连接

# Identify yourself as mypostgresuser
su - mypostgresuser

# Connect to the database
psql -d mytestdb 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐