{"id":179873,"date":"2013-09-27T22:05:06","date_gmt":"2013-09-27T18:05:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=179873"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=179873","title":{"rendered":"<span class=\"post_title\">\u0421\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 Django \u0441 PostgreSQL<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442.<br \/>  \u042d\u0442\u043e \u0442\u043e\u043f\u0438\u043a \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (\u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435) \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e \u043c\u0435\u0441\u044f\u0446\u0430\u043c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Django+PostgreSQL. \u041c\u043d\u043e\u0433\u043e\u0435 \u0438\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u0438 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 ORM.<\/p>\n<p>  \u041e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u043d\u0443\u0436\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"http:\/\/habrahabr.ru\/post\/74984\/\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438 <a href=\"http:\/\/www.postgresql.org\/docs\/9.1\/static\/ddl-partitioning.html\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 Django \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439. \u0415\u0441\u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0430\u0441\u0442\u043e, \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u044c \u0431\u044b\u043b\u0430 \u0441\u0434\u0435\u043b\u0430\u043d\u0430, \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0441\u043a\u043e\u0440\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0425\u043e\u0440\u043e\u0448\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0441 SQL \u0447\u0435\u043b\u043e\u0432\u0435\u043a. I&#8217;ve read the docs, so you don&#8217;t have to.<a name=\"habracut\"><\/a><\/p>\n<p>  \u0421\u043f\u0435\u0440\u0432\u0430 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0438 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0430 \u043f\u043e\u0442\u043e\u043c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u0414\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u043c \u0442\u0430\u043a:  <\/p>\n<ol>\n<li>\u041b\u043e\u0432\u0438\u043c <code>syncdb<\/code>, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/li>\n<li>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c SQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0442\u0430\u0449\u0438\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u0435\u043a\u0446\u0438\u0438, \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0430 \u043d\u0438\u0445, \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u044b.<\/li>\n<li>\u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u0445.<\/li>\n<\/ol>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442 \u0438\u0437 <a href=\"https:\/\/github.com\/podshumok\/django-post-syncdb-hooks\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/a>  <\/p>\n<pre><code class=\"bash\">pip install git+https:\/\/github.com\/podshumok\/django-post-syncdb-hooks <\/code><\/pre>\n<p>   \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439:  <\/p>\n<pre><code class=\"python\">INSTALLED APPS = (     # ...     'post_syncdb_hooks',     'post_syncdb_hooks.partitioning',      'your.app',     # ... ) <\/code><\/pre>\n<p>  \u041f\u0443\u0441\u0442\u044c \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 <code>yourapp\/models.py<\/code>:  <\/p>\n<pre><code class=\"python\">from django.db import models  class MyModel(models.Model):     date_created = models.DateTimeField()     my_data = models.IntegerField(db_index=True)  <\/code><\/pre>\n<p>  \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>yourapp\/sql\/post_syncdb-hook.postgresql_psycopg2.sql<\/code> (\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043f\u043e\u0434 \u043d\u0443\u0436\u0434\u044b):  <\/p>\n<pre><code class=\"sql\">SELECT month_partition_creation(     date_trunc('MONTH', NOW())::date,     date_trunc('MONTH', NOW() + INTERVAL '1 year' )::date,     'yourapp_mymodel', 'date_created'); <\/code><\/pre>\n<p>  \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c <code>syncdb<\/code>:  <\/p>\n<pre><code class=\"bash\">.\/manage.py syncdb <\/code><\/pre>\n<p>\u2026 \u0438 \u0441\u0435\u043a\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 <code>syncdb<\/code>, \u0442\u043e \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0435\u043a\u0446\u0438\u044f\u0445 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e, \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <code>syncdb<\/code> \u0435\u0449\u0451 \u0440\u0430\u0437.<\/p>\n<p>  \u0427\u0442\u043e \u0436, \u0431\u0430\u0437\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0433\u043e\u0442\u043e\u0432\u0430, \u0430 \u0432\u043e\u0442 Django \u2014 \u0435\u0449\u0451 \u043d\u0435\u0442. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 1.3 Django \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u0442 \u0434\u043b\u044f PostgreSQL \u0437\u0430\u043f\u0440\u043e\u0441\u044b <code>INSERT INTO<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0432 \u043d\u0438\u0445 <code>RETURNING...<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <code>id<\/code> \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438. \u0410 \u043c\u0435\u0442\u043e\u0434 \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u044d\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0433\u0440\u0443\u0431\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c Django \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>RETURNING<\/code> \u043d\u0438\u0433\u0434\u0435:  <\/p>\n<pre><code class=\"python\">from django.db import connections, DEFAULT_DB_ALIAS  connections[DEFAULT_DB_ALIAS].features.can_return_id_from_insert = False <\/code><\/pre>\n<p>  \u0410 \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b <code>RETURNING<\/code> \u043d\u0435 \u0438\u0441\u043f\u0442\u0430\u043c\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043d\u0435\u0439:  <\/p>\n<pre><code class=\"python\">from post_syncdb_hooks.partitioning import to_partition  class MyModel(models.Model):     &quot;...&quot;     #...      @to_partition     def save(self, *args, **kwargs):         return super(MyModel, self).save(*args, **kwargs) <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0431\u0430\u0437\u0430 \u0433\u043e\u0442\u043e\u0432\u0430, Django \u0433\u043e\u0442\u043e\u0432, \u043d\u043e \u0433\u043e\u0442\u043e\u0432\u044b \u043b\u0438 \u043c\u044b? \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u0438 \u043a \u043e\u043f\u0440\u043e\u0441\u0443 \u0431\u0430\u0437\u043e\u0439 \u0432\u0441\u0435\u0445 \u0441\u0435\u043a\u0446\u0438\u0439, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c <code>QuerySet<\/code>&#8216;\u044b \u043f\u043e \u043f\u043e\u043b\u044e, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2014 <code>date_created<\/code>):  <\/p>\n<pre><code class=\"python\">qs = MyModel.objects.filter(date_created__lte=..., date_created__gt=...) <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b, \u0431\u0435\u0437 \u043e\u0441\u043e\u0431\u043e\u0439 \u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438, <code>count()<\/code> \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>paginator<\/code> \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u043b\u044e\u0431\u0438\u0442 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u044b. \u0412\u0441\u0451.<\/p>\n<h5>\u041f\u043e\u0434\u043a\u0430\u043f\u043e\u0442\u043d\u043e\u0435 \u043f\u0440\u043e <code>post_syncdb_hooks<\/code><\/h5>\n<p>  <code>post_syncdb_hooks<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>management.py<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0441\u0438\u0432\u0435\u0440 \u0434\u043b\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u0430 <code>post_syncdb<\/code>. \u042d\u0442\u043e\u0442 \u0440\u0435\u0441\u0438\u0432\u0435\u0440 \u0438\u043b\u0438 \u0445\u0443\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041e\u043d \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442, \u043d\u0435 \u043b\u0435\u0436\u0438\u0442 \u043b\u0438 \u0440\u044f\u0434\u043e\u043c \u0441 \u0444\u0430\u0439\u043b\u043e\u043c <code>models.py<\/code> \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0430\u043f\u043a\u0430 <code>sql<\/code>, \u0438, \u0435\u0441\u043b\u0438 \u043b\u0435\u0436\u0438\u0442, \u043d\u0435\u0442 \u043b\u0438 \u0442\u0430\u043c \u0444\u0430\u0439\u043b\u043e\u0432 <code>post_syncdb-hook.sql<\/code> \u0438\u043b\u0438 <code>post_syncdb-hook.(backend).sql<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<p>  <code>post_syncdb_hooks.partitioning<\/code> \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0430\u043a\u043e\u0439 SQL \u0444\u0430\u0439\u043b. \u0412 \u043d\u0451\u043c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c SQL-\u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430: \u0434\u0430\u0442\u0443 \u043d\u0430\u0447\u0430\u043b\u0430, \u0434\u0430\u0442\u0443 \u043a\u043e\u043d\u0446\u0430, \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044f. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0435\u043a\u0446\u0438\u0438 \u043f\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0434\u0430\u0442\u044b \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e \u0434\u0430\u0442\u044b \u043a\u043e\u043d\u0446\u0430 \u0441 \u0448\u0430\u0433\u043e\u043c \u0432 \u043c\u0435\u0441\u044f\u0446, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0440\u0438\u0433\u0433\u0435\u0440 \u0434\u043b\u044f <code>INSERT INTO<\/code> \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0442\u0430\u0431\u043b\u0438\u0446-\u0441\u0435\u043a\u0446\u0438\u0439 (\u0435\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0437\u0430\u0434\u0430\u043d\u044b \u0434\u043b\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b).<\/p>\n<h5>\u041f\u043e\u0434\u043a\u0430\u043f\u043e\u0442\u043d\u043e\u0435 \u043f\u0440\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u044b<\/h5>\n<p>  \u0421\u0430\u043c\u044b\u043c \u0441\u043a\u0443\u0447\u043d\u044b\u043c \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0434\u043b\u044f \u0441\u0435\u043a\u0446\u0438\u0439. \u041a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 SQL \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u0445\u0435\u043c\u0435 \u0441 \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435\u0442 \u2014 \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442. \u0410 \u0432\u043e\u0442, \u043a\u043e\u0433\u0434\u0430 Django \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043a\u0430\u043a \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0434\u043b\u044f \u043c\u0430\u0441\u0442\u0435\u0440-\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 SQL. \u0412 \u0438\u0442\u043e\u0433\u0435, \u044f \u0440\u0435\u0448\u0438\u043b: \u043f\u0443\u0441\u0442\u044c Django \u0442\u0430\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b (\u043e\u043d\u0438 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u043f\u0443\u0441\u0442\u044b\u043c\u0438), \u0430 \u044f \u0438\u0445 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u044e \u0432 \u0441\u0435\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u0423 <code>psql<\/code> \u0435\u0441\u0442\u044c \u043e\u043f\u0446\u0438\u044f <code>-E<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c SQL, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u043c\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438. \u0422\u0430\u043a \u0447\u0442\u043e,  <\/p>\n<pre><code class=\"bash\">sudo -u postgres psql -E db <\/code><\/pre>\n<pre><code class=\"sql\">db=# \\di ********* QUERY ********** SELECT n.nspname as &quot;Schema&quot;,   c.relname as &quot;Name&quot;,   CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as &quot;Type&quot;,   pg_catalog.pg_get_userbyid(c.relowner) as &quot;Owner&quot;,  c2.relname as &quot;Table&quot; FROM pg_catalog.pg_class c      LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace      LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid      LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid WHERE c.relkind IN ('i','')       AND n.nspname &lt;&gt; 'pg_catalog'       AND n.nspname &lt;&gt; 'information_schema'       AND n.nspname !~ '^pg_toast'   AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1,2; ************************** db=# <\/code><\/pre>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e <a href=\"https:\/\/github.com\/podshumok\/django-post-syncdb-hooks\/blob\/64aa758b22ae935ee673bff4f8f8e97583fbd141\/post_syncdb_hooks\/partitioning\/sql\/post_syncdb-hook.postgresql_psycopg2.sql#L30\">\u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0430<\/a> \u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0451 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446-\u0441\u0435\u043a\u0446\u0438\u0439.<\/p>\n<h5>\u0421\u043f\u0430\u0441\u0438\u0431\u043e!<\/h5>\n<p>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0434\u0435\u0441\u044c \u043f\u0430\u043a\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u044e \u0432 \u043f\u0430\u0440\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438.<br \/>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f.<br \/>  \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0448\u0443 \u043e\u0442\u043c\u0435\u0447\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/podshumok\/django-post-syncdb-hooks\/issues\/new\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a> \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0442\u044c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/179873\/\"> http:\/\/habrahabr.ru\/post\/179873\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442.<br \/>  \u042d\u0442\u043e \u0442\u043e\u043f\u0438\u043a \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (\u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435) \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e \u043c\u0435\u0441\u044f\u0446\u0430\u043c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Django+PostgreSQL. \u041c\u043d\u043e\u0433\u043e\u0435 \u0438\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u0438 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 ORM.<\/p>\n<p>  \u041e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u043d\u0443\u0436\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"http:\/\/habrahabr.ru\/post\/74984\/\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438 <a href=\"http:\/\/www.postgresql.org\/docs\/9.1\/static\/ddl-partitioning.html\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 Django \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439. \u0415\u0441\u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0430\u0441\u0442\u043e, \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u044c \u0431\u044b\u043b\u0430 \u0441\u0434\u0435\u043b\u0430\u043d\u0430, \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0441\u043a\u043e\u0440\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0425\u043e\u0440\u043e\u0448\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0441 SQL \u0447\u0435\u043b\u043e\u0432\u0435\u043a. I&#8217;ve read the docs, so you don&#8217;t have to.<\/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-179873","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/179873","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=179873"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/179873\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=179873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=179873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=179873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}