当前正在运行 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/ 以了解为什么该服务在登录时启动但到目前为止没有运气。有人对我接下来应该检查的地方有任何想法吗?在活动监视器中强制退出也没有帮助我。
我正在使用Ruby(而不是Rails)并连接PostgreSQL数据库.我一直试图在Heroku上设置,但是我在启动应用程序时遇到了问题.在本地运行应用程序正常.
我的本地.env看起来像:
postgres://DATABASE_URL=localhost
Run Code Online (Sandbox Code Playgroud)
并且连接到数据库的Ruby连接如下所示:
@@db = PGconn.open(:hostaddr => ENV['DATABASE_URL'], :dbname => '(dbname)', :password => '(password)')
Run Code Online (Sandbox Code Playgroud)
当我推送到Heroku时,应用程序在该行崩溃,并将此错误写入日志:
could not translate host name "postgres://(my heroku db address)" to address: Name or service not known (PG::Error)
Run Code Online (Sandbox Code Playgroud)
那里的数据库地址与DATABASE_URL我的匹配heroku:config.我正在使用共享数据库.
我尝试使用:host => ENV['DATABASE_URL'](而不是:hostaddr),但结果相同.我猜我有一些简单的东西,但是我没有任何好的想法.
我正在使用Heroku推荐的pg:transfer实用程序来推送和提取数据库.例如:
heroku pg:transfer -f postgres://username:password@localhost/database-name -t postgres://user-name:password@host-name/database-name --confirm app-name
Run Code Online (Sandbox Code Playgroud)
我已经能够成功地完成它,但每次它都表明在传输结束时忽略了错误:
WARNING: errors ignored on restore: 59
Run Code Online (Sandbox Code Playgroud)
我需要担心吗?
编辑:
我经历了我的输出,似乎每张桌子都出错了.它似乎丢弃序列,然后抛出一个错误,说它不存在.
pg_restore: dropping SEQUENCE OWNED BY roles_id_seq
pg_restore: dropping SEQUENCE roles_id_seq
pg_restore: [archiver (db)] Error from TOC entry 170; 1259 35485 SEQUENCE roles_id_seq postgres
pg_restore: [archiver (db)] could not execute query: ERROR: sequence "roles_id_seq" does not exist Command was: DROP SEQUENCE public.roles_id_seq;
Run Code Online (Sandbox Code Playgroud) 有没有办法配置database.yml文件远程连接到Heroku的Postgres?
我无法理解Heroku,Rails和PG gem如何协同工作.
看起来在部署期间,Heroku重写了database.yml文件 - 是否可以查看此更新的.yml文件的内容并在本地使用它?
我目前正在参加一个数据库课程,其中一个实验室问题让我难以理解如何实现上述内容,实际上,如果有可能的话.我试过搜索文档但是定义的事务方法很模糊.
这是我第一次尝试进行任何数据库操作而没有Rails的舒适毯,所以我有点迷失.我已经设法创建了一个与postgresql数据库的连接并且可以执行语句,我需要做的最后一件事就是根据一个简单的条件回滚一个事务.
请允许我向您展示代码:
require 'pg'
@conn = PG::Connection.open(:dbname => 'db_15_11_labs')
@conn.prepare('insert', 'INSERT INTO house (housenumber, street) VALUES ($1, $2) returning id')
@words = ["Foo", "Bar", "Bash", "Bang"]
def populate
100.times.each_with_index do |i|
# cycle through the @words array for street names, use i as house number
ins = @conn.exec_prepared('insert', [i, "#{@words1[i % 4]} street"])
end
end
Run Code Online (Sandbox Code Playgroud)
基本上,条件是如果返回的id(ins[0]['id'])是偶数,则回滚事务.我想如果ins[0]['id'] % 2 == 0我需要抛出某种异常,但我该如何做,更重要的是,如何将这些信息编码到文档中给出的语法中?
感谢您的时间.
编辑1
我现在设法获得了允许条件放在定义的事务中的语法,如下所示:
@conn.transaction do |conn|
ins = @conn.exec_prepared('insert', [i, "#{@words1[i …Run Code Online (Sandbox Code Playgroud) 我在我的MacOS X上安装了RubyOnRails 4.1.4和PostgreSQL:
brew install postgresql
Run Code Online (Sandbox Code Playgroud)
当我尝试迁移这个时:
CREATE EXTENSION hstore
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误:
PG::UndefinedFile: ERROR: could not open extension control file "/usr/share/postgresql/9.3/extension/hstore.control": No such file or directory
Run Code Online (Sandbox Code Playgroud)
我试图在文件系统中找到"hstore.control"使用:
find / -name "hstore.control"
Run Code Online (Sandbox Code Playgroud)
并发现该文件位于不同的路径:
usr/local/Cellar/postgresql/9.3.4/share/postgresql/extension/hstore.control
Run Code Online (Sandbox Code Playgroud)
那么如何重新定义"PG"gem的配置以纠正hstore扩展的路径?我只是试图删除宝石并安装它:
rvm all do gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
Run Code Online (Sandbox Code Playgroud)
但它没有用.我仍然有同样的错误.
先感谢您.
更新:
我刚刚创建了符号链接以纠正路径,但无论如何它给了我同样的错误.
我有一个系统,我们执行大量的插入和更新查询(也有一些upsert)
我看到我的日志偶尔会出现错误.
PG::ObjectNotInPrerequisiteState: ERROR: attempted to delete invisible tuple
INSERT INTO call_records(plain_crn,efd,acd,slt,slr,ror,raw_processing_data,parsed_json,timestamp,active,created_at,updated_at) VALUES (9873,2016030233,'R',0,0,'PKC01','\x02000086000181f9000101007 ... ')
Run Code Online (Sandbox Code Playgroud)
即使没有执行(删除)查询(上面的错误出现在insert子句中),我仍然无法理解但是引发了错误.
我一直在谷歌搜索这个问题,但没有确凿的证据表明为什么会这样.
database=# select version();
version
--------------------------------------------------------------------------------------------------------------
PostgreSQL 9.5.2 on x86_64-apple-darwin14.5.0, compiled by Apple LLVM version 7.0.0 (clang-700.1.76), 64-bit
(1 row)
Run Code Online (Sandbox Code Playgroud)
任何线索?
我正在尝试使用 node.js npm 包创建 PostgreSQL 准备好的语句pg。但是,我不断收到错误:
无法确定参数 $1 的数据类型
function promiseQuery(sql, values) {
return new Promise(function(resolve, reject) {
pool.query('select $1 from workers', ['name'], function(err, result) {
if (err) {console.log(err); reject(err)}
else resolve(result.rows);
})
});
}
Run Code Online (Sandbox Code Playgroud)
在数据库中,该name字段设置为 type text not null。
我也尝试了pg-promise,但也没有成功。
我有一个生产服务器运行ubuntu 14.04, Rails 4.2.0, postgresql 9.6.1gem pg 0.21.0/0.20.0。在过去的几天里,有不断的错误与访问的表customer_input_datax_records在psql server。
D, [2017-07-20T18:08:39.166897 #1244] DEBUG -- : CustomerInputDatax::Record Load (0.1ms) SELECT "customer_input_datax_records".* FROM "customer_input_datax_records" WHERE ("customer_input_datax_records"."status" != $1) [["status", "email_sent"]]
E, [2017-07-20T18:08:39.166990 #1244] ERROR -- : PG::UnableToSend: no connection to the server
: SELECT "customer_input_datax_records".* FROM "customer_input_datax_records" WHERE ("customer_input_datax_records"."status" != $1)
Run Code Online (Sandbox Code Playgroud)
调用访问数据库服务器的代码是Rufus scheduler 3.4.2循环的:
s = Rufus::Scheduler.singleton
s.every '2m' do
new_signups = CustomerInputDatax::Record.where.not(:status => 'email_sent').all
.......
end
Run Code Online (Sandbox Code Playgroud)
重启服务器后,通常会有第一个请求(或几个)。但是一段时间后(例如 1 或 2 …
我使用 pg_dump 和 pg_restore 对数据库进行每日备份,这些备份在我推送更新后最近停止工作。
我有一个函数validate_id,它是一个Case/When语句,可以快速检查一些存在完整性问题的数据。看起来像这样:
CREATE OR REPLACE FUNCTION validate_id(
_string text,
_type type
) RETURNS boolean AS
$$
SELECT
CASE WHEN (stuff) THEN TRUE
WHEN (other stuff) THEN TRUE
When (more stuff) THEN raise_err('Not an accepted type, the accepted types are: x y z')
ELSE FALSE
$$
LANGUAGE SQL;
Run Code Online (Sandbox Code Playgroud)
由于我添加了此功能,当我使用此命令转储时:
pg_dump -U postgres -h ipaddress -p 5432 -w -F t databaseName > backupsfolder/databaseName.tar
当我使用这个命令时:
pg_restore -U postgres -h localhost -p 5432 -d postgres -C …
pg ×10
postgresql ×10
heroku ×3
ruby ×3
hstore ×1
javascript ×1
launchctl ×1
macos ×1
node.js ×1
pg-dump ×1
pg-promise ×1
pg-restore ×1
rvm ×1
transactions ×1