gsql连接opengauss报错

opengauss连接失败

错误信息

[og@RHEL7_DB pg_log]$ gsql
gsql: expected authentication request from server, but received v

查原因

[og@RHEL7_DB pg_log]$ gsql
gsql: expected authentication request from server, but received v
[og@RHEL7_DB pg_log]$ gsql postgres
gsql: expected authentication request from server, but received v
[og@RHEL7_DB pg_log]$ which gsql
alias gsql='gsql postgres -r'
        ~/openGauss-server/mppdb_temp_install/bin/gsql
[og@RHEL7_DB pg_log]$ cd
[og@RHEL7_DB ~]$ vi .bash_profile
[og@RHEL7_DB ~]$ vi .bashrc

#尝试重新初始化数据库
[og@RHEL7_DB ~]$ history|grep gs_initdb
   32  gs_initdb -D $HOME/ogdata --nodename=ogserver
  340  history|grep gs_initdb
[og@RHEL7_DB ~]$ pwd
/home/og
[og@RHEL7_DB ~]$ env|grep PGDATA
PGDATA=/home/og/ogdata
[og@RHEL7_DB ~]$ gs_initdb --nodename ogserver
The files belonging to this database system will be owned by user "og".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

gs_initdb: directory "/home/og/ogdata" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/home/og/ogdata" or run gs_initdb
with an argument other than "/home/og/ogdata".
#目录不为空.所以不能使用这目录. 
[og@RHEL7_DB ~]$ gs_ctl stop
[2024-05-06 12:05:42.542][12142][][gs_ctl]: gs_ctl stopped ,datadir is /home/og/ogdata
waiting for server to shut down..... done
server stopped
[og@RHEL7_DB ~]$ cd /home/og
[og@RHEL7_DB ~]$ ls
binarylibs  ogdata  openGauss-server  var.sql
[og@RHEL7_DB ~]$ cd ogdata
[og@RHEL7_DB ogdata]$ ls
asp_data         gs_profile          pg_audit      pg_hba.conf    pg_logical    pg_serial     PG_VERSION            ..
[og@RHEL7_DB ogdata]$ cd ..
[og@RHEL7_DB ~]$ mv ogdata ogdata.old
[og@RHEL7_DB ~]$ mkdir ogdata
#新建目录 并初始化成功
[og@RHEL7_DB ~]$ gs_initdb --nodename=pghost1
The files belonging to this database system will be owned by user "og".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

