gpt4 book ai didi

postgresql - 我怎样才能创建一个具有有限访问权限、没有插入更新但可以执行重建索引和备份等维护任务的 postgres 角色?

转载 作者:行者123 更新时间:2023-11-29 12:04:51 28 4
gpt4 key购买 nike

我的 postgres 9.3 与我的 Windows 桌面应用程序一起安装在各处的计算机上。我不希望 Joe Script-kiddy 查看 pgpass.conf,让 postgres 密码在我的数据库中乱七八糟地运行。

我能够使用 this article 做一个备份角色但是我没有使用 reindexdb 和 Vacuum Analyze。

到目前为止,我的解决方案是编写一个应用程序,它将采用加密的 vbscript 文件并使用 ado 连接和运行。

我已经阅读了关于 grant 和 role 的 PG 帮助,但我不知道该怎么做。如果有任何想法,我将不胜感激。

Neil McGuigan 的建议适用于重新索引和分析。不过,我需要在循环中重新索引每个表。如果我尝试重新索引数据库 myDb,我会得到 EINDEX DATABASE cannot be executed from a function or multi-command string。我在使用 vacuum [table] 时遇到了同样的错误

我还在研究 dblink作为可能的解决方案。.. 我不能使用 dblink,因为它需要密码,所以我必须将密码编码到函数中,因为我的备份角色已选择它可以查看函数的内容。

所以我有一个低特权角色,backup,它可以备份、分析和重建索引,但不能 vacuum。我觉得很奇怪。

最佳答案

您始终可以将命令包装在一个函数中。以其定义者 的权限运行该函数。将执行权限授予其他人。示例:

set role roleThatOwnsTable1;

/*
SECURITY DEFINER tells Postgres to run the function with the privileges of the role that
defined the function, as opposed to the privileges of the role that invoked the function.
*/
create or replace function reindexTable1() returns void SECURITY DEFINER language plpgsql as $$
begin
reindex table table1;
end $$;

grant execute on function reindexTable1() to someGuy;

set role someGuy;

select reindexTable1();

当然,这确实会向通常不应该拥有它的人开放该功能,所以要小心。

关于postgresql - 我怎样才能创建一个具有有限访问权限、没有插入更新但可以执行重建索引和备份等维护任务的 postgres 角色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30676420/

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