安装postgresql11数据库

安装postgresql数据库

yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

yum -y install postgresql11-contrib postgresql11-server

 

创建数据目录,默认是/var/lib/pgsql,这里更改为/data/postgresql_data

mkdir /data/postgresql_data -p

chown postgres:postgres -R /data/postgresql_data/

chmod 750 /data/postgresql_data/

 

修改配置文件,更改数据目录

vim /usr/lib/systemd/system/postgresql-11.service

    Environment=PGDATA=/data/postgresql_data

 

添加环境变量

vim /etc/profile

    export PATH=/usr/pgsql-11/bin:$PATH
    export LD_LIBRARY_PATH=/usr/pgsql-11/lib
    export PGDATA=/data/postgresql_data

source /etc/profile

 

初始化postgresql

/usr/pgsql-11/bin/postgresql-11-setup initdb

systemctl start postgresql-11.service
systemctl enable postgresql-11.service

netstat -atnup | grep 5432         #postgresql数据库默认端口5432

 

设置登录密码

su - postgres        #进入postgres用户

-bash-4.2$ psql

psql (11.4)

Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD '311311';

ALTER ROLE

postgres=# \q

备注:\q退出数据库;\l列出所有用户;\du列出库下所有表

 

设置远程访问

vim /data/postgresql_data/pg_hba.conf       #拉到最下面,更改如下

local all all md5

# IPv4 local connections:

host all all 127.0.0.1/32 md5

# IPv6 local connections:

host all all ::1/128 md5

# Allow replication connections from localhost, by a user with the

# replication privilege.

#local replication all md5

#host replication all 127.0.0.1/32 md5

#host replication all ::1/128 md5

host all all 0.0.0.0/0 md5

 

vim /data/postgresql_data/postgresql.conf       #改为如下

重启:

[root@test ~]# systemctl restart postgresql-11

再进入postgresql就要密码了

使用pgAdmin工具远程连接

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值