2015-06-12 13 views
5

ho installato un'estensione Postgres (unaccent) conCome faccio Postgres estensione a disposizione non superuser

sudo su posgres 
psql create extension unaccent 

e ora posso usare unacccent in SQL, ma solo se io sono l'utente Postgres.

Come faccio Postgres estensione a disposizione di tutti/un altro utente

(Im su Ubuntu utilizzando Postgres 9.3.5 installato usando apt-install)

jthinksearch=# \dx; 
         List of installed extensions 
    Name | Version | Schema |     Description 
----------+---------+------------+--------------------------------------------- 
plpgsql | 1.0  | pg_catalog | PL/pgSQL procedural language 
unaccent | 1.0  | public  | text search dictionary that removes accents 
(2 rows) 

jthinksearch=# 


jthinksearch=> \du; 
          List of roles 
Role name |     Attributes     | Member of 
-----------+------------------------------------------------+----------- 
postgres | Superuser, Create role, Create DB, Replication | {} 
ubuntu |            | {} 

postgres @ ip-172-31- 39-147:/home/ubuntu/code/jthinksearch/reports/src/main/sql $ exit ubuntu @ ip-172-31-39-147: ~/code/jthinksearch/reports/src/main/sql $ psql jthinksearch psql (9.3.5) Digitare "help" per aiuto.

ho dato utente ruolo superuser, ma che non ha ancora aiuto, allora come suggerito mettere il nome dello schema in, che ha avuto un effetto sul messaggio di errore, ma ancora non ha funzionato

jthinksearch=# \du; 
          List of roles 
Role name |     Attributes     | Member of 
-----------+------------------------------------------------+----------- 
postgres | Superuser, Create role, Create DB, Replication | {} 
ubuntu | Superuser          | {} 

jthinksearch=# select unaccent(name) from musicbrainz.artist where id=195660; 
ERROR: function unaccent(character varying) does not exist 
LINE 1: select unaccent(name) from musicbrainz.artist where id=19566... 
      ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 
jthinksearch=# ^C 
jthinksearch=# select public.unaccent(name) from musicbrainz.artist where id=195660; 
ERROR: text search dictionary "unaccent" does not exist 
jthinksearch=# 
+1

'grant' accesso alle funzioni dall'interno. Se crei l'estensione nel proprio schema, puoi semplicemente concedere l'accesso a tutto in quello schema –

+0

Come, per favore, ho provato 'CONCEDO TUTTO SU TUTTE LE FUNZIONI IN SCHEMA pubblico TO ubuntu' e non ha avuto effetto –

+0

@a_horse_with_no_name Provato tutto il mio schemi e ancora non funziona –

risposta

5

Sulla base di questo messaggio di errore:

ERROR: text search dictionary "unaccent" does not exist

e quello precedente in cui unaccent senza il prefisso schema non viene trovato, significa che il public schema, in cui risiede la funzione unaccent, non è nel vostro search_path.

Succede che unaccent fallisca in questo caso perché è una funzione di dizionario e in pratica ha bisogno di trovare le sue cose attraverso lo search_path.

questo è spiegato più in dettaglio in Does PostgreSQL support “accent insensitive” collations?

Una volta che lo schema public viene aggiunto alla search_path degli utenti che hanno bisogno di chiamarlo (questo è normalmente il default), questo dovrebbe funzionare e non hanno bisogno di essere superutente

O se questa soluzione non è accettabile, è possibile utilizzare anche una funzione di stub intermedio che incorpora lo schema e aggiunge l'immutabilità, come suggerito nella risposta collegata sopra.

+0

ah, grazie. Sì, questo era il problema che il mio database conteneva due schemi che dovevo usare, quindi avevo già fatto ALTER USER ubuntu SET search_path = discogs, musicbrainz; passando a ALTER USER ubuntu SET search_path = discogs, musicbrainz, public; risolto il problema –

+0

Ho lo stesso identico problema, non posso usare l'estensione 'unaccent' senza utente' postgres'. Ma ancora non riesco a farlo funzionare. –

Problemi correlati