gpt4 book ai didi

postgresql - 无法授予用户对Postgresql数据库的特权(用于Rails应用)

转载 作者:行者123 更新时间:2023-11-29 11:09:48 25 4
gpt4 key购买 nike

我通过:http://www.postgresql.org/docs/current/interactive/app-psql.html#APP-PSQL-META-COMMANDSfhttps://www.digitalocean.com/community/articles/how-to-use-roles-and-manage-grant-permissions-in-postgresql-on-a-vps--2进行了梳理,但是仍然无法正常工作。

我这样做是为了使postgres在本地工作:https://askubuntu.com/questions/42013/problem-installing-and-configuring-postgresql

pavan@myUbuntuLaptop% which psql
/usr/bin/psql

这让我进入:
pavan@myUbuntuLaptop% sudo su - postgres
[sudo] password for pavan:
postgres@myUbuntuLaptop%

所以...
postgres@myUbuntuLaptop% createuser pavankat
Shall the new role be a superuser? (y/n) y
postgres@myUbuntuLaptop%

这得到了所有的角色
\du

显示了pavankat,因此该角色

这有效:
postgres=# CREATE database lateraldev;
CREATE DATABASE
postgres=# \l

现在,我尝试向用户pavankat授予对lateraldev的特权:

这不起作用:
GRANT RULE ON lateraldev to pavankat

不起作用:
GRANT ALL ON lateraldev TO pavankat;

不起作用:
postgres=# GRANT ALL ON lateraldev TO pavankat;
ERROR: relation "lateraldev" does not exist

看起来好像可行,但是\ du没有显示任何内容:
postgres=# GRANT ALL ON DATABASE lateraldev TO pavankat;
GRANT

与此相同,不这样做:
postgres=# GRANT ALL ON ALL TABLES IN SCHEMA public TO pavankat;
GRANT
postgres=# GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO pavankat;
GRANT
postgres=# GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO pavankat;
GRANT
postgres=# \du

我使用了这篇文章: http://imaginaryrobots.wordpress.com/2010/03/10/grant-all-in-postgres/并将shell脚本复制到了rails应用程序中。

然后运行(使文件可执行):
pavan@myUbuntuLaptop% chmod 755 give_permissions_script.sh

它不起作用:
postgres@myUbuntuLaptop$ ./give_permissions_script.sh
GRANT ALL ON DATABASE lateraldev TO pavankat;
could not change directory to "/home/pavan/Dropbox/venturelateral"
could not change directory to "/home/pavan/Dropbox/venturelateral"

尝试了这个: http://smokeandumami.com/2009/11/11/grant-permissions-on-all-tables-and-sequences-in-postgresql/
它似乎已经做了一些事情,但是没有用:
pavan@myUbuntuLaptop% chmod 755 give_permissions_script2.sh
pavan@myUbuntuLaptop% ./give_permissions_script2.sh
GRANT SELECT,UPDATE,DELETE,INSERT ON TABLE public.relname to pavankat;

看到:
postgres=# grant all privileges on database lateraldev to pavan;
GRANT
postgres=# \du

这也不起作用:
首先连接数据库:
postgres=# psql lateraldev

lateraldev=# GRANT ALL ON DATABASE lateraldev TO pavankat;
GRANT
lateraldev=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
pavan | Superuser, Create role, Create DB, Replication | {}
pavankat | Superuser, Create role, Create DB, Replication | {}
postgres | Superuser, Create role, Create DB, Replication | {}

我没主意了。请帮帮我?

圣诞快乐,节日快乐!

最佳答案

你有没有尝试过:

--Change the database ownership
alter database lateraldev owner to pavan;

--and do the same for all tables
psql -tc "select 'alter table ' || tablename || ' owner to pavan;' from pg_tables where schemaname not in ('pg_catalog', 'information_schema');" lateraldev | psql -a lateraldev

关于postgresql - 无法授予用户对Postgresql数据库的特权(用于Rails应用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20775462/

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