{"title":"Database migration operations","version":"3.0","locale":"pl","docname":"ref/contrib/postgres/operations","url":"/pl/3.0/ref/contrib/postgres/operations/","canonical":"https://djangodocs.dev/pl/3.0/ref/contrib/postgres/operations/","summary":"All of these operations are available from the django.contrib.postgres.operations module.","html":"<h1>Database migration operations<a class=\"heading-anchor\" href=\"#database-migration-operations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>All of these <a class=\"reference internal\" href=\"/pl/3.0/ref/migration-operations/\"><span class=\"doc\">operations</span></a> are available from\nthe <code class=\"docutils literal notranslate\">django.contrib.postgres.operations</code> module.</p>\n<section id=\"creating-extension-using-migrations\">\n<span id=\"create-postgresql-extensions\"></span><h2>Creating extension using migrations<a class=\"heading-anchor\" href=\"#creating-extension-using-migrations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>You can create a PostgreSQL extension in your database using a migration file.\nThis example creates an hstore extension, but the same principles apply for\nother extensions.</p>\n<p>Set up the hstore extension in PostgreSQL before the first <code class=\"docutils literal notranslate\">CreateModel</code>\nor <code class=\"docutils literal notranslate\">AddField</code> operation that involves\n<a class=\"reference internal\" href=\"/pl/3.0/ref/contrib/postgres/fields/#django.contrib.postgres.fields.HStoreField\" title=\"django.contrib.postgres.fields.HStoreField\"><code class=\"xref py py-class docutils literal notranslate\">HStoreField</code></a> by adding a migration with\nthe <a class=\"reference internal\" href=\"#django.contrib.postgres.operations.HStoreExtension\" title=\"django.contrib.postgres.operations.HStoreExtension\"><code class=\"xref py py-class docutils literal notranslate\">HStoreExtension</code></a> operation.\nFor example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib.postgres.operations</span> <span class=\"kn\">import</span> HStoreExtension\n\n<span class=\"k\">class</span> <span class=\"nc\">Migration</span><span class=\"p\">(</span>migrations<span class=\"o\">.</span>Migration<span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n\n    operations <span class=\"o\">=</span> <span class=\"p\">[</span>\n        HStoreExtension<span class=\"p\">(),</span>\n        <span class=\"o\">...</span>\n    <span class=\"p\">]</span>\n</code></pre></div>\n<p>Creating the extension requires a database user with superuser privileges.\nIf the Django database user doesn’t have superuser privileges, you’ll have\nto create the extension outside of Django migrations with a user that has\nthe appropriate privileges. In that case, connect to your Django database and\nrun the query <code class=\"docutils literal notranslate\">CREATE EXTENSION IF NOT EXISTS hstore;</code>.</p>\n</section>\n<section id=\"createextension\">\n<h2><code class=\"docutils literal notranslate\">CreateExtension</code><a class=\"heading-anchor\" href=\"#createextension\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.CreateExtension\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">CreateExtension</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.CreateExtension\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>An <code class=\"docutils literal notranslate\">Operation</code> subclass which installs PostgreSQL extensions.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.CreateExtension.name\">\n<span class=\"sig-name descname\">name</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.CreateExtension.name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>This is a required argument. The name of the extension to be installed.</p>\n</dd></dl>\n\n</dd></dl>\n\n</section>\n<section id=\"btreeginextension\">\n<h2><code class=\"docutils literal notranslate\">BtreeGinExtension</code><a class=\"heading-anchor\" href=\"#btreeginextension\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.BtreeGinExtension\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">BtreeGinExtension</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.BtreeGinExtension\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Install the <code class=\"docutils literal notranslate\">btree_gin</code> extension.</p>\n</dd></dl>\n\n</section>\n<section id=\"btreegistextension\">\n<h2><code class=\"docutils literal notranslate\">BtreeGistExtension</code><a class=\"heading-anchor\" href=\"#btreegistextension\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.BtreeGistExtension\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">BtreeGistExtension</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.BtreeGistExtension\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Install the <code class=\"docutils literal notranslate\">btree_gist</code> extension.</p>\n</dd></dl>\n\n</section>\n<section id=\"citextextension\">\n<h2><code class=\"docutils literal notranslate\">CITextExtension</code><a class=\"heading-anchor\" href=\"#citextextension\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.CITextExtension\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">CITextExtension</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.CITextExtension\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Installs the <code class=\"docutils literal notranslate\">citext</code> extension.</p>\n</dd></dl>\n\n</section>\n<section id=\"cryptoextension\">\n<h2><code class=\"docutils literal notranslate\">CryptoExtension</code><a class=\"heading-anchor\" href=\"#cryptoextension\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.CryptoExtension\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">CryptoExtension</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.CryptoExtension\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Installs the <code class=\"docutils literal notranslate\">pgcrypto</code> extension.</p>\n</dd></dl>\n\n</section>\n<section id=\"hstoreextension\">\n<h2><code class=\"docutils literal notranslate\">HStoreExtension</code><a class=\"heading-anchor\" href=\"#hstoreextension\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.HStoreExtension\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">HStoreExtension</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.HStoreExtension\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Installs the <code class=\"docutils literal notranslate\">hstore</code> extension and also sets up the connection to\ninterpret hstore data for possible use in subsequent migrations.</p>\n</dd></dl>\n\n</section>\n<section id=\"trigramextension\">\n<h2><code class=\"docutils literal notranslate\">TrigramExtension</code><a class=\"heading-anchor\" href=\"#trigramextension\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.TrigramExtension\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">TrigramExtension</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.TrigramExtension\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Installs the <code class=\"docutils literal notranslate\">pg_trgm</code> extension.</p>\n</dd></dl>\n\n</section>\n<section id=\"unaccentextension\">\n<h2><code class=\"docutils literal notranslate\">UnaccentExtension</code><a class=\"heading-anchor\" href=\"#unaccentextension\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.UnaccentExtension\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">UnaccentExtension</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.UnaccentExtension\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Installs the <code class=\"docutils literal notranslate\">unaccent</code> extension.</p>\n</dd></dl>\n\n</section>\n<section id=\"index-concurrent-operations\">\n<h2>Index concurrent operations<a class=\"heading-anchor\" href=\"#index-concurrent-operations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<aside class=\"version-note version-added\" data-version=\"3.0\" role=\"note\">\n<p class=\"version-note-title\">New in Django 3.0</p></aside>\n<p>PostgreSQL supports the <code class=\"docutils literal notranslate\">CONCURRENTLY</code> option to <code class=\"docutils literal notranslate\">CREATE INDEX</code> and\n<code class=\"docutils literal notranslate\">DROP INDEX</code> statements to add and remove indexes without locking out writes.\nThis option is useful for adding or removing an index in a live production\ndatabase.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.AddIndexConcurrently\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AddIndexConcurrently</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">index</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.AddIndexConcurrently\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Like <a class=\"reference internal\" href=\"/pl/3.0/ref/migration-operations/#django.db.migrations.operations.AddIndex\" title=\"django.db.migrations.operations.AddIndex\"><code class=\"xref py py-class docutils literal notranslate\">AddIndex</code></a>, but creates an\nindex with the <code class=\"docutils literal notranslate\">CONCURRENTLY</code> option. This has a few caveats to be aware\nof when using this option, see <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY\">the PostgreSQL documentation of building\nindexes concurrently</a>.</p>\n</dd></dl>\n\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.operations.RemoveIndexConcurrently\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RemoveIndexConcurrently</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_name</em>, <em class=\"sig-param\">name</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.operations.RemoveIndexConcurrently\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Like <a class=\"reference internal\" href=\"/pl/3.0/ref/migration-operations/#django.db.migrations.operations.RemoveIndex\" title=\"django.db.migrations.operations.RemoveIndex\"><code class=\"xref py py-class docutils literal notranslate\">RemoveIndex</code></a>, but removes the\nindex with the <code class=\"docutils literal notranslate\">CONCURRENTLY</code> option. This has a few caveats to be aware\nof when using this option, see <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/sql-dropindex.html\">the PostgreSQL documentation</a>.</p>\n</dd></dl>\n\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Informacja</p>\n<p>The <code class=\"docutils literal notranslate\">CONCURRENTLY</code> option is not supported inside a transaction (see\n<a class=\"reference internal\" href=\"/pl/3.0/howto/writing-migrations/#non-atomic-migrations\"><span class=\"std std-ref\">non-atomic migration</span></a>).</p>\n</aside>\n</section>","rootId":"database-migration-operations","toc":[{"title":"Creating extension using migrations","anchor":"creating-extension-using-migrations","children":[]},{"title":"CreateExtension","anchor":"createextension","children":[]},{"title":"BtreeGinExtension","anchor":"btreeginextension","children":[]},{"title":"BtreeGistExtension","anchor":"btreegistextension","children":[]},{"title":"CITextExtension","anchor":"citextextension","children":[]},{"title":"CryptoExtension","anchor":"cryptoextension","children":[]},{"title":"HStoreExtension","anchor":"hstoreextension","children":[]},{"title":"TrigramExtension","anchor":"trigramextension","children":[]},{"title":"UnaccentExtension","anchor":"unaccentextension","children":[]},{"title":"Index concurrent operations","anchor":"index-concurrent-operations","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/pl/3.0/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/pl/3.0/ref/contrib/"},{"docname":"ref/contrib/postgres/index","title":"django.contrib.postgres","url":"/pl/3.0/ref/contrib/postgres/"}],"prev":{"docname":"ref/contrib/postgres/lookups","title":"PostgreSQL specific lookups","url":"/pl/3.0/ref/contrib/postgres/lookups/"},"next":{"docname":"ref/contrib/postgres/search","title":"Full text search","url":"/pl/3.0/ref/contrib/postgres/search/"},"formats":{"html":"/pl/3.0/ref/contrib/postgres/operations/","markdown":"/pl/3.0/ref/contrib/postgres/operations.md","json":"/pl/3.0/ref/contrib/postgres/operations.json"},"source":"https://github.com/django/django/blob/stable/3.0.x/docs/ref/contrib/postgres/operations.txt","official":"https://docs.djangoproject.com/pl/3.0/ref/contrib/postgres/operations/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}