Installation and configuration of postgresql in Linux

Source: Internet
Author: User
Tags psql postgresql version

I. Introduction

PostgreSQL is a very complex object-relational database management system (ordbms). It is also currently the most powerful, feature-rich and complex free software database system. Some features are not even available in commercial databases. This database research program originated from Berkeley (BSD) has now been developed into an international development project and has a wide range of users.

Ii. System Environment

System Platform: centos release 6.3 (final)

PostgreSQL version: PostgreSQL 9.2.4

Firewall disabled/iptables: Firewall is not running.

SELinux = disabled

Iii. Installation Method

A. download and install the RPM package

B. Install yum

C. Install the source code package

Iv. Installation Process

A. Install the RPM package

1. Check whether PostgreSQL has been installed

 
[Root @ TS-DEV ~] # Rpm-Qa |GrepPostgres [root @ TS-DEV~] #

If it has been installed, run the rpm-e command to uninstall it.

2. Download the RPM package

 #  wget  HTTP: ///   effect  #  wget  HTTP: ///   effect  #  wget  HTTP: ///   effect  #  wget  HTTP: ///   average  

3. Install PostgreSQL. Pay attention to the installation sequence.

 
# Rpm-IVH postgresql92-libs-9.2.4-1pgdg. rhel6.i686. rpm
# Rpm-IVH postgresql92-9.2.4-1PGDG.rhel6.i686.rpm
# Rpm-IVH postgresql92-server-9.2.4-1PGDG.rhel6.i686.rpm
# Rpm-IVH postgresql92-contrib-9.2.4-1PGDG.rhel6.i686.rpm

4. InitializationPostgreSQL database

Initialization is prompted when the postgresql service is started for the first time.

 
# Service PostgreSQL-9.2Initdb

5. Start the service

 
# Service PostgreSQL-9.2Start

6. Add the postgresql service to the startup list.

# Chkconfig PostgreSQL-9.2 On# Chkconfig--List | grep Postgres

7. Modify the PostgreSQL database user's Postgres password (note that it is not a Linux Account)

By default, PostgreSQL creates an ipvs database user as the database administrator. The default password is blank. We need to change it to the specified password, which is set to 'ipvs '.

# Su-Postgres $ Psql #Alter UserPostgresWithPassword'Postgres';#Select * FromPg_shadow;

8. Test the database

8.1 create a Test Database

# Create database David;

8.2 switch to the David Database

# \ C David

8.3 create a test table

David=#Create TableTest (IDInteger, NameText);

8.4 insert Test Data

David=#Insert IntoTestValues(1,'David');Insert 0 1David=#

8.5 select data

David=#Select * FromTest; ID|Name---- + -------1 |David (1Row) David=#

The test is successful.

9. Modify the Linux User's Postgres Password

PostgreSQL databaseA Linux User is created by default.Postgres, Use the passwd command to set the password of the System user to post123.

#PasswdPostgres

10. Modify the PostgreSQL database configuration for remote access

10.1 modifyPostgreSQL. conf file

# Vi/var/lib/PostgreSQL/9.2/data/PostgreSQL. conf

If you want PostgreSQL to listen to the entire network, remove the # Before listen_addresses and change listen_addresses = 'localhost' to listen_addresses = '*'

10.2 modifyClient Authentication configuration file pg_mirror.conf

Add the IP address or address segment that requires remote database access to the file.

# Vi/var/lib/pgsql/9.2/data/pg_assist.conf

11. Restart the service to make the settings take effect.

 
# Service postgresql-9.2Restart

12. Remote Test connection

Connection successful.

B. Install yum

1. Uninstall the installed PostgreSQL.

// Stop the postgresql service

#/Etc/init. d/postgresql-9.2 stop

// View installed packages

# Rpm-Qa | grep Postgres

// Uninstall

 

 

 

 

 

1. Download PostgreSQLSource code

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $ wget http://ftp.postgresql.org/pub/source/v9.0.3/postgresql-9.0.3.tar.bz2

