暂无图片
请问各位老大postgresql如何给用户授予创建schema的权限?
我来答
分享
yueli34
2024-06-11
请问各位老大postgresql如何给用户授予创建schema的权限?

请问各位老大postgresql如何给用户授予创建schema的权限?


[postgres@vm01 ~]$ psql -d postgres -h 10.10.10.2 -p 1921 -U u01
Password for user u01:
psql: error: FATAL: password authentication failed for user "u01"
[postgres@vm01 ~]$ psql -d postgres -h 10.10.10.2 -p 1921 -U erp_etl
Password for user erp_etl:
psql (12.18)
Type "help" for help.

postgres=> create schema ecuac;
ERROR: permission denied for database postgres

我来答
添加附件
收藏
分享
问题补充
2条回答
默认
最新
shunwahⓂ️

postgres=> create schema ecuac;
ERROR: permission denied for database postgres

这个错误表明你正在尝试在 postgres 数据库上创建 schema,但是你的用户 erp_etl 没有足够的权限来在 postgres 数据库上执行此操作。postgres 数据库是 PostgreSQL 的系统数据库,通常不建议在其中创建用户 schema 或其他对象,除非你确切知道你在做什么。

如果你想要在另一个数据库中创建 schema,比如叫做 mydatabase 的数据库,你需要首先确保你连接到了正确的数据库,然后再次尝试创建 schema。以下是如何做到这一点的步骤:

使用有权限的账号 psql 连接到正确的数据库:

输入密码后,你应该在 mydatabase 数据库的上下文中。现在,尝试创建 schema:

CREATE SCHEMA ecuac;

如果你收到关于权限的错误,你需要确保 erp_etl 用户有足够的权限在 mydatabase 上创建 schema。你可以通过以下 SQL 语句给 erp_etl 用户授予这些权限:

-- 作为数据库所有者(通常是 postgres 用户)登录  
GRANT USAGE, CREATE ON SCHEMA public TO erp_etl;  -- 允许在 public schema 中创建对象  
-- 如果你想允许在名为 ecuac 的 schema 中创建对象(但首先你需要创建它)  
CREATE SCHEMA ecuac;  
GRANT USAGE, CREATE ON SCHEMA ecuac TO erp_etl;

注意,USAGE 权限允许用户访问 schema 中的对象,而 CREATE 权限允许用户在该 schema 中创建新对象。如果你只想允许在 public schema 中创建对象,那么你只需要授予 public schema 的权限。

或者
使用具有足够权限的用户(如 postgres)登录到数据库。

psql -d mydatabase -h 10.10.10.2 -p 1921 -U postgres

给用户授予权限:
给用户 erp_etl 在 mydatabase 数据库中创建 schema 的权限:

GRANT CREATE ON DATABASE mydatabase TO erp_etl;

创建一个新的 schema 并给 erp_etl 权限:

CREATE SCHEMA ecuac;  
GRANT USAGE, CREATE ON SCHEMA ecuac TO erp_etl;

这里,USAGE 权限允许用户访问 schema 中的对象,而 CREATE 权限允许用户在该 schema 中创建新对象。

然后再让用户 erp_etl 登录并尝试创建 schema:

暂无图片 评论
暂无图片 有用 2
暂无图片
小鲁菜

你可以按照以下步骤操作:

给用户 `erp_etl` 授予创建 schema 的权限:
GRANT CREATE ON DATABASE your_database_name TO erp_etl;

请将 `your_database_name` 替换为实际的数据库名。这将允许 `erp_etl` 在指定的数据库上创建 schema。

eg:

postgres=# GRANT CREATE ON DATABASE postgres TO erp_etl;
GRANT
postgres=# \q
[postgres@localhost ~]$ psql -d postgres -U erp_etl
psql (14.9)
Type "help" for help.

postgres=> create schema ecuac;
CREATE SCHEMA
postgres=> 

暂无图片 评论
暂无图片 有用 1
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