Install PostgreSQL on Linux

xiaoxiao2021-03-06  69

To be honest, my LAMP website is actually can't forget this elephant. MySQL is a brisk dolphin, but lacks a number of modern relational databases, such as reference integrity, view, trigger, etc. Therefore, if you need to develop an e-commerce website, if you need these features, you may consider PostgreSQL. This article will briefly introduce the usage by its installation 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 developments, you need to download and install Flex (version number is greater than 2.5.4) and Bison (version number is greater than 1.28)

For safety reasons, PostgreSQL cannot run with root users, so you must establish a corresponding user and group.

# UserAdd Postgre (Automatically create a Postgre group)

The installation process is not complex and other source code versions are similar:

Unzip 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 a good job, there is still some ending 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 with Postgres users,

# su - postgre

Establish a database directory:

$ MKDIR DATA

Start the database engine:

$ initdb

[Postgre @ www postgre] $ initdb

This Database System Will BE Initialized with username "postgre".

THIS User Will 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 data.

You can now Start The Database Server Using:

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

oral

/ 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 strau jan 31 02:00:44 2002

Debug: Data Base System Was Shut Down At Thu Jan 31 01:57:58 2002

Debug: Data Base System Is in Production State At Thu Jan 31 02:00:44 2002

Such postgreSQL uses a database located in / usr / local / pgsql / data, allows Internet users to connect (-i) and run in the background.

build database

$ cretedb mydb

PostgreSQL will return information about "create Database", indicating that the database is completed.

$ psql mydb

Enter interactive PSQL tools, establish tables:

Create Table MyTable

ID VARCHAR (20),

Name varchar (30));

After the establishment is complete, a "create" information will be obtained, indicating that establishing success. Now insert a data:

INSERT INTO MyTable Values ​​('Author', 'Xu Yongjiu');

PSQL Returns INSERT 18732 1, the query insert is successful:

Select * from mytable;

Exit PSQL and use the / Q command.

转载请注明原文地址:https://www.9cbs.com/read-110299.html

New Post(0)