Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install PostgreSQL on Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to install PostgreSQL on Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

The official download address of PostgreSQL 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 need to download and install flex (version number greater than 2.5.4) and bison (version number greater than 1.28)

For security reasons, PostgreSQL cannot be run as root users, so corresponding users and groups must be established.

# useradd postgre (automatically establish postgre group)

The installation process is not complicated, similar to the installation method of other source code versions:

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

After this installation, everything will not be all right, and there is still some finishing work to be done:

# vi ~ postgre/.bash_profile

Add:

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 postgres user

# su-postgre

Create 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 database.

Success. You 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 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

This way PostgreSQL uses the database located at / usr/local/pgsql/data, which allows Internet users to connect (- I) and run in the background.

Set up a database

$createdb mydb

PostgreSQL returns a message of "CREATED DATABASE" indicating that the database has been set up.

$psql mydb

Enter the interactive psql tool and create the table:

CREATE TABLE mytable (

Id varchar (20)

Name varchar (30))

After the establishment is completed, you will get a "CREATED" message indicating that the establishment is successful. Now insert a piece of data:

INSERT INTO mytable values ('Author',' Xu Yongjiu')

Psql returned INSERT 18732 1 and queried whether the insertion was successful:

SELECT * FROM MYTABLE

Exit psql and use the\ Q command

Thank you for reading this article carefully. I hope the article "how to install PostgreSQL on Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report