如何处理瀚高数据库与PG的冲突
文章目录
- 环境
- 症状
- 问题原因
- 解决方案
- 相关文档
- 报错编码
环境
系统平台:N/A
版本:4.5,4.5.8
症状
当服务器上同时部署PostgreSQL数据库与瀚高数据库时,可能会出现以下几种常见问题:
1. 使用psql登录HGDB时出现如下报错
[root@localhost ~]# psql
psql: could not connect to server: No such file or directoryIs the server running locally and acceptingconnections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
以上情况,发现psql默认访问的socket文件在/var/run/postgresql/下,可能有如下原因:
1、使用了错误的psql工具
2、使用了错误的 libpq.so
对于HGDB安全版4.5和企业版6,psql工具默认会访问位于/tmp/下的socket文件。
2. pg_ctl start 时提示cannot be run as root无法启动
[root@localhost ~]# pg_ctl start
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
该问题通常是由于PGDATA和PATH路径配置不正确,调用了其他pg的可执行文件
3. 出现其他和数据库版本或libpq版本等相关的报错
psql: symbol lookup error: psql: undefined symbol: PQkernelVersion
通常和libpq文件有关,配置LD_LIBRARY_PATH可解决
问题原因
瀚高数据库引进了国际上最先进的开源数据库PostgreSQL内核技术,在此PostgreSQL社区版之上做了一系列的研发和优化。当服务器上同时部署PostgreSQL数据库与瀚高数据库时,可能存在数据库命令冲突、误操作等情况。
解决方案
当psql无法正常进入数据库时,请按照如下步骤排查:
1. 确认当前服务器中HGDB进程正在运行
[root@localhost ~]# ps -ef |grep postg
root 1207 1 0 06:10 ? 00:00:00 /opt/highgo/hgdb-see-4.5.8/bin/postgres <-----可以看到存在HGDB主进程,是从HGDB安装路径中执行,且主进程正常派生出多个HGDB后台进程
root 1372 1207 0 06:10 ? 00:00:00 postgres: logger
root 1382 1207 0 06:10 ? 00:00:00 postgres: checkpointer
root 1383 1207 0 06:10 ? 00:00:00 postgres: background writer
root 1384 1207 0 06:10 ? 00:00:00 postgres: walwriter
root 1385 1207 0 06:10 ? 00:00:00 postgres: autovacuum launcher
root 1386 1207 0 06:10 ? 00:00:00 postgres: archiver last was 0000000100000000000000BE
root 1387 1207 0 06:10 ? 00:00:00 postgres: stats collector
root 1388 1207 0 06:10 ? 00:00:00 postgres: logical replication launcher
假如无HGDB进程,则检查下面两步骤后,尝试pg_ctl启动HGDB
2. 检查数据库相关命令是否为HGDB自带工具
使用which命令,确保命令行中调起的psql或其他命令为HGDB自带工具
[root@localhost ~]# which psql
/opt/highgo/hgdb-see-4.5.8/bin/psql #路径在HGDB安装目录下
3. 检查环境变量配置
使用ENV命令,确认当前shell环境变量指向HGDB的相关路径
[root@localhost ~]# env |grep -E 'PG|LD|HG|PATH'
LD_LIBRARY_PATH=/opt/highgo/hgdb-see-4.5.8/lib #LD_LIBRARY_PATH在正常情况下无需配置,但是当psql无法进入数据库或无法启动时,可以尝试配置该参数指向HGDB安装目录下的lib目录
PGPORT=5866
PGDATABASE=highgo
PATH=/opt/highgo/hgdb-see-4.5.8/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin #HGDB的可执行文件路径应该在PATH最前方,可以使用which命令再次确认
HGDB_HOME=/opt/highgo/hgdb-see-4.5.8
PGDATA=/opt/highgo/hgdb-see-4.5.8/data #该路径指向HGDB的数据文件目录
HG_BASE=/opt/highgo
正常情况下,配置好PATH、LD_LIBRARY_PATH、PGDATA这三个变量,即可使用psql正常连接到HGDB的psql命令行下,并能够通过pg_ctl控制数据库服务的启停。
示例:
export PATH=/opt/highgo/hgdb-see-4.5.8/bin:$PATH
export LD_LIBRARY_PATH=/opt/highgo/hgdb-see-4.5.8/lib
export PGDATA=/data/highgo/data
请根据实际情况的安装路径配置如上参数,问题通常即可解决。 若要使其永久生效,可以在经过评估后,将其添加到~/.bashrc文件中,