postgresql postgres hstore 同时存在和不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19467481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
postgres hstore exists and doesn't exist at same time
提问by Tomoko Yamaguchi
I set up a Rails app on a remote server and created an hstore extension
我在远程服务器上设置了一个 Rails 应用程序并创建了一个 hstore 扩展
sudo -u postgres psql
CREATE EXTENSION hstore;
I then deployed an iteration of the app that uses hstore in one of the postgres tables, but when it ran the migrations it gave an error message
然后我部署了一个应用程序的迭代,它在一个 postgres 表中使用了 hstore,但是当它运行迁移时,它给出了一条错误消息
PG::UndefinedObject: ERROR: type "hstore" does not exist
I then tried to do this again
然后我再次尝试这样做
sudo -u postgres psql
CREATE EXTENSION hstore;
but it told me hstore already exists
但它告诉我 hstore 已经存在
ERROR: extension "hstore" already exists
and this circle continued on.
而这个圈子还在继续。
Any idea what might be causing this problem? I'm using postgres 9.1 on an Ubuntu 12.04 server
知道什么可能导致这个问题吗?我在 Ubuntu 12.04 服务器上使用 postgres 9.1
UpdateNote, wondering if this issue was related to permissions, I tried to check my permissions like this but got the following error
更新注意,想知道这个问题是否与权限有关,我尝试像这样检查我的权限但出现以下错误
sudo -u postgres psql -U username
psql: FATAL: Peer authentication failed for user "username"
UpdateAlthough hstore is installed, it's not an extension for the database I'm using. How to install it in a specific database?
更新虽然安装了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)
回答by kik
To create extension in your database, you have to explicitly connect to that database. So, if your database is my_app_development
, you have to do :
要在您的数据库中创建扩展,您必须显式连接到该数据库。因此,如果您的数据库是my_app_development
,则必须执行以下操作:
sudo -u postgres psql my_app_development
create extension hstore;
Also, you do not tell which rails version you're on. If you're not on rails-4, you will have to use the postgres hstore gem.
此外,您不知道您使用的是哪个 Rails 版本。如果您不在 rails-4 上,则必须使用postgres hstore gem。
回答by Tomoko Yamaguchi
Using this SO answer How to create a new database with the hstore extension already installed?, I found out that I had to create the extension for the template1 database and then any other database I created thereafter would have it installed
使用这个 SO 答案How to create a new database with the hstore extension has already installed? ,我发现我必须为 template1 数据库创建扩展,然后我创建的任何其他数据库都会安装它