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 ...
随机推荐
- yii2 查询构建器
Query Builder $rows = (new \yii\db\Query()) ->select(['dyn_id', 'dyn_name']) ->from('zs_dynast ...
- Windows系统上Redis的安装
Redis 安装 Window 下安装 下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你系统 ...
- 由select引发的思考
一.前言 网络编程里一个经典的问题,selec,poll和epoll的区别?这个问题刚学习编程时就接触了,当时看了材料很不明白,许多概念和思想没有体会,现在在这个阶段,再重新回头看这个问题,有一种豁然 ...
- MySQL 5.7 多主一丛同步的数据库配置(将多处数据源合并到一点)
工作需要,笔记之用.文章很长,倒一杯茶慢慢看. 数据库的应用场景颇多,如 数据库双机同步,一主多从,多主多从,多主一从等:下文记录多主一从的配置及测试. 大多数复制场景中是一主或者一主多从.这种拓扑用 ...
- 2015最新iOS学习线路图
iOS是由苹果公司开发的移动操作系统,以xcode为主要开发工具,具有简单易用的界面.令人惊叹的功能,以及超强的稳定性,已经成为iPhone.iPad 和iPod touch 的强大基础:iOS 内置 ...
- Linux CentOS安装配置MySQL数据库
没什么好说的,直接正面刚吧. 安装mysql数据库 a)下载mysql源安装包:wget http://dev.mysql.com/get/mysql57-community-release-el7- ...
- Java Web项目(Extjs)报错五
1. Java Web项目(Extjs)报错五 具体报错如下: usage: java org.apache.catalina.startup.Catalina [ -config {pathname ...
- 完美的js运动框架
//完美运动框架, 对象,json,函数function move(obj,json,funEnd){clearInterval(obj.timer);//清除定时器obj.timer= setInt ...
- VMware vSphere学习整理
知识点整理 内存选择 一般来说,每个虚拟机需要的内存在1~4GB甚至更多,还要为VMware ESXi预留一部分内存 2个6核的2U服务器配置64GB内存,4个6核或8核心的4U服务器配置128GB或 ...
- 手机端仿ios的单级联动脚本三
脚本 <script>var weekdayArr=['非公司企业法人','个体工商户','私营独资企业','私营合伙企业','有限责任公司','股份有限责任公司'];var mobile ...