cannot create extension without superuser role cannot create extension without superuser role database database

cannot create extension without superuser role


The Django documentation on postgis has some information on setting up user privileges.

In the worst case you can create a new superuser:

$ createuser --superuser <user_name>

or alter an existing user's role:

postgres# ALTER ROLE <user_name> SUPERUSER;


Easiest way I found is to:

su postgrespsqlalter role user_name superuser;#then create the extension as the user in a different screenalter role user_name nosuperuser;

Basically give the user superuser powers for a short time, and create the extension. Then revoke the superuser powers.

You can also use \connect user_name to become that user and create the extension directly from the postgres user.


Another way to solve this that is suggested in the django docs

$ psql <db name>> CREATE EXTENSION postgis;

you can log into a database as the superuser and create the extension once. The extension will then be available to your api's db user. When django executes CREATE EXTENSION IF NOT EXISTS postgis postgres will not throw.

If you are seeing errors when migrating doublecheck you created the extension in the correct database, a sample sesssion

$ psql=> \l            - list databases=> \c <db name>  - connect to django db=> create extension postgis;

you can verify the extension is installed if you see the table spatial_ref_sys

=> \dt                   List of relations Schema |            Name            | Type  |  Owner--------+----------------------------+-------+---------- public | spatial_ref_sys            | table | postgres

for tests I recommend running them against a local dev database and granting the user superuser abilities like > ALTER ROLE <user_name> SUPERUSER;