Postgresql

錯誤:行太大:大小 XXX,最大大小 8160 - 與 pg_policies 表相關

  • March 15, 2022

嘗試時CREATE POLICY出現以下錯誤:

ERROR: row is too big: size XXX, maximum size 8160

pg_policies表有大小限制嗎?

可以擴大,還是用連接寫這麼多條件是不好的做法?

現在,我通過將查詢更改為更少的字元來解決它,但是如何避免呢?

幾乎太長的政策範例。

       CREATE POLICY check_out_insert ON check_out FOR INSERT
           WITH CHECK ( 
               (user_id = current_setting('app.current_user_id')::bigint AND
               file_version_id = ANY(ARRAY(
                   SELECT file_version.id fv_id FROM file_version 
                       INNER JOIN "file" ON (file_version.file_id = "file".id)
                       INNER JOIN "file_user" ON ("file".id = "file_user".file_id AND file_user.deleted_at IS NULL)
                       WHERE file_user.user_id = current_setting('app.current_user_id')::bigint)
               )
               OR
               true = ANY(
                   ARRAY(SELECT is_owner 
                   FROM "group"
                   WHERE id = current_setting('app.current_user_group_id')::bigint
                   LIMIT 1
                   )
               )
               OR
               file_version_id = ANY( 
                   ARRAY(SELECT DISTINCT file_version.id fv_id FROM file_version 
                       INNER JOIN "file" ON (file_version.file_id = "file".id)
                       INNER JOIN "sub_folder" ON (file.sub_folder_id = "sub_folder".id)
                       INNER JOIN "folder" ON (sub_folder.folder_id = "folder".id)
                       INNER JOIN "folder_group" ON (folder_group.folder_id = "folder".id AND folder_group.group_id = current_setting('app.current_user_group_id')::bigint)
                       INNER JOIN "project_user" ON (folder.project_id = "project_user".project_id AND "project_user".user_id = current_setting('app.current_user_id')::bigint)
                       WHERE folder.type = 'nda'
                   )
               )
           )
       );`);

您可能正在執行早於 v12 的 PostgreSQL 版本,因為pg_policy自 v12 以來就有一個 TOAST 表,因此可以將超大的屬性儲存在行外。

在此之前,您僅限於pg_policy行適合單個表塊的策略。您的策略文本小於該值,但 PostgreSQL 儲存了解析的查詢樹,它可能大於文本。

升級到更高版本的 PostgreSQL 或使用多個PERMISSIVE策略,這些策略將與OR.

引用自:https://dba.stackexchange.com/questions/280746