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:
- Postgresql.conf
Set the Listen_addresses key value in the file to "*" and in 9.0 Windows Edition, the item configuration is "*" without modification.
- 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