Linux CentOS 7 Installation PostgreSQL 9.3 (release version)

Source: Internet
Author: User
Tags postgresql postgresql version

Objective

Title, this blog record in the Linux CentOS 7 installation postgressql The entire process, as well as the database configuration, in the Linux system, PostgreSQL installation methods are divided into two kinds, namely:

    1. Binary installation package Installation
    2. Source Code Compilation Installation

Because we don't have any special needs. Here's a simple way to choose--binary installation package installation, binary package installation method is usually through the different distributions of Linux under the package Manager, For example, Debian and Ubuntu are installed using the Apt-get command or the Aptitude command, as follows:

sudo apt-get install postgresql

And in Redhat. Under CentOS or Fedora, use the Yum tool to install PostgreSQL with the following command:

yum install postgresql-server.x86_64

Let's take a look at the whole installation process and details below.

Installing PostgreSQL

I chose Yum installation, which is a 9.3 version, so just enter the location of the repository (you can check to see if there is an rpm -qa | grep postgres installed PostgreSQL rpm package, and if so, uninstall it by yum remove postgresql* command):

yum install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm

You can also manually download the specified version directly in the official RPM Repository, with the following address: PostgreSQL RPM Repository (with Yum), select the CentOS 7-based version 9.3 as required:

After downloading, go to the RPM package directory to run the rpm -ivh ./pgdg-centos93-9.3-3.noarch.rpm installation RPM package, then you can continue to install PostgreSQL and some of the necessary components, such as the Official guide:

For example, since we are installing the 9.3 version here, you can simply enter the following command to install it:

yum install postgresql93-server postgresql93-contrib

The installation log is as follows:


The first thing to do when the installation is complete is to initialize the DB, and one thing to note is that the default installation directory for PostgreSQL in CentOS 7 is:/usr/pgsql-9.3, the default data directory is /var/lib/pgsql/ Version/data, the following is the official guide:

It is important to note that to perform the init command in the installation directory to switch to PostgreSQL, we can find the Initdb script in the installation directory:

Initialize the database by running the Initialize command into the bin directory:

Initialization can start the database and log in, the Start command is as follows:

start postgresql-9.3.service

Login after startup, we use Postgres user to login:

As shown, you can see that the service has started successfully and queried the database version, and then you can see which databases are currently available through the \l command:

For example, you can see that there are 4 databases by default and\q is the Exit command. To be safe, let's change the password for the Postgres user, which is empty by default:

alter user postgres with password ‘111111‘;

Such as:

Finally, if you are a DB server, you need to set the database service to boot:

The setup-related settings are all over now, so let's see how the Client tool (NAVICAT) connects to the database.

Client Connection PostgreSQL

Title, since the client wants to connect, the first step must be open port, introduced a more powerful firewall--firewall in CentOS 7, so we need to open the default port 5432 of PostgreSQL in Firewall, That is, adding 5432 ports to the zone (firewall's new feature, which simply means defining the trusted level of network connectivity). The command is as follows:

firewall-cmd--zone=public--add-port=5432/tcp--permanent

This successfully joins the 5432 port into the public area, the permanent parameter indicates permanent, that is, the restart will not expire, and finally do not forget to update the firewall rules:

firewall-cmd--reload

OK, take a look at all the open ports under the public area, the command is as follows:

firewall-cmd--zone=public--list-ports

You can see that port 5432 has been successfully opened:

Only open the port is not enough, PostgreSQL also do a good job in security, it can specify which IP addresses can access the database server remotely, by default, only listen to local, so first need to let PostgreSQL listen to the entire network, first into the PostgreSQL installation directory, Locate the configuration file with the following path:

 cd /var/lib/pgsql/9.3/data/

The following two files are mainly modified:

For example, first PostgreSQL main configuration file postgresql.conf, will listen_addresses before the # removed, and will listen_addresses = ' localhost ' changed to listen_addresses = ' *’:

Next, to modify the pg_hba.conf file, add the allowed IP address to the list in the format "Type Database User address Method", For example, I hope that only 192.168.111.1 this address can access the PostgreSQL database remotely, add the following configuration:

Finally, restart the database service for the configuration to take effect:

systemctl restart postgresql-9.3.service

At this point, use the host's Navicat (192.168.111.1) to connect to the PostgreSQL server in the virtual machine to test:

If you see a successful connection, the installation of PostgreSQL is complete.

Summarize

Simply record the entire process of installing PostgreSQL version 9.3 in the Linux CentOS 7 system and the associated configuration, the End.

Linux CentOS 7 Installation PostgreSQL 9.3 (release version)

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.