在centos6.5安装pg

环境:centos 6.5系统,连外网。

1.参考pg官方网站进行安装。(按照上面的命令行依次执行就行)

https://www.postgresql.org/download/linux/redhat/

选择的是pg9.6版本。

 

也可以直接安装centos6.5自带的pg包。 可参考在CentOS6.5上安装/启动PostgreSQL

 安装第三方贡献的工具:contrib

yum install postgresql96-contrib。

 

2.安装好后,服务器上就已经运行了postgresql-9.6服务。  

可以查看服务状态:service postgresql-9.6 status。

默认的数据库为postgres,用户名为postgres,端口为5432.

安装路径在/usr/pgsql-9.6,data路径在/var/lib/pgsql/9.6。

 

3.在root下无法运行psql,需要切换到postgres用户,然后运行psql,可以进行pg数据库命令操作。

[root@localhost 9.6]# psql
psql: FATAL: role "root" does not exist


[root@localhost 9.6]# su postgres

bash-4.1$ psql

psql (9.6.8)
Type "help" for help.

postgres=#

 

4.使用psql修改postgres用户的密码:

postgres=# \password postgres
Enter new password:
Enter it again:
postgres=#

 

退出使用\q。

 

常用命令

  • ? 列出命令行
  • \h 命令的帮助文件
  • \q 退出接口
  • \d 列出当前数据库的表,试图(views),队列(sequences)
  • \du 列出当前数据库的角色
  • \dt列出当前数据库表
  • \l 列出数据库
  • \password xxx 更改xxx的密码
  • \conninfo 当前连接信息(不一定有,具体可使用?查看哪些命令可用)

5.外面客户端连接pg时,可能报connection refused。

首先保证网络是通的,以及防火墙是关闭的。

此时需要做一下配置修改:

进入到数据目录下:

cd /var/lib/pgsql/9.6/data

修改postgresql.conf配置文件,将以下

# - Connection Settings -

#listen_addresses = 'localhost'  

改为:

# - Connection Settings -

listen_addresses = '*'

 

修改pg_hba.conf配置文件,在

# IPv4 local connections:
host all all 127.0.0.1/32 ident

下面增加以下行:
host all all 0.0.0.0/0 trust。

 

上面操作原因:

原来,在客户端访问PostgreSQL数据库时,PostgreSQL会读取文件pg_hba.conf判断是否信任该主机,故所有需要连接PostgreSQL Server的主机都应当在pg_hba.conf中添加对其信任,即使是Server主机也不例外!

 

6.至此数据库安装完毕。

 

参考文档:

官网下载:https://www.postgresql.org/download/linux/redhat/

在CentOS6.5上安装/启动PostgreSQL

PostgreSQL问题解决--连接失败:https://blog.csdn.net/u012948976/article/details/51763565

 

posted on 2018-04-14 17:42  傻瓜乐园  阅读(477)  评论(0编辑  收藏  举报

导航