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 postgre

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

How to install postgre, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

1 Experimental purpose

PostgreSQL database installation, initialization and usability testing.

2 introduction to the environment

Operating system: RedHat 6.5

Database software: PostgreSQL version9.5

3 introduction to PostgreSQL database

PostgresQL is an object-relational database management system (ORDBMS) based on the object-relational database management system (ORDBMS) developed by the Department of computer Science at the University of California, Berkeley and now renamed PostgreSQL. PostgreSQL supports most SQL standards and provides many other modern features: complex queries, foreign keys, triggers, views, transaction integrity, MVCC. Similarly, PostgreSQL can be extended in many ways, for example, by adding new data types, functions, operators, aggregation functions, and indexes. Free use, modification, and distribution of PostgreSQL, whether for private use, commercial use, or academic research.

4 Software acquisition

Official download address: https://yum.postgresql.org/rpmchart.php

Official document: https://www.postgresql.org/docs/

Note: it is recommended that you learn any software, starting from reading the official documents.

5 installation mode

Method 1: yum installation

These distributions all include PostgreSQL by default. To install PostgreSQL from these repositories, use the yum command on RHEL 5, 6 and 7, or dnf command on Fedora 22:

Yum install postgresql-server

Dnf install postgresql-server

Which version of PostgreSQL you get will depend on the version of the distribution:

Distribution

Version

RHEL/CentOS/SL/OL 7

9.2 (also supplies package rh-postgresql95 and rh-postgresql94 via SCL)

RHEL/CentOS/SL/OL 6

8.4 (also supplies package postgresql92)

RHEL/CentOS/SL/OL 5

8.1 (also supplies package postgresql84)

Fedora 24

9.5

Fedora 23

9.4

Method 2: download the RPM installation directly

Method 3: install the source package

6 installation practice 6.1 check if PostgreSQL is installed

[root@mhapp1 ~] # rpm-qa | grep postgres

Postgresql-8.4.18-1.el6_4.x86_64

Postgresql-libs-8.4.18-1.el6_4.x86_64

Postgresql-devel-8.4.18-1.el6_4.x86_64

Use rpm-e to uninstall if installed. Note: please confirm that it is the practice library!

6.2 install PostgreSQL, pay attention to the installation sequence

[root@mhapp1 rpm] # rpm-ivh postgresql95-libs-9.5.6-2PGDG.rhel6.x86_64.rpm

Warning: postgresql95-libs-9.5.6-2PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

Preparing... # [100%]

1:postgresql95-libs # # [100%]

[root@mhapp1 rpm] # rpm-ivh postgresql95-9.5.6-2PGDG.rhel6.x86_64.rpm

Warning: postgresql95-9.5.6-2PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

Preparing... # [100%]

1:postgresql95 # # [100%]

[root@mhapp1 rpm] # rpm-ivh postgresql95-server-9.5.6-2PGDG.rhel6.x86_64.rpm

Warning: postgresql95-server-9.5.6-2PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

Preparing... # [100%]

1:postgresql95-server # # [100%]

[root@mhapp1 rpm] # rpm-ivh postgresql95-contrib-9.5.6-2PGDG.rhel6.x86_64.rpm

Warning: postgresql95-contrib-9.5.6-2PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

Preparing... # [100%]

1:postgresql95-contrib # # [100%]

6.3 initialize PostgreSQL

[root@mhapp1 rpm] # / etc/init.d/postgresql-9.5 start

/ var/lib/pgsql/9.5/data is missing. Use "service postgresql-9.5 initdb" to initialize the cluster first.

[root@mhapp1 rpm] # service postgresql-9.5 initdb

Initializing database: [OK]

6.4 start the service

[root@mhapp1 rpm] # service postgresql-9.5 start

Starting postgresql-9.5 service: [OK]

6.5 add the PostgreSQL service to the startup list

[root@mhapp1 rpm] # chkconfig postgresql-9.5 on

[root@mhapp1 rpm] # chkconfig-- list | grep postgres

Postgresql-9.5 0:off 1:off 2:on 3:on 4:on 5:on 6:off

6.6 modify the password of PostgreSQL database user postgres

PostgreSQL database default will create a postgres database user as the database administrator, the default password is empty, we need to change to the specified password

[root@mhapp1 rpm] # su-postgres

$id

Uid=26 (postgres) gid=26 (postgres) groups=26 (postgres)

$psql

Psql (9.5.6)

Type "help" for help.

Postgres=# alter user postgres with password'orastar'

ALTER ROLE

Postgres=# select * from pg_shadow

Usename | usesysid | usecreatedb | usesuper | userepl | usebypassrls | passwd | valuntil | useconfig

-+-

-

Postgres | 10 | t | t | t | t | md53175bce1d3201d16594cebf9d7eb3f9d | |

(1 row)

7 Test Database 7.1 create a test database

Postgres=#

Postgres=# create database htdb

CREATE DATABASE

7.2 switch to htdb database

Postgres=#\ c htdb

You are now connected to database "htdb" as user "postgres".

7.3 create a test table

Htdb=# create table test (id integer,name text)

CREATE TABLE

7.4 insert test data

Htdb=# insert into test values (1 recorder ht')

INSERT 0 1

7.5 query data

Htdb=# select * from test

Id | name

-- +-

1 | ht

(1 row)

Htdb=#

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Database

Wechat

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

12
Report