我梳理过:http://www.postgresql.org/docs/current/interactive/app-psql.html#APP-PSQL-META-COMMANDSf和https://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
现在我尝试向用户授予lateraldev权限,pavankat:
这不起作用:
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 app。
然后运行(使文件可执行):
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 | {}
我没有想法。请帮帮我?
圣诞快乐,节日快乐!
答案 0 :(得分:21)
你试过了吗?
--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
答案 1 :(得分:11)
GRANT ALL PRIVILEGES ON DATABASE my_newly_created_db_name TO my_user_name;
http://www.postgresql.org/message-id/4BDE2E41.5090505@agliodbs.com
答案 2 :(得分:10)
尝试以CREATEDB
权限授予用户权限,然后您可以使用该用户创建数据库。从那时起,用户将拥有该数据库的权限。
CREATE USER myuser CREATEDB;
我知道这不是一个完美的解决方案,但我希望这对你有用
-Brian
答案 3 :(得分:0)
尝试改为以psql命令发送。
psql -c "GRANT ALL ON lateraldev TO pavankat";