Does PostgreSQL support JDBC and ODBC connectivity using unix domain socket instead of TCP/IP connec

 

Does PostgreSQL support JDBC and ODBC connectivity using unix domain socket instead of TCP/IP connection

 SOLUTION 已验证 - 已更新 2017年十二月26日03:22 - 

English 

环境

  • Red Hat Enterprise Linux 4
  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7

问题

  • Need to connect PostgreSQL database using JDBC and ODBC driver with UNIX domain socket instead of TCP/IP connection.

决议

  • PostgreSQL supports Unix domain socket with ODBC driver but not with JDBC driver.
  • Packages need - unixODBC and postgresql-odbc

PostgreSQL with ODBC Unix domain socket configuration

Raw

# cat /etc/odbcinst.ini

[PostgreSQL]
Description = ODBC for PostgreSQL
Driver      = /usr/lib64/psqlodbc.so
Setup       = /usr/lib64/libodbcpsqlS.so
FileUsage   = 1

Note: In order to get Unix domain Socket working never use server name or port number.

Raw

# cat /etc/odbc.ini 
[postgres]
Description         = PostgreSQL connection
Driver              = PostgreSQL
Database            = postgres
UserName            = postgres
Password            = postgres
Protocol            = 9.3
ReadOnly            = No
RowVersioning       = No
ShowSystemTables    = No
ConnSettings        =

Raw

# cat /var/lib/pgsql/data/pg_hba.conf 
# "local" is for Unix domain socket connections only
local   all             all                                     trust

根源

What is Unix Domain Socket

诊断步骤

Testing

Raw

# isql postgres
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+

Raw

SQL> select * from company;
+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+---------------------------------------------------+--------------+
| id         | name                                                                                                                                                                                                                                                                                                        | age        | address                                           | salary       |
+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+---------------------------------------------------+--------------+
+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+---------------------------------------------------+--------------+
SQLRowCount returns 0

SQL> quit

TCPDUMP CAPTURE

No packets captured on port 5432

Raw

# tcpdump -i any port 5432 -nnnvvvSex
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值