2012-09-25 7 views
12

Sto cercando di utilizzare PostgreSQL con il libro "Seven Databases in Seven Weeks". Sto usando PostgreSQL 8.4.1 su un server Ubuntu 10.04.Problemi nell'installazione di cubo modulo aggiuntivo in PostgreSQL 8.4

Il primo compito è creare un database denominato "libro" e verificare se i pacchetti contrib sono stati installati correttamente.

$ createdb book 
$ psql book -c "SELECT '1'::cube;" 

Quando faccio che ottengo il seguente output:

ERROR: type "cube" does not exist 
LINE 1: SELECT '1'::cube; 

ho già installato il pacchetto di cubo con il seguente comando:

$ sudo -u postgres psql postgres < /usr/share/postgresql/8.4/contrib/cube.sql 

ho provato a riavviare PostgreSQL ma il problema persiste . Quando ho provato a fare funzionare il pacchetto di importare una seconda volta ho ricevuto il seguente messaggio, in cui si afferma esplicitamente che type "cube" already exists:

SET 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
ERROR: type "cube" already exists 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
COMMENT 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
ERROR: operator < already exists 
ERROR: operator > already exists 
ERROR: operator <= already exists 
ERROR: operator >= already exists 
ERROR: operator && already exists 
ERROR: operator = already exists 
ERROR: operator <> already exists 
ERROR: operator @> already exists 
ERROR: operator <@ already exists 
ERROR: operator @ already exists 
ERROR: operator ~ already exists 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
CREATE FUNCTION 
ERROR: operator class "cube_ops" for access method "btree" already exists 
ERROR: operator class "gist_cube_ops" for access method "gist" already exists 

Allora, che cosa sto sbagliando?

risposta

11

L'estensione è stata installata sul proprio database postgres (il database di sistema predefinito denominato "postgres") - che probabilmente è non quello che si desidera. Devi installare l'estensione su il tuo database - una volta per database in cui utilizzarlo.

Oppure è possibile installarlo su un database di template (template1 per impostazione predefinita, ma qualsiasi database può essere utilizzato come modello), in modo che ogni nuovo database creato inizia con la funzionalità di pre-installato.

in PostgreSQL 8.4 o più anziani, è necessario eseguire nella shell:

psql -d dbname -f SHAREDIR/contrib/cube.sql

Dove dbname è il nome del vostro db obiettivo reale. Oppure usa la linea equivalente che hai nella tua domanda.
More info for PostgreSQL 8.4 in the manual here.

Dato PostgreSQL 9.1 questo è stato ulteriormente semplificato e si può semplicemente eseguire in una sessione di database:

CREATE extension cube 

More in the manual here.

+0

Grazie! Questo è stato. Ho anche provato il metodo per PostgreSQL 9.1 su un'altra macchina con Ubuntu 12.04. –

6

Il comando completo per la 9.1 è:

psql -d dbname 
    CREATE EXTENSION cube; 
    \q 

Dove dbname è il nome del database che si desidera aggiungere l'estensione a. Si noti che l'ultimo comando è un backlash q per uscire. E non dimenticare il punto e virgola alla fine del secondo.

Problemi correlati