postgresql修改端口后使用psql连接数据库出现报错如何解决

postgresql修改端口后使用psql连接数据库出现报错如何解决

本篇文章给大家分享的是有关postgresql修改端口后使用psql连接数据库出现报错如何解决,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

今天修改pg的端口号port改成5435后重启完数据库的时候直接psql进库的时候进不去

[postgres@node2 data]$ psql
psql: could not connect to server: No such file or directory
 Is the server running locally and accepting
 connections on Unix domain socket "/tmp/.s.PGSQL.5432

这时,进数据库有两种方式

1、psql 后面加上端口号

[postgres@node2 data]$ psql -p 5435
psql (9.6.1)
Type "help" for help.
postgres=#

2、在环境变量/home/postgres/.bash_profile中加上一句

export PGPORT=5435

然后

[postgres@node2 ~]$ source ~/.bash_profile 
[postgres@node2 ~]$ psql
psql (9.6.1)
Type "help" for help.
postgres=#

这样就可以直接进库了

补充:psql不是默认端口时如何连接postgresql

psql不是默认端口时如何连接postgresql

[stork@instance-609xznso pgsql]$ /usr/pgsql-11/bin/psql c3_data -p 5432
could not change directory to “/var/lib/pgsql”: Permission denied
Password for user stork:
psql (11.5)
Type “help” for help.
c3_data=>

自己指定端口就可以了

/usr/pgsql-11/bin/psql xxdatabase -p 端口号

以上就是postgresql修改端口后使用psql连接数据库出现报错如何解决,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。