The download address is:
Upload the compressed package postgresql-12.3.tar.gz to: /usr/local/src #Decompression:
su root
tar -xzvf /usr/local/src/postgresql-12.3.tar.gz -C /usr/local/src
cd /usr/local/src/postgresql-12.3
./configure --prefix=/usr/local/postgresql-12.3 --without-readline --without-zlib
make && make install
It can take a lot of time, wait patiently, and the success prompt is as follows:
Create database directory and log directory
mkdir -p /usr/local/postgresql-12.3/data
mkdir -p /usr/local/postgresql-12.3/log
touch /usr/local/postgresql-12.3/log/pgsql.log
#Because pg_ctl cannot run with root account, create another account for maintenance
groupadd wang
useradd -d /home/wang -g wang -m wang
chown -R wang:wang /usr/local/postgresql-12.3
su-wang
/usr/local/postgresql-12.3/bin/initdb -D /usr/local/postgresql-12.3/data
The success prompt is shown in the figure below:
start database
su-wang
-- Note that the following command is one line
/usr/local/postgresql-12.3/bin/pg_ctl -D /usr/local/postgresql-12.3/data -l /usr/local/postgresql-12.3/log/pgsql.log start
If the startup is not successful, check the log:
cat /usr/local/postgresql-12.3/log/pgsql.log
Unable to create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Insufficient permissions
chown -R wang:wang /var/run/postgresql
Open the port and restart the firewall
su root
firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reload
configuration database
Create a database administrator account postgre, -s is a super user, -d allows it to create a database, -P creates a password
su-wang
/usr/local/postgresql-12.3/bin/createuser -s -d -P postgre
Enter password for new role:
Enter it again:
Enter the password twice consecutively: qq123456
Modify the configuration file to achieve remote access:
vi /usr/local/postgresql-12.3/data/postgresql.conf
Make the following changes:
#listen_addresses= 'localhost' remove the comment and change to listen_addresses = '*'
#password_encryption= md5 Remove the comment and change to password_encryption = md5
max_connections = 100 changed to max_connections = 1000
Modify the accessible user ip segment
vi /usr/local/postgresql-12.3/data/pg_hba.conf
Add a line at the end:
host all all 0.0.0.0/0 trust
Restart the database service to make the configuration take effect:
This command is one line
/usr/local/postgresql-12.3/bin/pg_ctl -D /usr/local/postgresql-12.3/data -l /usr/local/postgresql-12.3/log/pgsql.log restart
So far the installation process is complete, use the tool to connect to check whether the database is configured successfully.