我正在尝试使用带有 pg 扩展名(版本 0.5.4)的 node.js 在 postgres 数据库中进行插入或更新。
到目前为止,我有这个代码:(...)
client.query({
text: "update users set is_active = 0, ip = $1 where id=$2",
values: [ip,id]
}, function(u_err, u_result){
debug(socket_id,"update query result: ",u_result);
debug(socket_id,"update query error: ",u_err);
date_now = new Date();
var month = date_now.getMonth() + 1;
if(!u_err){
client.query({
text: 'insert into users (id,first_name,last_name,is_active,ip,date_joined) values' +
'($1,$2,$3,$4,$5,$6)',
values: [
result.id,
result.first_name,
result.last_name,
1,
ip,
date_now.getFullYear() + "-" + month + "-" + date_now.getDate() + " " + date_now.getHours() + ":" + date_now.getMinutes() …Run Code Online (Sandbox Code Playgroud) 我查看了postgres文档,下面给出了概要:
pg_resetxlog [-f] [-n] [-ooid ] [-x xid ] [-e xid_epoch ] [-m mxid ] [-O mxoff ] [-l timelineid,fileid,seg ] datadir
Run Code Online (Sandbox Code Playgroud)
但是在文档中没有任何地方可以解释数据的含义.是它%postgres-path%/9.0/data还是可能%postgres-path%/9.0/data/pgxlog?
另外,如果我想更改我的xlog目录,我可以简单地移动当前pg_xlog目录中的项目并运行命令指向另一个目录吗?(假设我现在的pg_xlog里面的目录是在/data1/postgres/data/pg_xlog和目录我想要的日志,去的是:/data2/pg_xlog)
以下命令会实现我刚才描述的吗?
mv /data1/postgres/data/pg_xlog /data2/pg_xlog
pg_resetxlog /data2
Run Code Online (Sandbox Code Playgroud) 奥拉所有聪明的人.我正面临着一个问题,我正在努力解决但却失败了.我正在尝试在安装了Omnibus Chef的服务器上安装pg gem,即http://www.opscode.com/chef/install/
基本上已经报告了这个问题(http://tickets.opscode.com/browse/COOK-1406)但我正在寻找一个解决方案,如果有的话 - 建议从Opscode Ubuntu repos安装包的解决方法 - 但那些带有红宝石1.8 - 我希望我不必再继续为什么我不愿意这样做:)
我在安装pg gem时遇到的错误是:
$ sudo /opt/chef/embedded/bin/gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/opt/chef/embedded/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no …Run Code Online (Sandbox Code Playgroud) 正在工作
不知道发生了什么。在 linux 机器上构建 gemfile.lock 并将其移动。有丢失的东西,运行捆绑安装,工作。
Bundle 忽略了我在 Gemfile 中包含的“pg”gem。通过安装 pggem install pg工作正常,当我使用gem list --local.
宝石档案:
source 'http://rubygems.org'
gem 'rails'
gem 'pg'
Run Code Online (Sandbox Code Playgroud)
bundle install (无页):
Using rake (10.0.4)
Using i18n (0.6.1)
Using multi_json (1.7.2)
Using activesupport (3.2.13)
Using builder (3.0.4)
Using activemodel (3.2.13)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.2)
Using tilt (1.3.7)
Using sprockets (2.2.2)
Using actionpack (3.2.13)
Using mime-types (1.23)
Using polyglot (0.3.3) …Run Code Online (Sandbox Code Playgroud) 我在OS X上使用Postgres.app(10.8.3).我修改了我的应用程序PATH的bin文件夹在所有其他文件夹之前.
Rammy:~ phrogz$ which pg_config
/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Run Code Online (Sandbox Code Playgroud)
我安装了rvm并且可以安装pg gem而不会出错,但是当我要求它时,我收到一个错误:
Rammy:~ phrogz$ gem -v
1.8.25
Rammy:~ phrogz$ gem install pg
Fetching: pg-0.15.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed pg-0.15.1
1 gem installed
Rammy:~ phrogz$ ruby -v -e "require 'pg'"
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0]
/Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': dlopen(/Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: @executable_path/../lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /Applications/Postgres.app/Contents/MacOS/lib/libpq.dylib
Reason: image not found - /Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg_ext.bundle
from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg.rb:4:in `<top (required)>' …Run Code Online (Sandbox Code Playgroud) 我正在使用rails中的hstore和postgresql存储产品信息,包括产品的发布年份.现在,我希望能够查询在特定年份之前或之后发布的所有产品.我可以使用以下方法查询'data'hstore列中包含year字段的所有记录:
Product.where("data ? 'year'")
Run Code Online (Sandbox Code Playgroud)
由于hstore,年份值存储为字符串.因此,我尝试将年份类型转换为整数,以便查找年份大于/小于X的记录:
Product.where("(data ? 'year')::int > 2011")
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用,我总是得到一个空数组的结果作为回报.我究竟做错了什么?还有另一种方法吗?
我在Rails应用程序中使用pg_search gem来搜索用户 - 他们的bios和相关的技能模型.用户是开发人员,所以他们的技能包括"CSS","C++","C#","Objective C"等等......
我最初使用以下搜索范围:
pg_search_scope :search,
against: [:bio],
using: {tsearch: {dictionary: "english", prefix: true}},
associated_against: {user: [:fname, :lname], skills: :name}
Run Code Online (Sandbox Code Playgroud)
但是,如果在这种情况下搜索"C++",则会得到包含"CSS"(包括其他内容)的结果.我更改了范围以使用"简单"字典并删除了前缀:
pg_search_scope :search_without_prefix,
against: [:bio],
using: {tsearch: {dictionary: "simple"}},
associated_against: {user: [:fname, :lname], skills: :name}
Run Code Online (Sandbox Code Playgroud)
这解决了一些问题 - 例如,搜索"C++"并不显示"CSS".但是,搜索"C++"或"C#"仍然匹配列出"C"或"Objective C"的用户
我绝对可以做一个基本的ILIKE匹配,但如果可能的话,希望用pg_search完成这个.
我正在尝试构建一个使用本地运行的postgres的ruby项目.pg gem install上的构建失败.我收到这个错误
$ gem install pg -v '0.12.2'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/path/to/.rvm/rubies/ruby-1.9.3-p545/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
Run Code Online (Sandbox Code Playgroud)
所以......我传递了pg_config路径,并得到了一个不同的错误:
$ gem install pg --with-pg-config=/usr/pgsql-9.2/bin/pg_config -v '0.12.2'
ERROR: While executing gem ... (OptionParser::InvalidOption)
invalid option: --with-pg-config=/usr/pgsql-9.2/bin/pg_config
Run Code Online (Sandbox Code Playgroud)
非常困惑.
从 heroku 移动到 dokku / 数字海洋,我使用 pg_dump 将数据库复制到一个文件“latest.dump”中,并使用 pg_restore 到我的本地 pg db 并且它正常工作。但是,当我尝试运行 dokku postegresql:restore 命令时,它会运行并且我收到“数据库已恢复”但有很多错误并且实际上没有任何数据被恢复。有关如何排除故障/导致错误的原因的任何建议?
root@domain:~# dokku postgresql:restore db_name < dokku/db/latest.dump
ERROR: syntax error at or near "PGDMP"
LINE 1: PGDMP
id integer NOT NULL,
^
ERROR: syntax error at or near ""
LINE 1: START WITH 1
^
ERROR: syntax error at or near ""
LINE 1: id integer NOT NULL,
^
ERROR: syntax error at or near ""
LINE 1: START WITH 1
^
ERROR: syntax error …Run Code Online (Sandbox Code Playgroud) 我将RVM用作Ruby的版本管理并安装了Ruby 2.2.5。该捆绑软件已完全成功安装。但是,当我使用rails启动rails服务器时,它给了我“要求”:pg的库版本不兼容(LoadError)。
我尝试过多次重新安装rvm。清洗了宝石镶嵌,但问题仍然存在。
我一次又一次收到以下错误:
.rvm/gems/ruby-2.2.5/gems/pg-0.19.0/lib/pg.rb:4:in `require': incompatible library version - /home/user/.rvm/gems/ruby-2.2.5/gems/pg-0.19.0/lib/pg_ext.so (LoadError)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。