postgres hstore存在且不存在同时
我在远程服务器上设置了Rails应用程序并创建了一个hstore扩展
sudo -u postgres psql CREATE EXTENSION hstore;
然后,我在其中一个postgres表中部署了一个使用hstore的应用程序的迭代,但是当它运行迁移时,它给出了一条错误消息
PG::UndefinedObject: ERROR: type "hstore" does not exist
然后我再次尝试这样做
sudo -u postgres psql CREATE EXTENSION hstore;
但它告诉我hstore已经存在
ERROR: extension "hstore" already exists
这圈继续。
知道可能导致这个问题的原因是什么? 我在Ubuntu 12.04服务器上使用postgres 9.1
更新注意,想知道这个问题是否与权限有关,我试图检查我的权限,但是得到了以下错误
sudo -u postgres psql -U username psql: FATAL: Peer authentication failed for user "username"
更新虽然安装了hstore,但它不是我正在使用的数据库的扩展。 如何在特定的数据库中安装它?
psql -d db_production -c '\dx' List of installed extensions Name | Version | Schema | Description ---------+---------+------------+------------------------------ plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language (1 row)
要在数据库中创建扩展,必须显式连接到该数据库。 因此,如果您的数据库是my_app_development
,则必须执行以下操作:
sudo -u postgres psql my_app_development create extension hstore;
另外,你不知道你在哪个版本的版本。 如果您不在rails-4上,则必须使用postgres hstore gem 。
使用此SO答案如何创建已安装hstore扩展的新数据库? ,我发现我必须为template1数据库创建扩展,然后我创建的任何其他数据库都会安装它