1. Environmental statement
CentOS7.2postgresql10.4
2. Download the official address of PostgreSQL
https://www.postgresql.org/ftp/source/
In the download list, select version 10.4 as required, such as:
After entering the subdirectory, you can see the list of files:
Select postgresql-10.4.tar.gz and upload to the specified directory of the Redhat server when the download is complete. 3. Configuring the compilation Installation
tar -zxvf postgresql-10.4.tar.gzcd postgresql-10.4./configure --prefix=/usr/local/postgresql
Compile postgres, find hints missing ReadLine library, such as:
yum search readline发现一个readline-devel包yum install readline-devel
Re-configure
./configure --prefix=/usr/local/postgresq
No error. Compile and install
make && make install
4. Configure user rights and environment variables
useradd postgreschown -R postgres:postgres /usr/local/postgresql/su - postgresvi ~/.bash_profilePGHOME=/usr/local/postgresqlexport PGHOMEPGDATA=/usr/local/postgresql/dataexport PGDATAPATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
After the modification is complete, you can make it effective immediately by using source./.bash_profile
source ~/.bash_profile
5. Initializing the database
###在使用initdb进行初始化的同时我们可以指定参数来同时进行一些初始化工作,例如指定pgdata(postgresql数据目录)、指定encoding(编码)、指定数据库超级用户的用户名和密码等等,在最后面我标记出的这段话指出了如果data目录没有指定,则会默认使用环境变量中的PGDATA,由于之前我们刚刚设置了PGDATA环境变量,所以此处我们也就无需再额外指定,最后执行初始化命令即可:initdb
After initialization, you can see the data directory and the associated data and configuration files for this directory in the PostgreSQL directory:
#base目录是表空间目录#global目录是相关全局变量的目录#pg_hba.conf:访问控制配置(127.0.0.1改为信任的客户端ip网段使其可以远程访问)#postgresql.conf:postgresql主配置文件(listen_address=localhost改为星号使其监听整个网络)
6. Modify the configuration file to change the IP address of pg_hba.conf to 0.0.0.0/0, and encrypt to MD5, which means password access is required:
Modify the listen_address in the postgresql.conf so that it listens to the entire network:
7. Turn off Firewall 8. Start the connection database
pg_ctl start -l /usr/local/postgresql/log/pg_server.logpsqlps -ef|grep postgres
Redhat 7.2 Compiling and installing PostgreSQL 10