{"title":"Installing PostGIS","version":"5.1","locale":"pl","docname":"ref/contrib/gis/install/postgis","url":"/pl/5.1/ref/contrib/gis/install/postgis/","canonical":"https://djangodocs.dev/pl/5.1/ref/contrib/gis/install/postgis/","summary":"PostGIS adds geographic object support to PostgreSQL, turning it into a spatial database. GEOS , PROJ and GDAL should be installed prior to building PostGIS. You…","html":"<h1>Installing PostGIS<a class=\"heading-anchor\" href=\"#installing-postgis\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><a class=\"reference external\" href=\"https://postgis.net/\">PostGIS</a> adds geographic object support to PostgreSQL, turning it\ninto a spatial database. <a class=\"reference internal\" href=\"/pl/5.1/ref/contrib/gis/install/geolibs/#geosbuild\"><span class=\"std std-ref\">GEOS</span></a>, <a class=\"reference internal\" href=\"/pl/5.1/ref/contrib/gis/install/geolibs/#proj4\"><span class=\"std std-ref\">PROJ</span></a> and\n<a class=\"reference internal\" href=\"/pl/5.1/ref/contrib/gis/install/geolibs/#gdalbuild\"><span class=\"std std-ref\">GDAL</span></a> should be installed prior to building PostGIS. You\nmight also need additional libraries, see <a class=\"reference external\" href=\"https://postgis.net/docs/postgis_installation.html#install_requirements\">PostGIS requirements</a>.</p>\n<p>The <a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/\">psycopg</a> or <a class=\"reference external\" href=\"https://www.psycopg.org/\">psycopg2</a> module is required for use as the database\nadapter when using GeoDjango with PostGIS.</p>\n<p>On Debian/Ubuntu, you are advised to install the following packages:\n<code class=\"docutils literal notranslate\"><span class=\"pre\">postgresql-x</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">postgresql-x-postgis-3</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">postgresql-server-dev-x</span></code>,\nand <code class=\"docutils literal notranslate\"><span class=\"pre\">python3-psycopg3</span></code> (x matching the PostgreSQL version you want to\ninstall). Alternately, you can <a class=\"reference external\" href=\"https://postgis.net/docs/postgis_installation.html#install_short_version\">build from source</a>. Consult the\nplatform-specific instructions if you are on <a class=\"reference internal\" href=\"/pl/5.1/ref/contrib/gis/install/#macos\"><span class=\"std std-ref\">macOS</span></a> or <a class=\"reference internal\" href=\"/pl/5.1/ref/contrib/gis/install/#windows\"><span class=\"std std-ref\">Windows</span></a>.</p>\n<section id=\"post-installation\">\n<h2>Post-installation<a class=\"heading-anchor\" href=\"#post-installation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"creating-a-spatial-database\">\n<span id=\"spatialdb-template\"></span><h3>Creating a spatial database<a class=\"heading-anchor\" href=\"#creating-a-spatial-database\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>PostGIS includes an extension for PostgreSQL that’s used to enable spatial\nfunctionality:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code>$<span class=\"w\"> </span>createdb<span class=\"w\">  </span>&lt;db<span class=\"w\"> </span>name&gt;\n$<span class=\"w\"> </span>psql<span class=\"w\"> </span>&lt;db<span class=\"w\"> </span>name&gt;\n&gt;<span class=\"w\"> </span>CREATE<span class=\"w\"> </span>EXTENSION<span class=\"w\"> </span>postgis<span class=\"p\">;</span>\n</code></pre></div>\n<p>The database user must be a superuser in order to run\n<code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">EXTENSION</span> <span class=\"pre\">postgis;</span></code>. The command is run during the <a class=\"reference internal\" href=\"/pl/5.1/ref/django-admin/#django-admin-migrate\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">migrate</span></code></a>\nprocess. An alternative is to use a migration operation in your project:</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=\"w\"> </span><span class=\"nn\">django.contrib.postgres.operations</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">CreateExtension</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.db</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">migrations</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Migration</span><span class=\"p\">(</span><span class=\"n\">migrations</span><span class=\"o\">.</span><span class=\"n\">Migration</span><span class=\"p\">):</span>\n    <span class=\"n\">operations</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"n\">CreateExtension</span><span class=\"p\">(</span><span class=\"s2\">&quot;postgis&quot;</span><span class=\"p\">),</span> <span class=\"o\">...</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>If you plan to use PostGIS raster functionality, you should also activate the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">postgis_raster</span></code> extension. You can install the extension using the\n<a class=\"reference internal\" href=\"/pl/5.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.CreateExtension\" title=\"django.contrib.postgres.operations.CreateExtension\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CreateExtension</span></code></a> migration\noperation, or directly by running <code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">EXTENSION</span> <span class=\"pre\">postgis_raster;</span></code>.</p>\n<p>GeoDjango does not currently leverage any <a class=\"reference external\" href=\"https://postgis.net/docs/Topology.html\">PostGIS topology functionality</a>.\nIf you plan to use those features at some point, you can also install the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">postgis_topology</span></code> extension by issuing <code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">EXTENSION</span>\n<span class=\"pre\">postgis_topology;</span></code>.</p>\n</section>\n<section id=\"managing-the-database\">\n<h3>Managing the database<a class=\"heading-anchor\" href=\"#managing-the-database\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>To administer the database, you can either use the pgAdmin III program\n(<span class=\"menuselection\">Start ‣ PostgreSQL X ‣ pgAdmin III</span>) or the SQL Shell\n(<span class=\"menuselection\">Start ‣ PostgreSQL X ‣ SQL Shell</span>). For example, to create\na <code class=\"docutils literal notranslate\"><span class=\"pre\">geodjango</span></code> spatial database and user, the following may be executed from\nthe SQL Shell as the <code class=\"docutils literal notranslate\"><span class=\"pre\">postgres</span></code> user:</p>\n<div class=\"code-block\" data-language=\"psql\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">SQL</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=\"SQL code\"><code><span class=\"n\">postgres</span><span class=\"o\">#</span><span class=\"w\"> </span><span class=\"k\">CREATE</span><span class=\"w\"> </span><span class=\"k\">USER</span><span class=\"w\"> </span><span class=\"n\">geodjango</span><span class=\"w\"> </span><span class=\"k\">PASSWORD</span><span class=\"w\"> </span><span class=\"s1\">&#39;my_passwd&#39;</span><span class=\"p\">;</span>\n<span class=\"go\">postgres# CREATE DATABASE geodjango OWNER geodjango;</span>\n</code></pre></div>\n</section>\n</section>","rootId":"installing-postgis","toc":[{"title":"Post-installation","anchor":"post-installation","children":[{"title":"Creating a spatial database","anchor":"creating-a-spatial-database","children":[]},{"title":"Managing the database","anchor":"managing-the-database","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/pl/5.1/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/pl/5.1/ref/contrib/"},{"docname":"ref/contrib/gis/index","title":"GeoDjango","url":"/pl/5.1/ref/contrib/gis/"},{"docname":"ref/contrib/gis/install/index","title":"GeoDjango Installation","url":"/pl/5.1/ref/contrib/gis/install/"}],"prev":{"docname":"ref/contrib/gis/install/geolibs","title":"Installing Geospatial libraries","url":"/pl/5.1/ref/contrib/gis/install/geolibs/"},"next":{"docname":"ref/contrib/gis/install/spatialite","title":"Installing SpatiaLite","url":"/pl/5.1/ref/contrib/gis/install/spatialite/"},"formats":{"html":"/pl/5.1/ref/contrib/gis/install/postgis/","markdown":"/pl/5.1/ref/contrib/gis/install/postgis.md","json":"/pl/5.1/ref/contrib/gis/install/postgis.json"},"source":"https://github.com/django/django/blob/stable/5.1.x/docs/ref/contrib/gis/install/postgis.txt","official":"https://docs.djangoproject.com/pl/5.1/ref/contrib/gis/install/postgis/","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","it","pt-br","ko","es","el","pl"]}