小编psz*_*fer的帖子

如何优化 Postgresql 中的行级安全性

我有基于 postgres (13.2) 的 API,启用了 RLS(我使用 postgraphile),而且速度非常慢。用户从 Google OAuth 发送 JWT。对表的访问基于角色(有 2 个:人员、管理员)+ RLS。我有 2 个用户身份验证表:person、person_groups

CREATE TABLE IF NOT EXISTS myschema.person_groups (
    id serial PRIMARY KEY,
    person_id citext NOT NULL REFERENCES myschema.person (id),
    google_id text NOT NULL REFERENCES myschema_private.person_account (google_id),
    group_id serial NOT NULL REFERENCES myschema.groups (id),
    updated_at timestamp DEFAULT now(),
    CONSTRAINT unq_person_id_group_id UNIQUE (person_id, group_id)
);

CREATE INDEX persongroups_google_group_idx ON myschema.person_groups (google_id, group_id);
Run Code Online (Sandbox Code Playgroud)

为了进行 RLS 检查,我将函数指定为:

CREATE OR REPLACE FUNCTION myschema.is_in_group (group_id int[])
  RETURNS boolean
  AS $$
  SELECT …
Run Code Online (Sandbox Code Playgroud)

postgresql row-level-security

8
推荐指数
1
解决办法
2241
查看次数

标签 统计

postgresql ×1

row-level-security ×1