Installing PostgreSQL under CentOS 6.9

Source: Internet
Author: User
Tags postgresql postgres database

Operating system: centos6.9_x64

Installing the Database

Use the following command:

Yum Install postgresql-server-y

Set boot up:

Chkconfig PostgreSQL on

Start the database:

Service PostgreSQL Start

After installation, a database named Postgres and a database user named Postgres are generated by default. It is important to note that a Linux system user named Postgres is also generated.

Configuration database

Initializing the database

Service PostgreSQL Initdb

Adding new users and new databases

AddUser psqladmin su -'123456'; CREATE DATABASE TestDB OWNER useradmin; GRANT all privileges on the DATABASE testdb to Useradmin;

Modify the Postgres database password

\password Postgres

To turn on remote access:

cd/var/lib/pgsql/data/

PostgreSQL by default, remote Access does not succeed, and if you need to allow remote access, you need to modify two configuration files, as described below:

    1. Postgresql.conf

Set the Listen_addresses key value in the file to "*" and in 9.0 Windows Edition, the item configuration is "*" without modification.

    1. Pg_hba.conf

Add the following configuration under the host all All 127.0.0.1/32 MD5 line of the configuration file, or modify the line directly to the following configuration

0.0. 0.0/0 MD5

If you do not want to allow all IP remote access, you can set the 0.0.0.0 in the above configuration item to a specific IP value.

Working with databases

Example code for SQL statements:

Create Tablestudents (ID bigserialPrimary Key, namevarchar( -) not NULL);Insert  intoStudentsValues(1,'STU1');Select *  fromstudents;Drop TableStudents;

Python accesses the sample code:

https://github.com/mike-zhang/pyExamples/blob/master/databaseRelate/psqlOpt/psqlTest1.py

All right, that's it, I hope it helps you.

This article GitHub address:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2017/20170711_centos6.9 under Installation Postgresql.rst

Welcome to Supplement

Installing PostgreSQL under CentOS 6.9

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.