You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Developers often uses an extension called [Citus] (https://www.citusdata.com/product/community) to build a multi-tenant system based on PostgreSQL, but we do not use it in this sample. The main purpose of Citus is to improve the "scalability" of the system. Citus distributes the huge database to multiple PostgreSQL instances using the technique "sharding".
18
18
19
-
作ろうとしている Web アプリケーションの規模がシャーディングを利用するほどに巨大にならないことがわかっているならば、このサンプルのように PostgreSQL の標準機能だけを用いてマルチテナントシステムを構築できます。
19
+
There are various advantages to Citus's adoption, but application developers should understand the mechanism of "sharding" well in order not to cause unexpected errors and performance degradation.
20
20
21
-
## 動作環境
21
+
If you know that the size of the Web application you are trying to create is not huge enough to use sharding, you can build a multi-tenant system using only PostgreSQL's standard functionalities as we did in this sample.
RLS is set by defining a security policy with the `CREATE POLICY`statement. The following example allows the user `alice`to refer to a part of the `articles`table.
80
81
81
82
```
82
83
CREATE POLICY alice_policy ON articles
@@ -85,15 +86,15 @@ CREATE POLICY alice_policy ON articles
85
86
USING (user_id = (SELECT id FROM users WHERE name = 'alice'))
Conditions for which reference to rows is permitted are described in the `USING`clause. In the above example, we allow references to rows of the `articles` table whose `user_id`matches the ID of the user `alice`.
PostgreSQL allows you to set values for custom variables using the `SET`statement. In the following example, the variable `foo.bar`is set to the string `'X'`. A custom variable name must include a dot.
130
131
131
132
```
132
133
SET foo.bar = 'X'
133
134
```
134
135
135
-
カスタム変数の値は `current_setting`関数を用いて取得できます。
136
+
We can get the values of custom variables using `current_setting`function.
If you add the `WITH CHECK`clause to the` CREATE POLICY` statement, it will be checked whether the record satisfies certain conditions when inserting or updating the line. If an `INSERT`statement or `UPDATE`statement that does not satisfy the condition is issued, an error occurs.
164
165
165
-
次の例をご覧ください。
166
+
See the example below.
166
167
167
168
```
168
169
CREATE POLICY tenant_policy ON articles
@@ -178,16 +179,16 @@ CREATE POLICY tenant_policy ON articles
When the security policy is set as described above, the presence or absence of a row satisfying the following two conditions is checked in the `users` table when inserting / updating a row in the `articles` table, otherwise an error occurs.
For roles with `SUPERUSER`and`BYPASSRLS`attributes, RLS is always disabled. Also, for table owners, RLS is disabled by default, but you can enable it using the `ALTER TABLE`statement as follows.
0 commit comments