Background things: the need to install postgres database on Linux, but want to directly specify the installation directory, so I want to compile and install the source code by pg
First, download the source code package. Source Download: https://github.com/postgres/postgres/releases
I downloaded version is postgres-REL_10_9.tar.gz
Root user switching command with the following actions:
sudo -i
(1) the installation package uploaded to the Linux server
(2) extract the source archive
tar xvfz the postgres-REL109. tar gz
(3) Configuration before compilation.
cd postgres-REL_10_9
./configure
(4) official compilation
make
In this process, will encounter a variety of missing dependency and error, can be installed via yum install ***.
(5) Installation
make install
(6) pg create a system user and password
adduser postgres
passwd postgres
(7) to create a database to store the data folder
mkdir /usr/local/pgsql/data
(8) authorization to postgres user data folder
chown postgres /usr/local/pgsql/data
(9) switching the user to initialize the database folder postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
(10) start the postgres service Services
/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data/ -l /usr/local/pgsql/data/logfile
(11) to create the first database
/usr/local/pgsql/bin/createdb test
(12) into the connector using the tool database psql Command Line
/usr/local/pgsql/bin/psql test
(13) is provided sql statement execution context (i.e. operation for which a Schema)
set search_path to public
(14) to create a test table
create table test(id int primary key,name varchar(50) not null); insert into test(id,name) values(1,'小明'); insert into test(id,name) values(2,'小红');
(15) Display Record
select * from test;
(16) configuration environment variable
Switch to the root user
we / etc / profile
Tail modify in the file:
. Export the JAVA_HOME = / usr / Java / jdk1 . 8 .0_121 Export the JRE_HOME . = / usr / Java / jdk1 . 8 .0_121 / JRE Export PG_HOME = / usr / local / installation path pgsql #postgres database Export the CLASSPATH =:. $ the JAVA_HOME / lib: $ JRE_HOME / lib: $ the CLASSPATH Export the PATH = $ PG_HOME / bin: $ JAVA_HOME / bin: $ # configure the PATH environment variable
(17) arranged to restart the
source /etc/profile
This completes the installation of postgres