通过 psqlODBC 连接 PostgreSQL

安装好 psqlODBC 后,键入 isql 命令显示帮助信息。

**********************************************
* unixODBC - isql                            *
**********************************************
* Syntax                                     *
*                                            *
*      isql DSN [UID [PWD]] [options]        *
*                                            *
* Options                                    *
*                                            *
* -b         batch.(no prompting etc)        *
* -dx        delimit columns with x          *
* -x0xXX     delimit columns with XX, where  *
*            x is in hex, ie 0x09 is tab     *
* -w         wrap results in an HTML table   *
* -c         column names on first row.      *
*            (only used when -d)             *
* -mn        limit column display width to n *
* -v         verbose.                        *
* -lx        set locale to x                 *
* -q         wrap char fields in dquotes     *
* -3         Use ODBC 3 calls                *
* -n         Use new line processing         *
* -e         Use SQLExecDirect not Prepare   *
* -k         Use SQLDriverConnect            *
* --version  version                         *
*                                            *
* Commands                                   *
*                                            *
* help - list tables                         *
* help table - list columns in table         *
* help help - list all help options          *
*                                            *
* Examples                                   *
*                                            *
*      isql WebDB MyID MyPWD -w < My.sql     *
*                                            *
*      Each line in My.sql must contain      *
*      exactly 1 SQL command except for the  *
*      last line which must be blank (unless *
*      -n option specified).                 *
*                                            *
* Please visit;                              *
*                                            *
*      http://www.unixodbc.org               *
*      nick@lurcher.org                      *
*      pharvey@codebydesign.com              *
**********************************************

参考 通过ODBC连接PostgreSQL和Greenplum 这篇文章,通过 /etc/odbc.ini 设置 DSN(数据来源名称),文章内的 /etc/odbcinst.ini 在源码编译安装 psqlODBC 后就有了,无需设置。这里我添加了名称为 db 的 DSN,然后试图链接时报错:

isql db
[ISQL]ERROR: Could not SQLConnect

通过 isql 的命令帮助,或者 Resolving database connection errors like this: ISQL ERROR: Could not SQLConnect 这篇文章,获悉可以加上 -v 参数打印具体错误信息。

isql -v db
[01000][unixODBC][Driver Manager]Can't open lib '/usr/lib64/psqlodbcw.so' : file not found
[ISQL]ERROR: Could not SQLConnect

原来是找不到动态库文件,默认编译安装时会把动态库文件放到 /usr/local/lib 目录下,最简单粗暴的办法 cp /usr/local/lib/* /usr/lib64/,再次链接 db 远程数据库:

isql -v db
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>

注意,isql 的退出命令是 quit,而不是 psql\q 了。

Advertisements

分类:默认目录, PostgreSQL

Tagged as:

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

w

Connecting to %s