Recently I went into trouble trying to use hstore with Django. I installed hstore this way:
$ sudo -u postgres psql
postgres=# CREATE EXTENSION hstore;
WARNING: => is deprecated as an operator name
DETAIL: This name may be disallowed altogether in future versions of PostgreSQL.
CREATE EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+--------------------------------------------------
hstore | 1.0 | public | data type for storing sets of (key, value) pairs
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
And naively thought that my new databases would include hstore. That ain’t the case:
$ createdb dbtest
$ psql -d dbtest -c '\dx'
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(1 row)
Is there a way to automatically have hstore in a newly created database ?
Long story short:
Install hstore in the template1 database:
Step-by-step explanation:
As stated by the PostgreSQL documentation:
Installing an extension is database-specific. The following returns you the current database name:
In case you have a database named after your username. Now with
dbtest:Ok, you got it. Now, to create new databases with hstore installed, you’ll have to install it in the
template1database. According to the doc:Let’s do this:
And check that it works :
Done!