在postgresql 8.1升级到9.0之后,我发现了库依赖的问题.Postgresql工作正常(连接,查询).
yum list postgresql*
Installed Packages
postgresql.i386 9.0.0-1PGDG.el5 installed
postgresql-debuginfo.i386 9.0.0-1PGDG.el5 installed
postgresql-devel.i386 9.0.0-1PGDG.el5 installed
postgresql-libs.i386 9.0.0-1PGDG.el5 installed
postgresql-odbcng.i386 0.90.101-2.el5 installed
postgresql-plruby.i386 0.5.1-5.el5 installed
postgresql-server.i386 9.0.0-1PGDG.el5 install
Run Code Online (Sandbox Code Playgroud)
但当我试图为红宝石安装'pg'时,我收到了
gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for pg_config... no
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PostgreSQL本地开发Ruby on Rails,所以我正在尝试安装pg gem.在Ubuntu 12.04上.在终端,我输入:
gem install pg -v '0.12.2'
Run Code Online (Sandbox Code Playgroud)
这会引发以下错误:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/troyshu/.rvm/rubies/ruby-1.9.3-p194/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
Can't find the PostgreSQL client library (libpq)
*** extconf.rb …Run Code Online (Sandbox Code Playgroud) 运行
gem install pg -v '0.15.1'
Run Code Online (Sandbox Code Playgroud)
给出错误:
构建原生扩展.这可能需要一段时间...错误:安装pg时出错:错误:无法构建gem原生扩展.
Run Code Online (Sandbox Code Playgroud)/home/askar/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If构建失败,请再次尝试使用--with -pg-config =/path/to/pg_config检查libpq-fe.h ...否找不到'libpq-fe.h header *extconf.rb失败*由于某些原因无法创建Makefile,可能缺少必要的库和/或标头.检查mkmf.log文件以获取更多详细信息.您可能需要配置选项.
提供的配置选项: - with-opt-dir --without-opt-dir --with-opt-include --without-opt-include = $ {opt-dir}/include --with-opt-lib - without-opt-lib = $ {opt-dir}/lib --with-make-prog --without-make-prog --srcdir =.--curdir --ruby =/home/askar/.rvm/rubies/ruby-1.9.3-p429/bin/ruby --with-pg --without-pg --with-pg-dir --without-pg -dir --with-pg-include --without-pg-include = $ {pg-dir}/include --with-pg-lib --without-pg-lib = $ {pg-dir}/lib - with-pg-config --without-pg-config --with-pg_config --without-pg_config
Gem文件将保留在/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/pg-0.15.1中进行检查.结果登录到/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/pg-0.15.1/ext/gem_make.out
我正在使用
我试图安装pg gem,我有这个警告:
您需要安装postgresql-server-dev-XY来构建服务器端扩展,或者安装libpq-dev来构建客户端应用程序.
所以我尝试安装libpq-dev包,我有这个警告:
libpq-dev:取决于:libpq5(= 8.4.17-0squeeze1)但是要安装9.1.9-1~bpo60 + 1
如何解决这个问题?
我试过按照这个答案让宝石工作,但它不会.我的项目设置使得个人项目有自己的宝石而不是生活在全球空间的所有主题宝石,然后我用binstubs它来做我喜欢的事情bin/rails.
因此,.bundle/gems/为每个项目安装所有宝石.总是给我最棘手的问题的是posgresql.让我们完成这些步骤.
所以我跑:
bundle
它爆炸说:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/Versions/9.3/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
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack …Run Code Online (Sandbox Code Playgroud) 每当我运行bundle install我的VPS(CentOS Linux版本7.0.1406(Core))时,我在安装pg gem时出错.
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Run Code Online (Sandbox Code Playgroud)
我可以用:安装pg standalone,gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config问题解决了.
所以我添加了一个capistrano任务来为部署创建一个./bundle/config,其中build.pg键设置为我的VPS上的pg_config路径.在Capistrano config/deploy.rb这被调用before bundler:install.
desc "Create bundle config"
task :prepare_bundle_config do
on …Run Code Online (Sandbox Code Playgroud) 我试图在Mac El Capitan上安装pg Gem,但我总是遇到这个错误:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/Users/ricardolopes/Developer/homebrew/bin/pg_config
Using config values from /Users/ricardolopes/Developer/homebrew/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
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file … 当前正在运行 postgreSQL 9.4.5_2
我试过了
pg_ctl stop -W -t 1 -s -D /usr/local/var/postgres -m f
Run Code Online (Sandbox Code Playgroud)
通常没有消息是好消息,但我会跑后
pg_ctl status -D /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)
并得到 pg_ctl: server is running (PID: 536)
我也试过
pg_ctl restart -w -D /usr/local/var/postgres -c -m i
Run Code Online (Sandbox Code Playgroud)
响应消息是:
waiting for server to shut down.......................... failed
pg_ctl: server does not shut down
Run Code Online (Sandbox Code Playgroud)
我还检查了我的 /Library/LaunchDaemons/ 以了解为什么该服务在登录时启动但到目前为止没有运气。有人对我接下来应该检查的地方有任何想法吗?在活动监视器中强制退出也没有帮助我。
我有一个rails app(4.1.5)由postgres数据库(9.2.13)支持使用pg gem(0.17.1),unicorn服务器(1.1.0)和2个工作进程.
rails app使用sidekiq(2.17.7)运行作业
在某些时候,postgres db进入恢复模式.多个作业抛出以下错误:
PG::ConnectionBad:FATAL: the database system is in recovery mode
FATAL: the database system is in recovery mode
Run Code Online (Sandbox Code Playgroud)
数据库恢复了,但作业继续引发以下两个错误:
PG::Error:invalid encoding name: utf8
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:908:in `set_client_encoding'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:908:in `configure_connection'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:603:in `reconnect!'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract_adapter.rb:313:in `verify!'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:453:in `block in checkout_and_verify'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:82:in `run_callbacks'
Run Code Online (Sandbox Code Playgroud)
和
ActiveRecord::ConnectionTimeoutError:could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `block in wait_poll'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `loop'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `wait_poll'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:136:in `block in poll'
/home/ruby/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:146:in `synchronize'
/home/ruby/data42/shared/bundle/ruby/2.2.0/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:134:in `poll'
Run Code Online (Sandbox Code Playgroud)
它看起来像rails通知连接未激活并尝试重置连接.在活动记录的postgresql_adapter.rb中,调用以下方法:
# Close then reopen the connection. …Run Code Online (Sandbox Code Playgroud) 如果可以动态确定名称并且仍然阻止SQL注入攻击,那么如何正确提供表名?
例如:
以下作品,但我认为是不安全的:
dbclient.query("INSERT INTO " + table_name + " VALUES ($1, $2, $3)", [value_a, value_b, value_c])
我想等同于(但不起作用)的是:
dbclient.query("INSERT INTO $1 VALUES ($2, $3, $4)", [table_name, value_a, value_b, value_c])
编辑:我正在使用node-postgres:https://github.com/brianc/node-postgres.