Sql9.3 graphic tutorial for installing PostgreSQL9.3 in CentOS 7, postgresql9.3

Source: Internet
Author: User

Sql9.3 graphic tutorial for installing PostgreSQL9.3 in CentOS 7, postgresql9.3

For example, this blog record the entire process of installing PostgreSQL in CentOS 7 and the database configuration. in Linux, PostgreSQL can be installed in two ways:

1. Install the binary installation package

2. source code compilation and Installation

Because we have no special requirements here, we can select a simple method -- binary installation package installation. The Binary Package installation method is generally carried out through the Package Manager in Linux of different release versions, for example, Debian and Ubuntu are installed using the apt-get command or the aptitude command. The command is as follows:

Sudo apt-get install postgresql

In RedHat. In CentOS or Fedora, use the yum tool to install PostgreSQL. The command is as follows:

Yum install postgresql-server.x86_64

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

Install PostgreSQL

I chose yum for installation. The requirement is version 9.3, you can directly enter the location of the software library (you can run the rpm-qa | grep postgres command to check whether the postgresql rpm package has been installed, if yes, run the yum remove postgresql * command to uninstall it ):

Copy codeThe Code is as follows: 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. The address is as follows: PostgreSQL RPM Repository (with Yum). Select CentOS 7-based version 9.3 as needed:

 

After the download, enter the rpm package directory run rpm-ivh./pgdg-centos93-9.3-3.noarch.rpm to install the rpm package, you can continue to install PostgreSQL and some essential components, such as the official Guide:

For example, because we have installed version 9.3, you can directly run the following command to install it:

Yum install postgresql93-server postgresql93-contrib

The Installation Log is as follows:



After the installation is complete, initialize the database. Note that the default installation directory of postgresql in CentOS 7 is:/Usr/pgsql-9.3The default data directory is/Var/lib/pgsql/version/dataThe following is the official Guide:

Note that you need to execute the initialization command in the installation directory to switch to postgresql. You can find the initdb script in the installation directory:

Run the initialization command in the bin directory to initialize the database:

After successful initialization, you can start the database and log on to the database. The startup command is as follows:

Systemctl start postgresql-9.3.service

You can log on after it is started. We use the postgres user to log on:

As shown in, you can see that the service has been successfully started and the database version has been queried.\ LCommand to view which databases are currently available:

For example, we can see that there are 4 databases by default,\ QTo exit the command. For the sake of security, let's change the postgres user password. The default value is null:

Alter user Login s with password '123 ';

For example:

Finally, if the database server is used, you need to set the Database Service to start upon startup:

The installation-related settings have all ended. Next, let's take a look at how the client tool (Navicat) connects to the database.

Connect the client to PostgreSQL

For example, since the client is connected, the first step is to open the port. In CentOS 7, a more powerful Firewall-Firewall, therefore, we need to enable PostgreSQL's default port 5432 in Firewall, that is, adding port 5432 to the zone (the new feature of Firewall, in short, it defines the credibility level of network connections in the network area. The command is as follows:

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

In this way, port 5432 is successfully added to the public area. The permanent parameter indicates that the port is permanently valid, that is, the restart will not expire. Do not forget to update the firewall rules:

Firewall-cmd -- reload

OK. Let's take a look at all opened ports in the public area. The command is as follows:

Firewall-cmd -- zone = public -- list-ports

We can see that port 5432 has been successfully opened:

It is not enough to open only ports. PostgreSQL is also doing well in terms of security. It can specify which IP addresses can remotely access the database server. By default, it only listens locally, first, you need to let PostgreSQL listen to the entire network. First, go to the PostgreSQL installation directory and find the configuration file. The path is as follows:

Cd/var/lib/pgsql/9.3/data/

Modify the following two files:

For example, in the first PostgreSQL main configuration file postgresql. conf, remove the # Before listen_addresses and change listen_addresses = 'localhost' to listen_addresses = '*':

Next, modify the pg_cmd.conf file and add the IP addresses that can be accessed to the list in the format of "Type Database User Address Method". For example, if I want to remotely access the PostgreSQL Database only at 192.168.111.1, add the following Configuration:

Finally, restart the Database Service to make the configuration take effect:

Systemctl restart postgresql-9.3.service

In this case, use the Navicat (192.168.111.1) of the host to connect to the PostgreSQL server of the VM and test it:

For example, you can see that the connection is successful, and the installation of PostgreSQL has been completed.

Summary

Briefly record The entire process of installing PostgreSQL 9.3 and related configurations in Linux CentOS 7, The End.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.