无法在MonetDB.R中设置与本地数据库的连接

时间:2014-01-27 14:32:44

标签: r monetdb

标题总结了我的问题,我想。我很感激任何人可能会对我还能尝试的其他任何指示。我已粘贴控制台输出,下面以粗体显示注释。 MonetDB.R的安装版本是R-forge(0.8.5)的最新版本。

fabians@wap27:~$ R

[...]

> library(MonetDB.R)   
Loading required package: DBI
Loading required package: digest

Attaching package: ‘MonetDB.R’

The following objects are masked from ‘package:stats’:

    sd, var

The following objects are masked from ‘package:base’:

    sample, tabulate

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] MonetDB.R_0.8.5 digest_0.6.3    DBI_0.2-7      
> 
> # as @ https://github.com/ajdamico/usgsd/tree/master/MonetDB:
> batfile <- monetdb.server.setup(
+         database.directory = "~/monetdb",
+         monetdb.program.path = "/usr",
+         dbname = "test",
+         dbport = 50000L)
/home/fabians/monetdb did not exist.  now it does

似乎有效......

>
> batfile <- "/home/fabians/monetdb/test.sh"

> system(paste("cat ", batfile))
#!/bin/sh
/usr/bin/mserver5 --set prefix=/usr --set exec_prefix=/usr --dbpath /home/fabians/monetdb/test --set mapi_port=50000 --daemon yes > /dev/null &
echo $! > /home/fabians/monetdb/mserver5.started.from.R.pid

有人能告诉我这个shell脚本是否应该是这样的吗?

> system(paste("ls ~/monetdb"))
test  test.sh

好的,所以创建了一个(空)'test'目录和.sh

> monetpid <- monetdb.server.start(batfile)
Read 1 item
> system(paste("ls ~/monetdb/test"))
00e3bc31-ca59-43e6-ace8-a96aac37bddd  bat  box

现在启动monetdb服务器后,测试目录包含数据库信息,我猜?

> dbname <- "test"
> dbport <- 50000L
> monet.url <- paste0("monetdb://localhost/", dbname)
> db <- dbConnect( MonetDB.R(), monet.url, 
+                  port=as.integer(dbport), timeout=as.integer(86400))
Error in .monetAuthenticate(socket, dbname, user, password) : 
  Authentication error: !monetdbd: no such database 'test', please create it first

找不到测试目录的原因是什么?

略有不同的命令,如monetdb.server.start的帮助以及https://github.com/ajdamico/usgsd/tree/master/MonetDB的帮助:

> monet.url <- paste0("monetdb://localhost:", dbport, "/", dbname)
> db <- dbConnect( MonetDB.R(), monet.url, wait = TRUE )
R: mapi.c:72: mapiConnect: Assertion `Rf_isInteger(port)' failed.
Aborted

此错误应该已修复,请参阅here ...

1 个答案:

答案 0 :(得分:2)

错误的原因是你的monetdbd仍在端口50000上运行,这就是monetdb.server.start生成的mserver5进程无法绑定到它的原因。因此,要么在monetdb.server.setup中选择一个不同的端口(例如50001),要么在调用monetdb.server.start之前终止monetdbd。也许我们可以在monetdb.server.setup中添加一个检查,以确保没有进程正在侦听指定的端口......