Configuring PostgreSQL ODBC connector

  1. apt-get install unixodbc odbc-postgresql

  2. Add the following line into /etc/odbcinst.ini

    [Postgres]
    Description             = Postgres
    Driver          = /usr/lib/odbc/psqlodbc.so
    Driver64                = /usr/lib
    Setup           = /usr/lib/odbc/libodbcpsqlS.so
    Setup64         = /usr/lib
    UsageCount              = 1
    CPTimeout               =
    CPReuse         =
    
  3. Add the following DSN into /etc/odbc.ini

    [test]
    Description   = test
    Driver    = Postgres
    Trace   = No
    TraceFile   =
    Database    = test
    Servername    = localhost
    Username    =
    Password    =
    Port    = 5432
    Protocol    = 6.4
    ReadOnly    = No
    RowVersioning   = No
    ShowSystemTables    = No
    ShowOidColumn   = No
    FakeOidIndex    = No
    ConnSettings    =
    

NOTE that the hostname is called servername here! If you use a standard hostname, the driver will connect to a socket, not the inet and you get a “connection refused” message.

  1. The DNS-less connection string to PostgreSQL (don’t need step 3 then) would be: "Driver=Postgres;Database=test;Servername=localhost;Port=5432;Username=test;Password=xxxx;"

NOTE: It’s error-prone and hell to debug.

  1. Driver should not be in curly braces {} (should be according to the spec).
  2. Absolutely no spaces anywhere (should be ok according to the spec).
  3. Error messages are not very informative as it fails silently and calls another connection methos producing “Data source name not found, and no default driver specified” :-|

A useless pointer: DSN-less connection strings – discussed here.

Leave a Reply