Official website
https://www.postgresql.org/download/
Pull to the end of the page
Select source
Choose the version you need
I use 12.3
Then waiting to download the official website is generally slow
1: Upload to virtual machine
Unzip: tarz -zxvf postgresql-12.3.tar.gz #Create
user postgres
useradd postgres #Install
dependency package
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python -devel gcc-c++ openssl-devel cmake gcc* readline-devel
mkdir /opt/postgres
chown -R postgres:postgres /opt/postgres/
Add environment variables
Open the configuration file
vi /etc/profile
Move to the file and add the following configuration at the end
export PATH=/opt/postgres/bin: P A T H e x p o r t P G H O M E = / o p t / p o s t g r e s e x p o r t P G D A T A = / o p t / p o s t g r e s / d a t a / e x p o r t L D L I B R A R Y P A T H = PATH export PGHOME=/opt/postgres export PGDATA=/opt/postgres/data/ export LD_LIBRARY_PATH= PATHexportPGHOME=/opt/postgresexportPGDATA=/opt/postgres/data/exportLDLIBRARYPA T H=LD_LIBRARY_PATH: P G H O M E / l i b / e x p o r t P A T H = PGHOME/lib/ export PATH= PGHOME/lib/exportPATH=PGHOME/bin: P A T H : PATH: PATH:HOME/bin
Reload configuration file
source /etc/profile
It takes a long time to check the environment
./configure --prefix=/opt/postgres/ --with-python --with-libxml --with-libxslt
carried out:
Make
It takes a long time to execute
make install
Initialize the database
Switch user
with postgres
carried out
/opt/postgres/bin/initdb -D $PGDATA -E UTF8
If an error is reported, modify $PGDATA =>/opt/postgres/data
/opt/postgres/bin/initdb -D /opt/postgres/data -E UTF8
Modify the configuration to facilitate other computers to connect
vi postgresql.conf
#Find listen_addresses and port parameters, modify them as follows, or modify
listen_addresses ='*'
port = 5432 according to your needs
#Set the ip rules for release according to your own network segment
vi pg_hba.conf
IPv4 local connections:
host all all 192.168.0.0/16 md5
Host configuration reference
start up:
/opt/postgres/bin/pg_ctl -l /opt/postgres/server.log start
connection
Note: If you modify the port
Create an account
CREATE USER test WITH PASSWORD'Here is the password, pay attention to the quotes';