2013-05-13 14 views
26

Próbuję uruchomić testy jednostkowe w Django, i tworzy nową bazę danych. Baza danych ma rozszerzenia postgis i kiedy regularnie tworzę bazę danych, używam "CREATE EXTENSION postgis".Nie można utworzyć rozszerzenia bez roli administratora

Jednak, kiedy uruchomić testy, to daje mi następujący błąd:

$ ./manage.py test 
Creating test database for alias 'default'... 
Got an error creating the test database: database "test_project" already exists 

Type 'yes' if you would like to try deleting the test database 'test_project', or 'no' to cancel: yes 
Destroying old test database 'default'... 
DatabaseError: permission denied to create extension "postgis" 
HINT: Must be superuser to create this extension. 

użytkownik ma uprawnienie Tworzenie DB już używam PostgreSQL 9.1 w Ubuntu 12.04 z PostGIS 2.0.

Odpowiedz

22

Najprostszym sposobem znalazłem jest:

su postgres 
psql 
alter role user_name superuser; 
#then create the extension as the user in a different screen 
alter role user_name nosuperuser; 

Zasadniczo daj użytkownikowi uprawnienia superużytkownika na krótki czas i utwórz rozszerzenie. Następnie odwołaj moce superużytkownika.

Możesz również użyć \connect user_name, aby zostać tym użytkownikiem i utworzyć rozszerzenie bezpośrednio od użytkownika postgres.

+1

To ma sens, nie ma sensu utrzymywać użytkownika z uprawnieniami administratora, zmniejsza powierzchnię ataku. Lubię to! –