{"title":"Installing PostGIS","version":"1.11","locale":"pt-br","docname":"ref/contrib/gis/install/postgis","url":"/pt-br/1.11/ref/contrib/gis/install/postgis/","canonical":"https://djangodocs.dev/pt-br/1.11/ref/contrib/gis/install/postgis/","summary":"PostGIS adds geographic object support to PostgreSQL, turning it into a spatial database. GEOS , PROJ.4 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 para este cabeçalho</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=\"/pt-br/1.11/ref/contrib/gis/install/geolibs/#geosbuild\"><span class=\"std std-ref\">GEOS</span></a>, <a class=\"reference internal\" href=\"/pt-br/1.11/ref/contrib/gis/install/geolibs/#proj4\"><span class=\"std std-ref\">PROJ.4</span></a> and\n<a class=\"reference internal\" href=\"/pt-br/1.11/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=\"http://initd.org/psycopg/\">psycopg2</a> module is required for use as the database adapter when using\nGeoDjango with PostGIS.</p>\n<p>On Debian/Ubuntu, you are advised to install the following packages:\npostgresql-x.x, postgresql-x.x-postgis, postgresql-server-dev-x.x,\npython-psycopg2 (x.x matching the PostgreSQL version you want to install).\nAlternately, you can <a class=\"reference external\" href=\"https://postgis.net/docs/postgis_installation.html#install_short_version\">build from source</a>. Consult the platform-specific\ninstructions if you are on <a class=\"reference internal\" href=\"/pt-br/1.11/ref/contrib/gis/install/#macos\"><span class=\"std std-ref\">macOS</span></a> or <a class=\"reference internal\" href=\"/pt-br/1.11/ref/contrib/gis/testing/#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 para este cabeçalho</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 para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>PostGIS 2 includes an extension for PostgreSQL that’s used to enable spatial\nfunctionality:</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>$ createdb  &lt;db name&gt;\n$ psql &lt;db name&gt;\n&gt; CREATE EXTENSION postgis;\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=\"/pt-br/1.11/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<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\n    <span class=\"n\">operations</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n        <span class=\"n\">CreateExtension</span><span class=\"p\">(</span><span class=\"s1\">&#39;postgis&#39;</span><span class=\"p\">),</span>\n        <span class=\"o\">...</span>\n    <span class=\"p\">]</span>\n</code></pre></div>\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 para este cabeçalho</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 9.x ‣ pgAdmin III</span>) or the\nSQL Shell (<span class=\"menuselection\">Start ‣ PostgreSQL 9.x ‣ SQL Shell</span>).\nFor example, to create a <code class=\"docutils literal notranslate\"><span class=\"pre\">geodjango</span></code> spatial database and user, the following\nmay be executed from the SQL Shell as the <code class=\"docutils literal notranslate\"><span class=\"pre\">postgres</span></code> user:</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=\"n\">postgres</span><span class=\"c1\"># CREATE USER geodjango PASSWORD &#39;my_passwd&#39;;</span>\n<span class=\"n\">postgres</span><span class=\"c1\"># 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":"Referência da API","url":"/pt-br/1.11/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/pt-br/1.11/ref/contrib/"},{"docname":"ref/contrib/gis/index","title":"GeoDjango","url":"/pt-br/1.11/ref/contrib/gis/"},{"docname":"ref/contrib/gis/install/index","title":"GeoDjango Installation","url":"/pt-br/1.11/ref/contrib/gis/install/"}],"prev":{"docname":"ref/contrib/gis/install/geolibs","title":"Installing Geospatial libraries","url":"/pt-br/1.11/ref/contrib/gis/install/geolibs/"},"next":{"docname":"ref/contrib/gis/install/spatialite","title":"Installing SpatiaLite","url":"/pt-br/1.11/ref/contrib/gis/install/spatialite/"},"formats":{"html":"/pt-br/1.11/ref/contrib/gis/install/postgis/","markdown":"/pt-br/1.11/ref/contrib/gis/install/postgis.md","json":"/pt-br/1.11/ref/contrib/gis/install/postgis.json"},"source":"https://github.com/django/django/blob/stable/1.11.x/docs/ref/contrib/gis/install/postgis.txt","official":"https://docs.djangoproject.com/pt-br/1.11/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","1.9"],"inLocales":["en","fr","ja","id","pt-br","ko","es","el","pl"]}