PostgreSQL Compilation Installation

Source: Internet
Author: User
Tags postgresql




PostgreSQL Compilation Installation



I. Introduction of PostgreSQL


PostgreSQL is currently the most powerful open source database, supporting rich data types and custom types, and it provides a rich interface to easily extend its functionality.

PostgreSQL has the following advantages over other databases:

PostgreSQL is currently the most powerful open source database

Stable and reliable: PostgreSQL is the only open source database that can lose data 0

Broad support: PostgreSQL supports a large number of mainstream development languages, including C, C + +, Perl, Python, Java, PHP, etc.

Community Active: A new patch version is basically released every three months, which means that a known bug will soon be repaired


The PostgreSQL database compared to MySQL database has the following advantages:

Powerful: Supports all major multi-table connection queries (e.g. Nest loop, hash join, etc.), rich built-in functions, and support for a large number of field types

Support for synchronous replication: Starting with PostgreSQL9.1, support for synchronous replication, high-availability scenarios where zero data loss can be achieved through replication between master and slave





Second, PostgreSQL installation and configuration


This installation uses the source code compilation installs, only as the study work use, the default option, the reader may choose the installation option by oneself.


1, pre-installation preparation

SOURCE Package

Postgresql-9.6.1.tar.gz can be downloaded using the following command

wget https://ftp.postgresql.org/pub/source/v9.6.1/postgresql-9.6.1.tar.gz

Create Postgres User

PostgreSQL cannot run as root and its default user is Postgres

[Email protected] ~]# useradd postgres[[email protected] ~]# passwd postgres

Create the installation directory and data directory

[Email protected] ~]# mkdir-p/usr/local/pgsql/data



2. Start the installation configuration

Unzip and install

Unzip the source package and enter the unzip directory to perform the configuration installation command

[[email protected] ~]# tar-xzf postgresql-9.6.1.tar.gz[[email protected] ~]# CD Postgresql-9.6.1[[email protected] Postg resql-9.6.1]#./configure--prefix=/usr/local/pgsql[[email protected] postgresql-9.6.1]# make && make install

If there is no error, then we can configure


Related configuration

1) Add Environment variables

For convenience, we create a new file named pgsql.sh in the/etc/init.d/directory, with the following content, and make the file effective immediately

[Email protected] ~]# more/etc/profile.d/pgsql.shexport path= $PATH:/usr/local/pgsql/bin[[email protected] ~]# source /etc/profile.d/pgsql.sh

2) The Data directory and the installation directory belong to the main, belong to the group changed to Postgres

[Email protected] ~]# chown‐r postgres.postgres/usr/local/pgsql

3) Initializing the database

Switch to the Postgres user, initialize the PostgreSQL database, and generate the corresponding database configuration file in the/usr/local/pgsql/data directory

[[email protected] ~]# su‐postgres[[email protected] ~]$ initdb‐d/usr/local/pgsql/data# It is important to note that the/usr/local/pgsql/da Ta directory must be empty # Now you can execute the following command to start the PostgreSQL database service [[email protected] ~]$ pg_ctl‐d/usr/local/pgsql/data‐l logfile Start

4) Modify the configuration file

Now our database can only be used for local user access, we need to modify the configuration file so that the remote machine can also access

[[email protected] ~]$ Cd/usr/local/pgsql/data[[email protected] data]$ vi postgresql.conf# in #listen_addresses = ' Localh OST ' Add the listening address for all (*), that is, add listen_addresses = ' * ' [[email protected] data]$ VI pg_hba.conf# Change the IP address of host to the IP segment address required to be accessed, The authentication method is changed to MD

The following changes are followed:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/8C/80/wKiom1huFO6yu5o9AABorp_60Z8223.png "style=" width : 654px;height:102px; "title=" postgresql.conf "alt=" Wkiom1hufo6yu5o9aaborp_60z8223.png "width=" 654 "height=" 102 " Border= "0" hspace= "0" vspace= "0"/>


650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/8C/80/wKiom1huF5SA356nAADFcYs1WUs075.png "title=" Pg_ Hba.conf "width=" "height=" 134 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px;height:134px; "alt=" Wkiom1huf5sa356naadfcys1wus075.png "/>


5) Copy Service startup script to/etc/init.d/directory, add pgsqld service

Switch to root user, copy extract directory under Contrib/startscripts/linux to/etc/init.d/pgsqld, and make simple modification, give execute permission

[[email protected] postgresql-9.6.1]# CP Contrib/start‐scripts/linux/etc/init.d/pgsqld[[email protected] postgresql-9.6.1]# vi/etc/init.d/pgsqld## See if this option corresponds to the data directory you set, and if not, modify # # The default directory for this option is Pgdata= "/usr/local/pgsql/data" # Add Execute permissions and add service to boot # chmod +x/etc/init.d/pgsqld Restart Service # services Pgsqld restart# add to boot # chkconfig--add pgsqld# chkconfig p Gsqld on



To this, the PostgreSQL installation configuration is complete, we can switch to the Postgres user, execute the psql command into the postgres interactive mode, the related database operations.

This article is from the "Carton People" blog, so be sure to keep this source http://zhiheren.blog.51cto.com/12120978/1889419

PostgreSQL Compilation Installation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.