Install PostgreSQL on Linux

Source: Internet
Author: User
Tags ftp postgresql psql

To tell the truth, my LAMP site, in fact, can not forget this elephant. MySQL is a brisk dolphin, but lacks many of the characteristics of modern relational databases, such as referential integrity, views, triggers, and so on. So if you need to develop an ecommerce site that requires these features, you might want to consider PostgreSQL. This article will briefly describe its usage by installing the process on Red Hat 7.1.

PostgreSQL's Official download address is:

Ftp://ftp.postgresql.org/pub/v7.1.3/postgresql-7.1.3.tar.gz

http://www.postgresql.org/

If you download the latest development version, you will need to download and install Flex (version number greater than 2.5.4) and Bison (version number greater than 1.28)

Designers must establish corresponding users and groups for security reasons, PostgreSQL cannot run as root.

# Useradd Postgre (automatically set up Postgre group)

The installation process is not complicated and is similar to other source version installation methods:

Extract to/usr/local/src:

# tar Xvfz postgresql-7.1.3.tar.gz

# CD postgresql-7.1.3

#./configure--prefix=/usr/local/pgsql

# make

# make Install

# Chown-r Postgre.postgre/usr/local/pgsql

This is not the end of the installation, there are some finishing work to do:

# VI ~postgre/.bash_profile

Add to:

Pglib=/usr/local/pgsql/lib

Pgdata= $HOME/data

Path= $PATH:/usr/local/pgsql/bin

Manpath= $MANPATH:/usr/local/pgsql/man

Export Pglib pgdata PATH Manpath

Log in as a postgres user,

# Su-postgre

To create a database directory:

$ mkdir Data

To start the database engine:

$ initdb

[Postgre@www postgre]$ Initdb

This database system'll is initialized with username "Postgre".

This user would own all the data files and must also own the server process.

Fixing permissions on pre-existing data directory/home/postgre/data

Creating database System Directory/home/postgre/data/base

Creating Database XLOG Directory/home/postgre/data/pg_xlog

Creating Template Database In/home/postgre/data/base/template1

Creating Global Relations In/home/postgre/data/base

Adding Template1 database to Pg_database

Creating View Pg_user.

Creating View Pg_rules.

Creating View Pg_views.

Creating View Pg_tables.

Creating View pg_indexes.

Loading pg_description.

Vacuuming database.

Success. The can now start the database server using:

/usr/local/pgsql/bin/postmaster-d/home/postgre/data

Or

/usr/local/pgsql/bin/pg_ctl-d/home/postgre/data Start

$ postmaster-i-D ~/data &

[1] 22603

[Postgre@www postgre]$ Debug:data Base System is starting up at Thu 31 02:00:44 2002

Debug:data Base System is shut down at Thu 31 01:57:58 2002

Debug:data Base System is in production to Thu 31 02:00:44 2002

This allows PostgreSQL to use the database located in/usr/local/pgsql/data, allowing Internet users to connect (-i) and run in the background.

Building a Database

$createdb MyDB

PostgreSQL will return "CREATED database" to indicate that the databases have been set up.

$psql MyDB

Enter the interactive Psql tool to create the table:

CREATE TABLE MyTable (

ID varchar (20),

Name varchar (30));

After the establishment is completed, a "CREATED" message is obtained, indicating a successful establishment. Now insert a piece of data:

INSERT into mytable values (' Author ', ' Xu yongjiu ');

Psql returns insert 18732 1, query Insert succeeded:

SELECT * from MYTABLE;

Exit psql, use Q command

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.