当前位置:   article > 正文

postgre安装和psql基础命令

postgre

postgre安装以及相关配置

操作系统: CentOS 7

数据库: PostgreSQL 12

一、yum安装postgresql12

1、安装存储库rpm包

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  • 1

2、安装客户端软件包

yum install postgresql12
yum install postgresql12-server (服务器软件包)
sudo yum install postgresql12-devel
  • 1
  • 2
  • 3

二、postgre的初始化

1、初始化数据库

sudo /usr/pgsql-12/bin/postgresql-12-setup initdb 
#Initializing database ... OK
  • 1
  • 2

2、修改IP绑定

#修改配置文件
vi /var/lib/pgsql/12/data/postgresql.conf

#将监听地址修改为*
#默认listen_addresses配置是注释掉的,所以可以直接在配置文件开头加入该行
listen_addresses='*'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3、初始化数据库并启用自动启动

/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12
  • 1
  • 2
  • 3

4、配置防火墙

firewall-cmd --permanent --add-port=5432/tcp  
firewall-cmd --permanent --add-port=80/tcp  
firewall-cmd --reload  
  • 1
  • 2
  • 3

6、修改用户密码

#切换用户,执行后提示符会变为 '-bash-4.2$'
   su - postgres  
#登录数据库,执行后提示符变为 'postgres=#'
   psql -U postgres 
#设置postgres用户密码为postgres
   ALTER USER postgres WITH PASSWORD 'postgres'  
# 退出数据库
    \q 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

[复制代码](javascript:void(0)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/415399
推荐阅读
相关标签