CENTOS7 Installation Configuration PostgreSQL

Source: Internet
Author: User
Tags postgresql psql create database postgres database postgresql version

Test: https://www.linuxidc.com/Linux/2017-10/147536.htm

http://blog.51cto.com/12482328/2090844

Https://www.cnblogs.com/think8848/p/5877076.html

Master/Slave configuration: https://www.linuxidc.com/Linux/2017-03/142145.htm

First, the system environment

System Environment centos7.4

PostgreSQL version 9.6.3

Second, installation

1. Install RPM Package

[HTML]View PlainCopy
    1. [email protected] share]# Yum install-y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/ pgdg-centos96-9.6-3.noarch.rpm

2. Install the Client

[HTML]View PlainCopy
    1. [email protected] share]# Yum install-y postgresql96

3. Install the server

[HTML]View PlainCopy
    1. [email protected] share]# Yum install-y postgresql96-server
    2. By default, a ' Postgres ' System account is created to perform PostgreSQL, and a ' postgres ' database is generated;

4. Initialization

[HTML]View PlainCopy
    1. [Email protected] share]#/usr/pgsql-9.6/bin/postgresql96-setup initdb

5. Set boot and start

[HTML]View PlainCopy
    1. [Email protected] share]# Systemctl enable postgresql-9.6
    2. [Email protected] share]# systemctl start postgresql-9.6

Third, the use of configuration

1. Modify User Password

[HTML]View PlainCopy
    1. [[email protected] ~]# su postgres//yum installed by default create a ' postgres ' user
    2. bash-4.2$ psql-u postgres//Enter Postgres database
    3. Psql (9.6.9)
    4. Type ' help ' for help.
    5. postgres=#
    6. postgres=# alter user postgres with password ' password '

2. Allow Remote access

[HTML]View PlainCopy
    1. [Email protected] ~]# Find/-name postgresql.conf
    2. /var/lib/pgsql/9.6/data/postgresql.conf
    3. [Email protected] ~]# vi/var/lib/pgsql/9.6/data/postgresql.conf
    4. Change listen_addresses = ' localhost ' to listen_addresses = ' * ' to restart service

3, host authentication.

[HTML]View PlainCopy
    1. [Email protected] ~]# vim/var/lib/pgsql/9.6/data/pg_hba.conf
    2. # IPV4 Local connections://ipv4 Add the following below, the first all is the database, the second is the USER,IP represents the client Ip,trust authentication method
    3. Host all 127.0.0.1/32 ident
    4. Host All 10.0.2.114/32 Trust

4. Setting Environment variables

[HTML]View PlainCopy
    1. [Email protected] ~]# Vi/etc/profile
    2. Export path= $PATH:/usr/pgsql-9.6/bin
    3. [Email protected] ~]# Source/etc/profile
    4. [Email protected] ~]# systemctl restart postgresql-9.6

5. Iptables
#postgresql默认开启tcp5432端口 [[Email protected]_master ~]# vim/etc/sysconfig/iptables-a input-m State--state new-m tcp-p t CP--dport 5432-j accept[[email protected]_master ~]# service iptables restart

Third, the use of verification

1. View Port

[HTML]View PlainCopy
  1. [Email protected] ~]# NETSTAT-TUNLP
  2. Active Internet connections (only servers)
  3. Proto recv-q send-q Local address Foreign address State Pid/program Name
  4. TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 870/nginx:master p
  5. TCP 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 29768/postmaster

2. Easy to use

[HTML]View PlainCopy
    1. [[email protected] ~]# su-postgres//Switch User
    2. Last login: May 03:41:13 EDT 2018PTS/1
    3. -bash-4.2$
    4. -bash-4.2$ psql-u postgres//Enter the database
    5. Psql (9.6.9)
    6. Type ' help ' for help.
    7. postgres=#

2.1 Creating a User

[HTML]View PlainCopy
    1. postgres=# create user user1 with password ' user123 ';
    2. CREATE ROLE

2.2 Creating a Database

[HTML]View PlainCopy
    1. postgres=# CREATE database T1 owner User1;
    2. CREATE DATABASE

2.3 Database Authorization

[HTML]View PlainCopy
    1. postgres=# Grant all privileges on the database T1 to User1; Not authorized to log in to the console only

2.4 Logging back into the database

[HTML]View PlainCopy
    1. -bash-4.2$ psql-u user1-d t1-h 127.0.0.1-p 5432

2.5 Creating a Table

Postdb1=> CREATE TABLE TB1 (          ID int primary KEY,          name VARCHAR (),           salary real          );

2.6 Inserting data

postdb1=> INSERT INTO TB1 (          ID, name, salary)          values (          101, ' Mike ', 5000.00          );

2.7 Queries

Postdb1=>select * from TB1;

CENTOS7 Installation Configuration PostgreSQL

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.