Install postgresql-10.3 under centos7

Install pgsql10.3 under centos7

Foreword

Installed pgsql-10.3 on centos7, and found many articles on the Internet. It took a long time to succeed. Then summarize the installation process to avoid wasting time next time.

Download pgsql-10.3

system versioncentos7

Download pgsql-10.3:https://www.postgresql.org/ftp/source/v10.3/

Upload tar package to server

$ scp postgresql-10.3.tar.gz [email protected]:~
The authenticity of host '192.168.56.189 (192.168.56.189)' can't be established.
ECDSA key fingerprint is SHA256:q2lore2LaeBsH4j3jmEVg0VYbfudDDR4LkmF/rt+Zp0.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/liz/.ssh/known_hosts).
[email protected]'s password: 
postgresql-10.3.tar.gz                                                     100%   25MB  37.5MB/s   00:00  

installation

Unzip

# tar -xzvf postgresql-10.3.tar.gz

Install basic tools

yum install -y vim lrzsz tree wget gcc gcc-c++ readline-devel zlib-devel

Compile

Go to the folder you just unzipped and execute the command

./configure --prefix=/usr/local/pgsql

The following /usr/local/pgsqlshows the specific location to be compiled and installed, you can define your own

installation

make && make install

Then wait for the installation ...

until it appears PostgreSQL installation complete.that the installation was successful

Create directory data, log

# mkdir /usr/local/pgsql/data
# mkdir /usr/local/pgsql/log

Add system environment variables

 vim /etc/profile

Write at the end

PGHOME=/usr/local/pgsql
export PGHOME
PGDATA=/usr/local/pgsql/data
export PGDATA
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin

Note: /usr/local/pgsqlneed to modify to your own installation directory

Make configuration file effective

# source /etc/profile

Add user postgres and empower

# adduser postgres
# chown -R postgres:root /usr/local/pgsql/

Change password (at root)

# passwd postgres 
更改用户 postgres 的密码 。
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

Initialize the database

Note: Need to postgresbe initialized under the user

Switch user postgres

# su postgres

Then initialize the database

# /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/

Edit configuration file

# vim /usr/local/ppgsql/data/postgresql.conf

modify

listen_addresses = '*'
port = 5432

Also modify

# vim /usr/local/pgsql/data/pg_hba.conf

Add at the end

Description:

TYPE: pg connection method, local: local unix socket, host: tcp / ip connection
DATABASE: designated database
USER: designated database user
ADDRESS: ip address, you can define a certain host or a certain network segment, 32 represents the entire The IP address is equivalent to a fixed IP. 24 represents only the first three digits, and the last digit is any
METHOD between 0 and 255 : authentication method, commonly used are ident, md5, password, trust, reject.
md5 is a commonly used password authentication method.
password is transmitted to the database as a clear text password, it is recommended not to use it in a production environment.
Trust is to log in as long as you know the database user name, it is recommended not to use in a production environment.
Reject is to reject authentication.

Start service

$ pg_ctl start -l /usr/local/pgsql/log/pg_server.log
could not change directory to "/root/postgresql-10.3": 权限不够
waiting for server to start.... done
server started

Start, stop, restart

./pg_ctl start\stop\restart -D /usr/local/pgsql/data/

View version

# psql -V
psql (PostgreSQL) 10.3

Set boot

Copy the linux file in the pgs installation package to /etc/init.d or /etc/rc.d

[root@10 postgresql-10.3]# cp contrib/start-scripts/linux /etc/init.d/pgsql

Modify the configuration items in the pgsql file according to the installation path

## EDIT FROM HERE

# Installation prefix (安装路径)
prefix=/usr/local/pgsql

# Data directory (data路径)
PGDATA="/usr/local/pgsql/data"

Modify pgsql file permissions

# chmod +x /etc/init.d/pgsql

Execute pgsql file at boot

# chkconfig --add pgsql

Turn off the firewall

$ systemctl stop firewalld
$ systemctl disable firewalld

Guess you like

Origin www.cnblogs.com/ricklz/p/12723699.html