Environmental requirements
- Centos7 system 64-bit
- postgresql version is 15
operate
Install postgresql-15 through yum, which can basically be installed quickly. The specific operation commands are as follows:
##添加yum安装的数据源(repo文件)
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
##已经存在数据源,就可以直接在yum中找到,直接安装即可,等待一会
sudo yum install -y postgresql15-server
#初始化数据库
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
#设为开机启动
sudo systemctl enable postgresql-15
#启动postgresql-15
sudo systemctl start postgresql-15
Follow the above steps to install postgresql-15, but it should be noted that the system needs to create a postgres account:
groupadd postgres
useradd -g postgres postgres
In order to be accessible remotely, some configuration is still required:
#停掉防火墙,并且开机不启动
systemctl stop firewalld
systemctl disable firewalld
#修改postgresql.conf
# vim postgresql.conf
# 修改监听IP,将地址设置为'*',这样就可以远程访问
listen_addresses = '*'
#修改 pg_hba.conf 服务连接配置文件
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 md5
#启动postgresql服务
systemctl start postgresql-15
At this point, the entire installation is over, and the database can be accessed through a remote client. The postgresql installed in this way does not require a password to log in. The account is postgres, and the port is 5432. When these information can be modified, mine is in It is installed on the Alibaba Cloud server, and the port has been modified. If the default port is used, Alibaba will report a lot of server risks. Sometimes the repair is careless, and the database cannot be connected at that time.
The postgresql database is still very powerful, and there are quite a lot of functions. Let's try to explore it!