.odbc.ini 文件有三个必须的段.第一个是 [ODBC Data Sources],定义了一个你希望访问的每个数据库的任意名称和描述.第二个必须的段是 Data Source Specification (数据源声明)并且每个数据库都将有一个这样的段.每个段必须用 [ODBC Data Sources] 里给出的名称标记并且必须包含下面的内容:
Driver = POSTGRESDIR/lib/libpsqlodbc.so Database=DatabaseName Servername=localhost Port=5432
小技巧:记住 Postgres 数据库名通常是单独一个词,没有任何类型的路径名称.Postgres 服务器管理对数据库的实际访问,并且你只需要在客户端声明(数据库)名称.
这里是一个 .odbc.ini 文件的例子,显示了三个数据库的访问信息:
[ODBC Data Sources] DataEntry = Read/Write Database QueryOnly = Read-only Database Test = Debugging Database Default = Postgres Stripped [DataEntry] ReadOnly = 0 Servername = localhost Database = Sales [QueryOnly] ReadOnly = 1 Servername = localhost Database = Sales [Test] Debug = 1 CommLog = 1 ReadOnly = 0 Servername = localhost Username = tgl Password = "no$way" Port = 5432 Database = test [Default] Servername = localhost Database = tgl Driver = /opt/postgres/current/lib/libpsqlodbc.so [ODBC] InstallDir = /opt/applix/axdata/axshlib