libpqxx接口的在linux下的使用,解决psql:connections on Unix domain socket "/tmp/.s.PGSQL.5432"错误
在项目中使用postgresql数据库时要求在windows和linux双平台兼容。于是在windows下使用的接口在linux下爆出异常:
psql:connections on Unix domain socket "/tmp/.s.PGSQL.5432"
经过分析和查看文档解决了这个问题:
1.原因:这是由于在linux下连接pg时使用了默认的unix domain socket方式连接pg时出现的,并且pg的端口运行在非默认端口上(默认端口是5432)。在windows下同样的接口使用了socket的TCP协议连接pg的。
2.在使用pgxx::connection("")时,要传入的字符串不完整,导致了在linux下使用了unix domain socket方式连接。
以下是postgresql官方文档解释:
host
Name of host to connect to. If a host name begins with a slash, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. If multiple host names are specified, each will be tried in turn in the order given. The default behavior when A comma-separated list of host names is also accepted, in which case each host name in the list is tried in order.
Numeric IP address of host to connect to. This should be in the standard IPv4 address format, e.g., Using
Note that authentication is likely to fail if A comma-separated list of Without either a host name or host address, libpq will connect using a local Unix-domain socket; or on machines without Unix-domain sockets, it will attempt to connect to |
因此,我们的接口主要发生了2件错误:
1.std::string strConnection在windows下使用strConnection = "dbname="+pg_dbname+" user="+pg_username+" password="时,string的拼接出现问题。所以再拼接string字符串时使用
std::string strConnection = "dbname=";
strConnection += pg_dbname.c_str();
strConnection += " user=";
strConnection += pg_username.c_str();
strConnection += " password=";
strConnection += pg_password.c_str();
strConnection += " hostaddr=";
strConnection += pg_ip.c_str();
strConnection += " port=";
strConnection += pg_port.c_str();
2.在strConnection字符串中最好加上host=localhost的配置,这样可以确保没有问题。
libpqxx接口的在linux下的使用,解决psql:connections on Unix domain socket "/tmp/.s.PGSQL.5432"错误的更多相关文章
- 由一个简单需求到Linux环境下的syslog、unix domain socket
本文记录了因为一个简单的日志需求,继而对linux环境下syslog.rsyslog.unix domain socket的学习.本文关注使用层面,并不涉及rsyslog的实现原理,感兴趣的读者可以参 ...
- Linux下的IPC-UNIX Domain Socket【转】
本文转载自:http://blog.csdn.net/guxch/article/details/7041052 一. 概述 UNIX Domain Socket是在socket架构上发展起来的用于同 ...
- linux一切皆文件之Unix domain socket描述符(二)
一.知识准备 1.在linux中,一切皆为文件,所有不同种类的类型都被抽象成文件(比如:块设备,socket套接字,pipe队列) 2.操作这些不同的类型就像操作文件一样,比如增删改查等 3.主要用于 ...
- hadoop学习;大数据集在HDFS中存为单个文件;安装linux下eclipse出错解决;查看.class文件插件
sudo apt-get install eclipse 安装后打开eclipse,提示出错 An error has occurred. See the log file /home/pengeor ...
- linux下开发,解决cocos2d-x中编译出现的一个小问题, undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
解决cocos2d-x中编译出现的一个小问题 对于cocos2d-x 2.×中编译中,若头文件里引入了#include "cocos-ext.h",在进行C++编译的时候会遇到例如 ...
- linux下关于PCL(point cloud library)库的安装,三行命令错误的问题
最近想再看看PCL,所以进行了安装,在之前的接触的过程中,由于之前的网络存在问题,导致以下三个命令: sudo add-apt-repository ppa:v-launchpad-jochen-sp ...
- 图形报表部署在Linux下出现乱码解决办法
客户问题: 客户的操作系统SUSE LINUX Enterprise Server 10 (i586) 64位,服务器 weblogic8.1, JDK版本:jdk1.4.系统中只有图形报表展示 ...
- linux下log4j乱码解决
使用log4j的时候,在WIN系统的时候正常显示中文,但是发布到linux系统的时候中文就显示成乱码了 由于log4j配置文件中没有设置编码格式(encoding),所以log4j就使用系统默认编码. ...
- linux下安装mysql解决乱码、时间差、表的大小写问题
编辑vi /etc/mysql/my.cnf,有的则是:/etc/my.cnf,加入 [client]default-character-set=utf8mb4 [mysql]default-char ...
随机推荐
- Nginx拦截算法
Nginx流量拦截算法 nginx 夏日小草 2015年10月22日发布 | 1 收藏 | 40 4.2k 次浏览 0x00.About 电商平台营销时候,经常会碰到的大流量问题,除了做流量分 ...
- 关于HTTP,你知道哪些?
HTTP简介 HTTP 的全称是 Hypertext Transfer Protocol,超文本传输协议 规定客户端和服务器之间的数据传输格式 让客户端和服务器能有效地进行数据沟通 HTTP 协议是网 ...
- 02 浅析Spring的AOP(面向切面编程)
1.关于AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.O ...
- C# 如何使用预处理指令?
#define Debug #define Release #undef Release #if Debug using System; #endif 注意:#define 必须在文档最前面
- Google 浏览器被劫持怎么办?
chrome://version/ 输入以上语句,在命令行中可看到恶意网址,复制该命令行,修改后面的网址即可
- AWS EC2 通过Linux终端:使用ssh连接到Linux实例
AWS的ubuntu主机登录用户是ubuntu 只能通过秘钥的方式登录 如果在linux终端通过ssh远程登录步骤如下: 假如申请EC2主机的时候下载的key名称叫my-key.pem,并保存在本地l ...
- 使用BEM命名规范来组织CSS代码
BEM 是 Block(块) Element(元素) Modifier(修饰器)的简称 使用BEM规范来命名CSS,组织HTML中选择器的结构,利于CSS代码的维护,使得代码结构更清晰(弊端主要是名字 ...
- USB OTG简介、与普通USB线的区别
USB有三类接口A类接口 -----------最常见的扁平接口,四芯 VCC GND D+ D- B类接口 ...
- 超链接a标签的属性target的可选值有哪些以及区别
超链接a标签的属性target的可选值有哪些以及区别 1.<a target="_blank"></a> 2.<a target="_par ...
- box-sizing -- 盒模型
项目开发中,在浏览同事的代码,发现他经常用一个属性--box-sizing,很好奇是什么,于是乎,上网查阅资料学了起来. 首先我们先复习一下盒模型的组成:一个div通常由 content(内容)+ma ...