{"id":332251,"date":"2022-04-21T15:01:16","date_gmt":"2022-04-21T15:01:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=332251"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=332251","title":{"rendered":"<span>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 PostgreSQL. \u0427\u0430\u0441\u0442\u044c 2. \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/post_images\/b82\/952\/2e3\/b829522e3670be1621275bd44422467e.jpg\" alt=\"image\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b82\/952\/2e3\/b829522e3670be1621275bd44422467e.jpg\" data-blurred=\"true\"\/><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432\u0430\u0441 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u043c \u0440\u0430\u0437\u0431\u043e\u0440\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 PostgreSQL. \u0412 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438, \u0447\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 PostgreSQL. \u0412\u043e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432:<\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/timeweb\/blog\/661771\/\">\u0420\u043e\u043b\u0438 \u0438 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438<\/a>;<\/li>\n<li>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a (\u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0437\u0434\u0435\u0441\u044c);<\/li>\n<li>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a (coming soon!);<\/li>\n<\/ul>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/ru\/company\/timeweb\/blog\/661771\/\">\u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0440\u043e\u043b\u0438 \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u0437\u0430\u043f\u0440\u043e\u0441\u044b SELECT, INSERT, UPDATE \u0438 DELETE) \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0411\u0414 (\u0442\u0430\u0431\u043b\u0438\u0446, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439). \u0422\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9A%D0%BB%D0%B8%D1%84%D1%84%D1%85%D1%8D%D0%BD%D0%B3%D0%B5%D1%80\">\u043a\u043b\u0438\u0444\u0444\u0445\u044d\u043d\u0433\u0435\u0440\u043e\u043c<\/a>: \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u0442\u0435 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u043e\u043b\u0438 \u0438 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u043e \u0432\u0430\u0448\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u043c\u043e\u0433\u0443\u0442 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <a href=\"https:\/\/www.postgresql.org\/docs\/current\/ddl-rowsecurity.html\">\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a<\/a> (RLS).<a name=\"habracut\"><\/a><\/p>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h2>\n<p>  \u041b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043d\u044f\u0442\u044c RLS \u2014 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e. \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0440\u043e\u043b\u0438 \u0438 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 (\u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u00absongs\u00bb) \u2014 \u043c\u044b \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u0445\u043e\u0436\u0435\u0433\u043e \u043d\u0430 <a href=\"https:\/\/bandcamp.com\/\">Bandcamp<\/a>, \u0433\u0434\u0435 \u043c\u0443\u0437\u044b\u043a\u0430\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u044c\u0431\u043e\u043c\u044b \u0438 \u043f\u0435\u0441\u043d\u0438, \u0430 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0435\u0439 \u0438 \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u043d\u0438\u043c\u0438.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/b15\/786\/493\/b1578649331bfc04b8461cfcd23ae14c.png\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b15\/786\/493\/b1578649331bfc04b8461cfcd23ae14c.png\"\/><\/div>\n<p>  <i>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0445\u0435\u043c\u044b \u043d\u0430\u0448\u0435\u0439 \u0411\u0414. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0445\u0435\u043c\u0443 \u043f\u043e \u044d\u0442\u043e\u0439 <\/i><a href=\"https:\/\/gitlab.com\/tangram-vision\/oss\/tangram-visions-blog\/-\/tree\/main\/2022.03.16_PostgreSQLAuthorizationRowLevelSecurity\"><i>\u0441\u0441\u044b\u043b\u043a\u0435<\/i><\/a><i> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0451 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Docker.<\/i><\/p>\n<p>  \u0412 Docker \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e<a href=\"https:\/\/hub.docker.com\/_\/postgres\">\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0437 Postgres Docker<\/a> \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL. \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0442\u043e\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u0444\u0430\u0439\u043b <code>schema.sql<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 \u0441\u0445\u0435\u043c\u0435 \u0432\u044b\u0448\u0435.<\/p>\n<pre><code class=\"plaintext\">docker run --name=postgres \\     --rm \\     --volume=$(pwd)\/schema.sql:\/docker-entrypoint-initdb.d\/schema.sql \\     --volume=$(pwd):\/repo \\     --env=PSQLRC=\/repo\/.psqlrc \\     --env=POSTGRES_PASSWORD=foo \\     postgres:latest -c log_statement=all <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043a\u043e\u043d\u0441\u043e\u043b\u044c <code>psql<\/code>, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u044d\u0442\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"plaintext\">docker exec --interactive --tty postgres \\     psql --username=postgres <\/code><\/pre>\n<p>  <\/p>\n<h2>RLS<\/h2>\n<p>  \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/ddl-rowsecurity.html\">\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a<\/a>? \u042d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0438\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u0442\u0440\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041e\u0431\u044b\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 <code>SELECT * FROM mytable<\/code>, \u0442\u043e PostgreSQL \u0432\u0435\u0440\u043d\u0435\u0442 \u0432\u0441\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 RLS, \u0442\u043e PostgreSQL \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u0442\u0440\u043e\u043a (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u043d\u0435 \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u043b\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u0435\u043b\u0435\u043c <a href=\"https:\/\/www.postgresql.org\/docs\/current\/sql-createrole.html\">\u043e\u043f\u0446\u0438\u0438 BYPASSRLS<\/a>).<\/p>\n<h3>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 RLS<\/h3>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 RLS, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e <a href=\"https:\/\/www.postgresql.org\/docs\/current\/sql-createpolicy.html\">\u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443<\/a> \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u0412 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 SQL (\u0441 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u041f\u043e \u043d\u0435\u043c\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f, \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432\u0448\u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441. \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0440\u043e\u043b\u044f\u043c, \u0442\u0430\u043a \u0438 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c (\u043a\u0430\u043a SELECT \u0438\u043b\u0438 INSERT, \u2026).<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043d\u0430\u0448\u0443 \u0411\u0414 \u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u043c RLS \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435: <\/p>\n<pre><code class=\"plaintext\">-- Add 3 musical artists =# INSERT INTO artists (name)      VALUES ('Tupper Ware Remix Party'), ('Steely Dan'), ('Missy Elliott');  -- Switch to the artist role (so we're not querying from a superuser role, which -- bypasses RLS) =# SET ROLE artist;  => SELECT * FROM artists; --  artist_id |     name       -- -----------+--------------- --          1 | Tupper Ware Remix Party --          2 | Steely Dan --          3 | Missy Elliott -- (3 rows)  -- Switch to the postgres superuser to enable RLS on the artists table => RESET ROLE; =# ALTER TABLE artists ENABLE ROW LEVEL SECURITY;  -- Now we don't see any rows! RLS hides all rows if no policies are declared on -- the table. =# SET ROLE artist; => SELECT * FROM artists; --  artist_id | name  -- -----------+------ -- (0 rows) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u0440\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u043e\u043b\u0438\u0442\u0438\u043a RLS:<\/p>\n<pre><code class=\"plaintext\">-- Let's create a simple RLS policy that applies to all roles and commands and -- allows access to all rows. => RESET ROLE; =# CREATE POLICY testing ON artists     USING (true);  -- The expression \"true\" is true for all rows, so all rows are visible. =# SET ROLE artist; => SELECT * FROM artists; --  artist_id |          name -- -----------+------------------------- --          1 | Tupper Ware Remix Party --          2 | Steely Dan --          3 | Missy Elliott -- (3 rows)  -- Let's change the policy to use an expression that depends on a value in the -- row. => RESET ROLE; =# ALTER POLICY testing ON artists     USING (name = 'Steely Dan');  -- Now, we see that only 1 row passes the policy's test. =# SET ROLE artist; => SELECT * FROM artists; --  artist_id |    name -- -----------+------------ --          2 | Steely Dan -- (1 row) <\/code><\/pre>\n<p>  <\/p>\n<h3>\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0438, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435<\/h3>\n<p>  \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e: \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0432\u043e\u0438 \u0438\u043c\u0435\u043d\u0430, \u043d\u043e \u043d\u0435 \u043c\u043e\u0433\u043b\u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0447\u0443\u0436\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u2014 \u0432\u044b\u0434\u0430\u0447\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043e\u0431\u0449\u0435\u0439 \u0440\u043e\u043b\u0438 \u00abartist\u00bb (\u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0432\u044b\u0448\u0435) \u043d\u0435 \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043b\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u0432 \u0440\u043e\u043b\u0438\/\u0433\u0440\u0443\u043f\u043f\u0435 \u00abartist\u00bb \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0440\u043e\u043b\u044c \u0411\u0414 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0451 \u0447\u043b\u0435\u043d\u043e\u043c \u0440\u043e\u043b\u0438 \u00abartist\u00bb:<\/p>\n<pre><code class=\"plaintext\">=> RESET ROLE; -- Create a login\/role for a specific artist. We'll design the role name to be -- \"artist:N\" where N is the artist_id. So, \"artist:1\" will be the account for -- Tupper Ware Remix Party. -- NOTE: We have to quote the role name because it contains a colon. =# CREATE ROLE \"artist:1\" LOGIN; =# GRANT artist TO \"artist:1\"; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u043e\u0439\u0434\u0435\u0442\u0435 \u0432 \u0411\u0414 \u043a\u0430\u043a \u00abartist:1\u00bb \u0442\u043e \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u0442\u0435 \u0436\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438, \u0447\u0442\u043e \u0438 \u0443 \u0440\u043e\u043b\u0438 \u00abartist\u00bb. \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 single-user \u043b\u043e\u0433\u0438\u043d\u044b (\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c \u0438\u043c\u0435\u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439), \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0411\u0414 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u0435\u043c\u0443.<\/p>\n<pre><code class=\"plaintext\">-- Let's make all artists visible to all users again =# DROP POLICY testing; =# CREATE POLICY viewable_by_all ON artists     FOR SELECT     USING (true);  -- We create an RLS policy specific to the \"artist\" role\/group and the UPDATE -- command. The policy makes rows from the \"artists\" table available if the -- row's artist_id matches the number in the current user's name (i.e. -- a db role name of \"artist:1\" makes the row with artist_id=1 available). =# CREATE POLICY update_self ON artists     FOR UPDATE     TO artist     USING (artist_id = substr(current_user, 8)::int);  =# SET ROLE \"artist:1\"; -- Even though we try to update the name for all artists in the table, the RLS -- policy limits our update to only the row we \"own\" (i.e. that has an artist_id -- matching our db role name). => UPDATE artists SET name = 'TWRP'; -- UPDATE 1 => SELECT * FROM artists; --  artist_id |     name -- -----------+--------------- --          2 | Steely Dan --          3 | Missy Elliott --          1 | TWRP -- (3 rows)  -- Trying to update a row that no policy gives us access to simply results in no -- rows updating. => UPDATE artists SET name = 'Ella Fitzgerald' WHERE name = 'Steely Dan'; -- UPDATE 0 <\/code><\/pre>\n<p>  \u041c\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0451 \u0438\u043c\u044f. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c:<\/p>\n<ul>\n<li>\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, SELECT, UPDATE);<\/li>\n<li>\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0440\u043e\u043b\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, artist);<\/li>\n<\/ul>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a\u043e \u0432\u0441\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c \u0438 \u0440\u043e\u043b\u044f\u043c. \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435\u0442 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u0438 \u0440\u043e\u043b\u044c\u044e, \u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 RLS \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0438\u0434\u043d\u044b \u0438 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.<\/p>\n<p>  <i>? \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>artist_id = substr(current_user, 8)::int <\/code>\u0438 \u043d\u0430\u0445\u043c\u0443\u0440\u0438\u043b\u0438\u0441\u044c, \u0442\u043e \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e! \u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u043e\u0434\u043d\u0430\u043a\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u0430\u043c \u0432\u0440\u044f\u0434 \u043b\u0438 \u0431\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0440\u043e\u043b\u0438\/\u0433\u0440\u0443\u043f\u043f\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c. \u0418\u0437-\u0437\u0430 \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0438\u0445 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f! \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u043c\u0435\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0411\u0414 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0438\u0445 \u043a \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430\u043c RLS, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445.<\/i><\/p>\n<h3>\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\/\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\/\u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0438 \u0430\u043b\u044c\u0431\u043e\u043c\u044b \u0438 \u043f\u0435\u0441\u043d\u0438 \u0432 \u044d\u0442\u0438\u0445 \u0430\u043b\u044c\u0431\u043e\u043c\u0430\u0445. \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 USING \u0432 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430\u0445 RLS \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 SQL, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f foreign-key \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<pre><code class=\"plaintext\">=> RESET ROLE; -- Enable RLS on albums and songs, and make them viewable by everyone. =# ALTER TABLE albums ENABLE ROW LEVEL SECURITY; =# ALTER TABLE songs ENABLE ROW LEVEL SECURITY; =# CREATE POLICY viewable_by_all ON albums     FOR SELECT     USING (true); =# CREATE POLICY viewable_by_all ON songs     FOR SELECT     USING (true);  -- Limit create\/edit\/delete of albums to the \"owning\" artist. =# CREATE POLICY affect_own_albums ON albums     FOR ALL     TO artist     USING (artist_id = substr(current_user, 8)::int); -- Limit create\/edit\/delete of songs to the \"owning\" artist of the album. =# CREATE POLICY affect_own_songs ON songs     FOR ALL     TO artist     USING (                 EXISTS (             SELECT 1 FROM albums             WHERE albums.album_id = songs.album_id         )         );  -- Add a Missy Elliott (artist_id=3) album (album_id=1) for testing below =# INSERT INTO albums (artist_id, title, released)     VALUES (3, 'Under Construction', '2002-11-12');  -- Change to the user account corresponding to the artist TWRP (artist_id=1) =# SET ROLE \"artist:1\"; -- Add an album and a song to that album => INSERT INTO albums (artist_id, title, released)     VALUES (1, 'Return to Wherever', '2019-07-11'); => INSERT INTO songs (album_id, title)     VALUES (2, 'Hidden Potential');  -- Trying to add an album to another artist fails the RLS policy => INSERT INTO albums (artist_id, title, released)     VALUES (2, 'Pretzel Logic', '1974-02-20'); -- ERROR:  42501: new row violates row-level security policy for table \"albums\" -- LOCATION:  ExecWithCheckOptions, execMain.c:2058  -- Trying to add a song to Missy Elliott's album fails the RLS policy => INSERT INTO songs (album_id, title)     VALUES (1, 'Work It'); -- ERROR:  42501: new row violates row-level security policy for table \"songs\" -- LOCATION:  ExecWithCheckOptions, execMain.c:2058 <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 RLS \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u00absongs\u00bb. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 INSERT, UPDATE \u0438\u043b\u0438 DELETE \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 RLS \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c, \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043f\u0435\u0441\u043d\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0430\u043b\u044c\u0431\u043e\u043c\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0432\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<p>  \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 EXISTS \u0434\u043b\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f USING \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u00absongs\u00bb, \u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041a\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d? \u0421 \u044d\u0442\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u00ab\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c RLS\u00bb.<\/p>\n<h3>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043b\u0438\u0442\u0438\u043a<\/h3>\n<p>  \u041c\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f:<\/p>\n<ul>\n<li>\u043a\u043e \u0432\u0441\u0435\u043c \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c;<\/li>\n<li>\u043a\u043e \u0432\u0441\u0435\u043c \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c;<\/li>\n<\/ul>\n<p>  \u041d\u043e \u0432\u0430\u0436\u043d\u044b\u043c \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u043b\u0438\u0442\u0438\u043a RLS \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0443\u043c\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0438\u0442\u0438\u043a;<\/li>\n<li>\u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439:<\/li>\n<\/ul>\n<p>  <strong>\u0422\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430\u043c\u0438<\/strong><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0438\u0442\u0438\u043a, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b \u043b\u0438 \u044d\u0442\u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043a\u0430\u043a PERMISSIVE (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e) \u0438\u043b\u0438 RESTRICTIVE. \u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043b\u044e\u0431\u044b\u043c \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c PERMISSIVE \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430. \u0415\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e PERMISSIVE \u043f\u043e\u043b\u0438\u0442\u0438\u043a, \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430, \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e PERMISSIVE \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 true. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0432\u0441\u0435 RESTRICTIVE \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 true, \u0447\u0442\u043e\u0431\u044b \u0441\u0442\u0440\u043e\u043a\u0430 \u0431\u044b\u043b\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430. \u0418\u0437\u0443\u0447\u0438\u043c \u044d\u0442\u043e, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043d\u043e\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0430\u043b\u044c\u0431\u043e\u043c\u044b \u0441 \u0434\u0430\u0442\u043e\u0439 \u0432\u044b\u043f\u0443\u0441\u043a\u0430 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0438\u0434\u0435\u0442\u044c \u0441\u0432\u043e\u0438 \u0435\u0449\u0435 \u043d\u0435 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0430\u043b\u044c\u0431\u043e\u043c\u044b.<\/p>\n<pre><code class=\"plaintext\">=> RESET ROLE; -- Reminder: We previously created a viewable_by_all policy on albums that shows -- all rows to SELECT queries issued by all roles. We re-create that policy here -- for reference: =# DROP POLICY viewable_by_all ON albums; =# CREATE POLICY viewable_by_all ON albums     FOR SELECT     USING (true);  -- For fans: restrict visibility to albums with a release date in the past. =# CREATE POLICY hide_unreleased_from_fans ON albums     AS RESTRICTIVE     FOR SELECT     TO fan     USING (released &lt;= now());  -- For artists: restrict visibility to albums with a release date in the past, -- unless the role issuing the query is the owning artist. =# CREATE POLICY hide_unreleased_from_other_artists ON albums     AS RESTRICTIVE     FOR SELECT     TO artist     USING (released &lt;= now() or (artist_id = substr(current_user, 8)::int); <\/code><\/pre>\n<p>  \u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u044f PERMISSIVE \u0438 RESTRICTIVE \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438, \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u043e\u043b\u0438 (fans \u0438 artists), \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0430\u043b\u044c\u0431\u043e\u043c\u044b \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0440\u0435\u043b\u0438\u0437\u043e\u0432 \u0432\u0438\u0434\u0438\u043c\u044b\u043c\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043b\u043e\u0433\u0438\u043a\u0443 \u2014 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e PERMISSIVE \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"plaintext\">-- Alternate implementation using only PERMISSIVE (rather than RESTRICTIVE) -- policies. =# DROP POLICY viewable_by_all ON albums; =# DROP POLICY hide_unreleased_from_fans ON albums; =# DROP POLICY hide_unreleased_from_other_artists ON albums; =# CREATE POLICY viewable_by_all ON albums     FOR SELECT     USING (released &lt;= now());  -- Reminder: We previously created an affect_own_albums policy on albums that -- already allows the artist to see their own albums. We re-create that policy -- here for reference: =# DROP POLICY affect_own_albums ON albums; =# CREATE POLICY affect_own_albums ON albums     -- FOR ALL     TO artist     USING (artist_id = substr(current_user, 8)::int); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 <code>viewable_by_all<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0432\u0438\u0434\u0435\u0442\u044c \u0443\u0436\u0435 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0430\u043b\u044c\u0431\u043e\u043c\u044b, \u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 <code>affect_own_albums<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e (SELECT, INSERT \u0438 \u0442.\u0434.) \u0441 \u0430\u043b\u044c\u0431\u043e\u043c\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u043d\u0438 \u0432\u043b\u0430\u0434\u0435\u044e\u0442.<\/p>\n<p>  <strong>\u0417\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c<\/strong><\/p>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043b\u0438\u0442\u0438\u043a \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 USING \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u00abalbums\u00bb, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0434\u043e\u043b\u0436\u043d\u044b \u043b\u0438 \u043f\u0435\u0441\u043d\u0438 \u0432 \u044d\u0442\u043e\u043c \u0430\u043b\u044c\u0431\u043e\u043c\u0435 \u0431\u044b\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u044b\u043c\u0438:<\/p>\n<pre><code class=\"plaintext\">-- To control visibility of songs, we simply query for the corresponding album -- and the RLS policy on the albums table will determine if we can see the -- album. If we see the album, we'll see the songs. =# DROP POLICY viewable_by_all ON songs; =# CREATE POLICY viewable_by_all ON songs     FOR SELECT     USING (         EXISTS (             SELECT 1 FROM albums             WHERE albums.album_id = songs.album_id         )     ); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 RLS, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u0440\u043e\u043b\u0438\/\u0433\u0440\u0443\u043f\u043f\u044b \u0432\u0438\u0434\u044f\u0442 (\u0438\u043b\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u0438\u0434\u0435\u0442\u044c) \u0435\u0449\u0451 \u043d\u0435 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0430\u043b\u044c\u0431\u043e\u043c\u044b \u0438 \u0438\u0445 \u043f\u0435\u0441\u043d\u0438.<\/p>\n<pre><code class=\"plaintext\">-- Create another artist role for testing =# CREATE ROLE \"artist:2\"; =# GRANT artist TO \"artist:2\";  -- Test that the owning artist (artist:1) can see future albums and songs, but -- other artists and fans cannot see them. =# SET ROLE \"artist:1\"; => SELECT * FROM albums; --  album_id | artist_id |       title        |  released   -- ----------+-----------+--------------------+------------ --         1 |         3 | Under Construction | 2002-11-12 --         2 |         1 | Return to Wherever | 2019-07-11 --         4 |         1 | Future Album       | 2050-01-01 -- (3 rows)  => SELECT * FROM songs; --  song_id | album_id |      title        -- ---------+----------+------------------ --        1 |        2 | Hidden Potential --        3 |        4 | Future Song 1 -- (2 rows)  => SET ROLE fan; => SELECT * FROM albums; --  album_id | artist_id |       title        |  released -- ----------+-----------+--------------------+------------ --         1 |         3 | Under Construction | 2002-11-12 --         2 |         1 | Return to Wherever | 2019-07-11 -- (2 rows)  => SELECT * FROM songs; --  song_id | album_id |      title -- ---------+----------+------------------ --        1 |        2 | Hidden Potential -- (1 row)  => SET ROLE \"artist:2\"; => SELECT * FROM albums; --  album_id | artist_id |       title        |  released -- ----------+-----------+--------------------+------------ --         1 |         3 | Under Construction | 2002-11-12 --         2 |         1 | Return to Wherever | 2019-07-11 -- (2 rows)  => SELECT * FROM songs; --  song_id | album_id |      title -- ---------+----------+------------------ --        1 |        2 | Hidden Potential -- (1 row) <\/code><\/pre>\n<p>  \u0423\u0441\u043f\u0435\u0445! \u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u0435 \u043c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043c \u043e\u0431\u0437\u043e\u0440 RLS \u0432 PostgreSQL; \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c (\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e <a href=\"https:\/\/www.postgresql.org\/docs\/current\/ddl-rowsecurity.html\">\u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430\u043c RLS<\/a> \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/sql-createpolicy.html\">CREATE POLICY<\/a>), \u043d\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a \u0431\u044b\u043b\u0438 \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u044b. \u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0431\u0435\u0437 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0432\u0430\u0436\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a RLS \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 USING (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439, \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439)? \u041c\u044b \u0443\u0433\u043b\u0443\u0431\u0438\u043c\u0441\u044f \u0432 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435!<br \/>  <a href=\"http:\/\/cloud.timeweb.com\/services\/timeweb-private-vpn?utm_source=habr&amp;utm_medium=banner&amp;utm_campaign=vpn\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ky\/mc\/4w\/kymc4w0tsvxjf9ninsv-gqhcpx0.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ky\/mc\/4w\/kymc4w0tsvxjf9ninsv-gqhcpx0.png\"\/><\/a><\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/timeweb\/blog\/662209\/\"> https:\/\/habr.com\/ru\/company\/timeweb\/blog\/662209\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/post_images\/b82\/952\/2e3\/b829522e3670be1621275bd44422467e.jpg\" alt=\"image\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b82\/952\/2e3\/b829522e3670be1621275bd44422467e.jpg\" data-blurred=\"true\"\/><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432\u0430\u0441 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u043c \u0440\u0430\u0437\u0431\u043e\u0440\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 PostgreSQL. \u0412 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438, \u0447\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 PostgreSQL. \u0412\u043e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432:<\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/timeweb\/blog\/661771\/\">\u0420\u043e\u043b\u0438 \u0438 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438<\/a>;<\/li>\n<li>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a (\u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0437\u0434\u0435\u0441\u044c);<\/li>\n<li>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a (coming soon!);<\/li>\n<\/ul>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/ru\/company\/timeweb\/blog\/661771\/\">\u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0440\u043e\u043b\u0438 \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u0437\u0430\u043f\u0440\u043e\u0441\u044b SELECT, INSERT, UPDATE \u0438 DELETE) \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0411\u0414 (\u0442\u0430\u0431\u043b\u0438\u0446, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439). \u0422\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9A%D0%BB%D0%B8%D1%84%D1%84%D1%85%D1%8D%D0%BD%D0%B3%D0%B5%D1%80\">\u043a\u043b\u0438\u0444\u0444\u0445\u044d\u043d\u0433\u0435\u0440\u043e\u043c<\/a>: \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u0442\u0435 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u043e\u043b\u0438 \u0438 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u043e \u0432\u0430\u0448\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u043c\u043e\u0433\u0443\u0442 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <a href=\"https:\/\/www.postgresql.org\/docs\/current\/ddl-rowsecurity.html\">\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0442\u0440\u043e\u043a<\/a> (RLS).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-332251","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332251"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332251\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}