fixing permissions on existing directory /home/og/ogdata ... ok
creating subdirectories ... in ordinary occasionok
creating configuration files ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 1024MB
Begin init undo subsystem meta.
[INIT UNDO] Init undo subsystem meta successfully.
creating template1 database in /home/og/ogdata/base/1 ... The core dump path is an invalid directory
2024-05-06 12:06:16.489 [unknown] [unknown] localhost 140578207818112 0[0:0#0]  [BACKEND] WARNING:  macAddr is 2048/654408142, sysidentifier is 134227713/2043546630, randomNum is 2215709702
ok
initializing pg_authid ... ok
setting password ... ok
initializing dependencies ... ok
loading PL/pgSQL server-side language ... ok
creating system views ... ok
creating performance views ... ok
loading system objects  descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
initialize global configure for bucketmap length ... ok
creating information schema ... ok
loading foreign-data wrapper for distfs access ... ok
loading foreign-data wrapper for log access ... ok
loading hstore extension ... ok
loading foreign-data wrapper for MOT access ... ok
loading security plugin ... ok
update system tables ... ok
creating snapshots catalog ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run gs_initdb.

Success. You can now start the database server of single node using:

    gaussdb -D /home/og/ogdata --single_node
or
    gs_ctl start -D /home/og/ogdata -Z single_node -l logfile
#启动数据库
[og@RHEL7_DB ~]$ gs_ctl start -Z single_node
[2024-05-06 12:07:31.007][12431][][gs_ctl]: gs_ctl started,datadir is /home/og/ogdata
...
2024-05-06 12:07:31.315 [unknown] [unknown] localhost 140424689111424 0[0:0#0]  0 [BACKEND] LOG:  could not bind IPv6 socket at the 0 time: Address already in use
2024-05-06 12:07:31.315 [unknown] [unknown] localhost 140424689111424 0[0:0#0]  0 [BACKEND] HINT:  Port 5432 is used, run 'netstat -anop|grep 5432' or 'lsof -i:5432'(need root) to see who is using this port.
.2024-05-06 12:07:32.315 [unknown] [unknown] localhost 140424689111424 0[0:0#0]  0 [BACKEND] LOG:  could not bind IPv6 socket at the 1 time: Address already in use
2024-05-06 12:07:32.315 [unknown] [unknown] localhost 140424689111424 0[0:0#0]  0 [BACKEND] HINT:  Port 5432 is used, run 'netstat -anop|grep 5432' or 'lsof -i:5432'(need root) to see who is using this port.
.2024-05-06 12:07:33.316 [unknown] [unknown] localhost 140424689111424 0[0:0#0]  0 [BACKEND] LOG:  could not bind IPv6 socket at the 2 time: Address already in use
2024-05-06 12:07:33.316 [unknown] [unknown] localhost 140424689111424 0[0:0#0]  0 [BACKEND] HINT:  Port 5432 is used, run 'netstat -anop|grep 5432' or 'lsof -i:5432'(need root) to see who is using this port.
.2024-05-06 12:07:34.317 [unknown] [unknown] localhost 140424689111424 0[0:0#0]  0 [BACKEND] LOG:  could not bind IPv4 socket at the 0 time: Address already in use
[2024-05-06 12:07:38.100][12431][][gs_ctl]: stopped waiting
[2024-05-06 12:07:38.100][12431][][gs_ctl]: could not start server
Examine the log output.
#启动失败,因为端口5432被占用
[og@RHEL7_DB ~]$
[og@RHEL7_DB ~]$ netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN
#5432被使用中
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
...
TIME_WAIT
[og@RHEL7_DB ~]$ ps -ef|grep gauss
og       12471 11932  0 12:07 pts/0    00:00:00 grep --color=auto gauss
[og@RHEL7_DB ~]$ ls
binarylibs  ogdata  ogdata.old  openGauss-server  var.sql
[og@RHEL7_DB ~]$ cd ogdata
[og@RHEL7_DB ogdata]$ vi postgresql.conf
#修改postgresql.conf的端口号,为5532
[og@RHEL7_DB ogdata]$ grep ^port postgresql.conf
port = 5532                             # (change requires restart)
#重启
[og@RHEL7_DB ogdata]$ gs_ctl start
[2024-05-06 12:08:24.816][12529][][gs_ctl]: gs_ctl started,datadir is /home/og/ogdata
[2024-05-06 12:08:24.911][12529][][gs_ctl]: waiting for ..
[2024-05-06 12:08:26.472][12529][][gs_ctl]:  done
[2024-05-06 12:08:26.472][12529][][gs_ctl]: server started (/home/og/ogdata)
[og@RHEL7_DB ogdata]$
[og@RHEL7_DB ogdata]$
[og@RHEL7_DB ogdata]$ gsql
gsql: expected authentication request from server, but received v
#还是报错.
[og@RHEL7_DB ogdata]$ gsql postgres
gsql: expected authentication request from server, but received v
[og@RHEL7_DB ogdata]$ netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:5532          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:5533          0.0.0.0:*               ..
[og@RHEL7_DB ogdata]$ gs_ctl stop
[2024-05-06 12:08:45.197][12631][][gs_ctl]: gs_ctl stopped ,datadir is /home/og/ogdata
waiting for server to shut down..... done
server stopped
[og@RHEL7_DB ogdata]$ gs_ctl start -D /home/og/ogdata -Z single_node -l logfile
[2024-05-06 12:09:09.049][12661][][gs_ctl]: gs_ctl started,datadir is /home/og/ogdata
[2024-05-06 12:09:09.141][12661][][gs_ctl]: waiting for server to start...
.
[2024-05-06 12:09:10.664][12661][][gs_ctl]:  done
[2024-05-06 12:09:10.664][12661][][gs_ctl]: server started (/home/og/ogdata)
[og@RHEL7_DB ogdata]$ gsql postgres
gsql: expected authentication request from server, but received v

[og@RHEL7_DB ogdata]$ grep -v -e ^# -e ^$ pg_hba.conf
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
#检查pg_hba.conf的认证设置. 没有问题.
[og@RHEL7_DB ogdata]$ gsql
gsql: expected authentication request from server, but received v

#搜索错误信息,查到需要加端口5532. 
[og@RHEL7_DB ogdata]$ gsql postgres -p5532
gsql ((openGauss 5.1.0 build 310e8463) compiled at 2024-04-21 16:57:23 commit 0 last mr  debug)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# \l
ERROR:  Please use "ALTER ROLE "og" PASSWORD 'password';" to set the password of the user before other operations!
openGauss=# ^Z
[1]+  Stopped                 gsql postgres -p5532
[og@RHEL7_DB ogdata]$


参考文档

https://www.cnblogs.com/aaronwell/p/15463203.html

解决

gsql 加上端口-p

gsql postgres -p5532

总结

5432是缺省端口.在这个环境中, 5432被postgresql数据库使用了. 而opengauss缺省也使用这个端口. 连接到了postgresql数据库的端口.导致连接错误.

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值