2. decompress the file.

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $ tar xjvf postgresql-9.0.3.tar.bz2

3. Enter the decompressed directory.

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $ CD postgresql-9.0.3/

4. View install

The short version section in the install file explains how to install the PostgreSQL command. The requirements section describes the lib on which PostgreSQL is installed. It is relatively long. Please try configure first. If an error occurs, check whether the requirements are met.

Short version

./Configure
Gmake
Su
Gmake install
Adduser Postgres
Mkdir/usr/local/pgsql/Data
Chown Postgres/usr/local/pgsql/Data
Su-Postgres
/Usr/local/pgsql/bin/initdb-D/usr/local/pgsql/Data
/Usr/local/pgsql/bin/Postgres-D/usr/local/pgsql/data> logfile2> &1&
/Usr/local/pgsql/bin/createdb Test
/Usr/local/pgsql/bin/Psql Test

5. Run the short version command in the install file to compile and install the mongopsql database.

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $./configure

The following error occurs when running the configure command in my environment:

Checking for main in-lM... yes

Checking for library containing setproctitle... no

Checking for library containing dlopen...-LDL

Checking for library containing socket... None required

Checking for library containing shl_load... no

Checking for library containing getopt_long... None required

Checking for library containing crypt...-lcrypt

Checking for library containing fdatasync... None required

Checking for library containing gethostbyname_r... None required

Checking for library containing shmget... None required

Checking for-lreadline... no

Checking for-ledit... no

Configure: Error: Readline library not found

If you have Readline already installed, see config. log for details on

Failure. It is possible the compiler isnt looking in the proper directory.

 

Use -- without-Readline to disable Readline support. 

Obviously, the dependencies required for PostgreSQL installation are not met. Install the Readline package:

Sudo apt-Get install libreadline5-dev

Sudo apt-Get install zlib1g-dev

After the Readline package is installed, reconfigure it.

6. Make

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $ make

7. make install

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $ make install

8. Add User ipvs

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $ sudo adduser Postgres

9. Create a database file storage folder

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $ sudo mkdir/usr/local/pgsql/Data

10. Change the folder permissions of the previously created data directory.

Linux-DAVID :~ /PostgreSQL/postgresql-9.0.3 $ sudo chown Postgres/usr/local/pgsql/Data

11. Switch users

Su-Postgres

12. Bind a database file storage directory

Postgres :~ /PostgreSQL/postgresql-9.0.3 $ sudo/usr/local/pgsql/bin/initdb-D/usr/local/pgsql/Data

13. Start the database

Postgres :~ /PostgreSQL/postgresql-9.0.3 $ sudo/usr/local/pgsql/bin/Postgres-D/usr/local/pgsql/data> logfile 2> & 1 &

[1] 18635

 

14. Create a database Test

Postgres-Linux :~ $/Usr/local/pgsql/bin/createdb Test

15. Connect to the Test Database

Postgres-Linux :~ $/Usr/local/pgsql/bin/Psql Test

Psql (9.0.3)

Type "help" for help.

Test = #

 

 

16. Create Table 1

Test = # create table Table1 (

Test (# ID integer

Test (#);

Create Table

Test = #

 

17. Insert a record to Table 1

Test = # insert into Table1 values (1 );

Insert 0 1

 

18. query the records just inserted

Test = # select * From Table1;

ID

----

1

(1 row)

 

 

 

TIPS:

PostgreSQL is an object-relational DBMS that provides the following feature:

Complex query complex queries

Foreign key foreign key

Trigger trigger

View views

Supports transaction transactional integrity

Concurrency Control multiversion Concurrency Control

It is also worth mentioning that the PostgreSQL database provides powerful expansion functions to support users to expand it.

More importantly, PostgreSQL is open soure. Authorization is as follows:

PostgreSQL can be used, modified, and distributed by anyone free of charge for any purpose, be it private, commercial, or academic.

 

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.