当前位置:Linux教程 - Linux - 通过ODBC连接Postgresql

通过ODBC连接Postgresql

通过ODBC连接Postgresql


适用于:

RedHat/SuSE Linux: Version 6.x

Applix: Version 5.0

Postgresql: Version 6.5.3


以下的安装的大纲是安装Postgresql在RedHat或者SuSE Linux所必须的. 为了更新Postgresql和更一步的参考资料,请访问www.postgresql.org . 为了完整考虑, 这个文挡解释怎样编译原始资料Applixware安装在 /opt/applix Postgresql 安装在/usr/local/Postgresql 。 你用""root""用户登陆:


1. 下载Postgresql

A.""ftp://ftp.postgresql.org/pub/""

B. 下载并保存为""postgresql-6.5.3.tar.gz""到你的home目录

2. 分发安装Postgresql

A. 创建一个用户''postgres'' 和一个组''postgres'' 如果他们都不存在于你的系统中. 这个用户''postgres''的home目录是 /var/lib/pgsql.

B. 把下载的文件移到 /var/lib/pgsql

C. 检查flex 和Postgres之间的兼容性:

$ flex --version

如果flex命令没有找到,你就可能不需要它. 如果版本是2.5.2 or 2.5.4 或者更大. 如果是2.5.3 在2.5.2之前,你将也需要升级 flex. 从这里可以下载ftp://prep.ai.mit.edu/pub/gnu/flex-2.5.4.tar.gz.


D. 创建新得安装目录


$ su

$ cd /usr/src

$ mkdir pgsql

$ chown postgres:postgres pgsql

$ cd /usr/local

$ mkdir pgsql

$ chown postgres:postgres pgsql

$ exit


E. 解压安装文件

$ cd /usr/src/pgsql

$ gunzip -c ~/postgresql-v6.5.3.tar.gz | tar xvf -


F. 配置 /usr/local/pgsql:

$ cd /usr/src/pgsql/posgresql-6.5.3/src

$ ./configure --prefix=/usr/local/pgsql --with-odbc


G. 安装 man 和 HTML 文件. 类型

$ cd /usr/src/pgsql/posgresql-6.5.3/doc

$ make install


H.编译release:

$ cd /usr/src/pgsql/src

$ make all > make.log 2>&1 &

$ tail -f make.log

日志最后一行表明: 所有PostgreSQL就绪. 准备安装.


I. 安装Postgresql:

$ gmake install > make.install.log 2>&1 &

$ tail -f make.install.log

最后一行解释为: 谢谢你使用Postgresql


J. 告诉你系统怎样找到新的共享的库

1. 作为root,编辑文件 /etc/ld.so.conf. 加入一行

/usr/local/pgsql/lib

2. 运行

$ /sbin/ldconfig


K. 增加路径至.bash_profile为你和 ''postgres''用户

PATH=$PATH:/usr/local/pgsql/bin

MANPATH=$MANPATH:/usr/local/pgsql/man

PGLIB=/usr/local/pgsql/lib

PGDATA=/usr/local/pgsql/data

export PATH MANPATH PGLIB PGDATA


确信你完整的定义了这些变量:

$ source ~/.bash_profile


3. 快速安装 Postgresql测试

A. 以用户 ''postgres''创建一个数据库:

$ su postgres

$ initdb


B. 设置许可的数据库通道

这一步要编辑文件 /usr/local/pgsql/data/pg_hba.conf. 这个文件的默认设置已经足够测试:

# By default, allow anything over UNIX domain sockets and localhost.

local all trust

host all 127.0.0.1 255.255.255.255 trust


C. 键入命令在后台运行postmaster daemon

$ cd

$ nohup postmaster -i > pgserver.log 2>&1 &


D. 创建一个库

$ createdb

E. 连接新的数据库

$ psql

F. 运行简单的请求

postgres SELECT datetime ''now'';

G. 退出psql

postgres=> q

H. 增加postgres用户

$ su - postgres

$ createuser michele

Enter user''s postgres ID or RETURN to use unix user ID: 500 ->

Is user ""tester"" allowed to create databases (y/n) y

Is user ""tester"" a superuser? (y/n) y

createuser: tester was successfully added


I. 给用户增加一个数据库

$ su -

$ createdb


4. 配置Applixware

A. 编辑 /opt/applix/axdata/axnet.cnf 文件,增加下几行 :

libFor gsqlodbc /opt/applix/axdata/axshlib/


注意: 在applixware 5.0或更高的版本中这个步骤取消


B. 增加""axnet"" 到 /etc/services

axnet 5492/tcp # Applix comms process


C. 在后台启动Applix axnet程序:

$ /opt/applix/axdata/axnet &


D. 接着创建"".odbc.ini""文件,在用户home目录下:

[ODBC Data Sources]

Postgresql=Postgresql database


[Postgresql]

Driver=/usr/local/pgsql/lib/libpsqlodbc.so

Database=michele

Server=localhost

Port=5432

ReadOnly=0


[ODBC]

Trace=1

TraceFile=/tmp/odbctrace.out

InstallDir=/opt/applix/axdata/axshlib


注意: 在Applixware 5.0 包含一个 postgresql 驱动程序叫做 libodbcpsql.so 在/axdata/axshlib. 如果你想用在axnet.cnf中的ODBCINI变量你就必须要用这个驱动。


E. 启动 Applix Data 连接Postgresql

1. Start Applix Data

2. Select Query->Choose Server

3. Select the ShelfSQL tab

4. Choose the gateway ""Shelf ODBC""

5. Click on ""Specify Connection Info...""

6. In the ODBC Connection dialog click on Browse and choose the ""Postgresql"" selection and click OK; this sets the ""Datasource"" field

7. Click OK in ""Choose Server"" dbox

8. Enter your username for the login and type the password to the database that you created earlier. You should see it successfully connect (It will show a status of ""Ready"" in the lower left-hand corner of the Data window)