[root@test02 init.d]# ll /etc/init.d/postgresql-9.5

-rwxr-xr-x. 1 root root 10072 May 15 06:34 /etc/init.d/postgresql-9.5

1. 检查PostgreSQL 是否已经安装

# rpm -qa|grep postgres

若已经安装,则使用rpm -e 命令卸载

[root@test02 bin]# rpm -qa|grep postgres

postgresql-8.4.18-1.el6_4.x86_64

postgresql-devel-8.4.18-1.el6_4.x86_64

postgresql-libs-8.4.18-1.el6_4.x86_64

[root@test02 bin]# rpm -e postgresql-devel-8.4.18-1.el6_4.x86_64

[root@test02 bin]# rpm -e postgresql-8.4.18-1.el6_4.x86_64

[root@test02 bin]# rpm -e postgresql-libs-8.4.18-1.el6_4.x86_64

[root@test02 soft_bak]# wget http://yum.postgresql.org/9.5/redhat/rhel-6.5-x86_64/postgresql95-server-9.5.3-1PGDG.rhel6.x86_64.rpm

[root@test02 soft_bak]# wget http://yum.postgresql.org/9.5/redhat/rhel-6.5-x86_64/postgresql95-contrib-9.5.3-1PGDG.rhel6.x86_64.rpm

[root@test02 soft_bak]# wget http://yum.postgresql.org/9.5/redhat/rhel-6.5-x86_64/postgresql95-libs-9.5.3-1PGDG.rhel6.x86_64.rpm

[root@test02 soft_bak]# wget http://yum.postgresql.org/9.5/redhat/rhel-6.5-x86_64/postgresql95-9.5.3-1PGDG.rhel6.x86_64.rpm

3. 安装PostgreSQL,注意安装顺序

[root@test02 soft_bak]# rpm -ivh postgresql95-libs-9.5.3-1PGDG.rhel6.x86_64.rpm

warning: postgresql95-libs-9.5.3-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

Preparing...                ########################################### [100%]

1:postgresql95-libs      ########################################### [100%]

[root@test02 soft_bak]# rpm -ivh postgresql95-9.5.3-1PGDG.rhel6.x86_64.rpm

warning: postgresql95-9.5.3-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

Preparing...                ########################################### [100%]

1:postgresql95           ########################################### [100%]

[root@test02 soft_bak]# rpm -ivh postgresql95-server-9.5.3-1PGDG.rhel6.x86_64.rpm

warning: postgresql95-server-9.5.3-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

Preparing...                ########################################### [100%]

1:postgresql95-server    ########################################### [100%]

[root@test02 soft_bak]# rpm -ivh postgresql95-contrib-9.5.3-1PGDG.rhel6.x86_64.rpm

warning: postgresql95-contrib-9.5.3-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

Preparing...                ########################################### [100%]

1:postgresql95-contrib   ########################################### [100%]

4 初始化PostgreSQL 数据库

初始化数据库

# service postgresql-9.5 initdb

[root@test02 pgsql]# service postgresql-9.5 initdb

Initializing database:                                     [  OK  ]

5. 启动服务

# service postgresql-9.5 start

[root@test02 pgsql]# service postgresql-9.5 start

Starting postgresql-9.5 service:                           [  OK  ]

6. 把PostgreSQL 服务加入到启动列表

# chkconfig postgresql-9.2 on

# chkconfig --list|grep postgres

chkconfig –list|grep postgres

7. 修改PostgreSQL 数据库用户postgres的密码

PostgreSQL 数据库默认会创建一个postgres的数据库用户作为数据库的管理员,默认密码为空,我们需要修改为指定的密码,这里设定为’postgres’。

[root@test02 bin]# su - postgres

-bash-4.1$ pwd

/var/lib/pgsql

-bash-4.1$ psql

psql (8.4.18, server 9.5.3)

WARNING: psql version 8.4, server version 9.5.

Some psql features might not work.

Type "help" for help.

postgres=#

postgres=# ALTER USER postgres WITH PASSWORD 'postgres';

ALTER ROLE

postgres=# SELECT * from pg_shadow ;

usename  | usesysid | usecreatedb | usesuper | userepl | usebypassrls |               passwd                | valuntil | us

econfig

----------+----------+-------------+----------+---------+--------------+-------------------------------------+----------+---

--------

postgres |       10 | t           | t        | t       | t            | md53175bce1d3201d16594cebf9d7eb3f9d |          |

(1 row)

8. 测试数据库

postgres=# CREATE DATABASE t_pgdb;

CREATE DATABASE

postgres=# \l+

List of databases

Name    |  Owner   | Encoding |  Collation  |    Ctype    |   Access privileges   |  Size   | Tablespace |

Description

-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+---------------

-----------------------------

postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 7248 kB | pg_default | default admini

strative connection database

t_pgdb    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 7129 kB | pg_default |

template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres           | 7129 kB | pg_default | unmodifiable e

mpty database

: postgres=CTc/postgres

template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres           | 7129 kB | pg_default | default templa

te for new databases

: postgres=CTc/postgres

(4 rows)

切换到t_pgdb 数据库

postgres=# \c t_pgdb

psql (8.4.18, server 9.5.3)

WARNING: psql version 8.4, server version 9.5.

Some psql features might not work.

You are now connected to database "t_pgdb".

t_pgdb=# CREATE TABLE t_table(id int primary key,name text);

CREATE TABLE

t_pgdb=# INSERT INTO t_table VALUES (1,'Andrew');

INSERT 0 1

t_pgdb=# INSERT INTO t_table VALUES (2,'Tonny');

INSERT 0 1

t_pgdb=# SELECT * from t_table ;

id |  name

----+--------

1 | Andrew

2 | Tonny

(2 rows)

9. 修改linux 系统用户postgres 的密码

PostgreSQL 数据库默认会创建一个linux 系统用户postgres,通过passwd 命令设置系统用户的密码为postgres

-bash-4.1$ exit

logout

[root@test02 bin]# passwd postgres

Changing password for user postgres.

New password:

BAD PASSWORD: it is based on a dictionary word

Retype new password:

passwd: all authentication tokens updated successfully.

修改postgresql.conf文件

如果想让PostgreSQL 监听整个网络的话,将listen_addresses 前的#去掉,并将 listen_addresses = 'localhost' 改成 listen_addresses = '*',因为localhost只允许本机连接,#开头的参数为默认配置

[root@test02 bin]# vim /var/lib/pgsql/9.5/data/postgresql.conf

listen_addresses = '*'

修改客户端认证配置文件pg_hba.conf

将需要远程访问数据库的IP地址或地址段加入该文件

host    all             all             0.0.0.0/0               md5

[root@test02 bin]# su - postgres

-bash-4.1$ service postgresql-9.5 restart

Stopping postgresql-9.5 service:                           [FAILED]

touch: cannot touch `/var/lock/subsys/postgresql-9.5': Permission denied

/etc/init.d/postgresql-9.5: line 170: /var/run/postgresql-9.5.pid: Permission denied

service postgresql-9.5 restart ( root用户执行)

[root@test02 9.5]# /etc/init.d/postgresql-9.5 restart

Stopping postgresql-9.5 service:                           [  OK  ]

Starting postgresql-9.5 service:                           [  OK  ]

/usr/pgsql-9.5/bin/pg_ctl -D /var/lib/pgsql/9.5/data/ stop

waiting for server to shut down.... done

server stopped

-bash-4.1$ /usr/pgsql-9.5/bin/pg_ctl -D /var/lib/pgsql/9.5/data/ start

server starting

-bash-4.1$ < 2016-06-02 23:49:28.415 CST >LOG:  redirecting log output to logging collector process

< 2016-06-02 23:49:28.415 CST >HINT:  Future log output will appear in directory "pg_log".

-bash-4.1$ ps hf -u postgres -o cmd

-bash

\_ ps hf -u postgres -o cmd

/usr/pgsql-9.5/bin/postgres -D /var/lib/pgsql/9.5/data

\_ postgres: logger process

\_ postgres: checkpointer process

\_ postgres: writer process

\_ postgres: wal writer process

\_ postgres: autovacuum launcher process

\_ postgres: stats collector process

-bash-4.1$ /usr/pgsql-9.5/bin/pg_ctl -D /var/lib/pgsql/9.5/data/ stop

waiting for server to shut down.... done

server stopped

[root@test02 bin]# rpm -qa|grep postgres

postgresql95-9.5.3-1PGDG.rhel6.x86_64

postgresql-8.4.18-1.el6_4.x86_64

postgresql-devel-8.4.18-1.el6_4.x86_64

postgresql95-server-9.5.3-1PGDG.rhel6.x86_64

postgresql95-contrib-9.5.3-1PGDG.rhel6.x86_64

postgresql-libs-8.4.18-1.el6_4.x86_64

postgresql95-libs-9.5.3-1PGDG.rhel6.x86_64

卸载(注意顺序)

[root@test02 bin]# rpm -e postgresql95-server-9.5.3-1PGDG.rhel6.x86_64

[root@test02 bin]# rpm -e postgresql95-contrib-9.5.3-1PGDG.rhel6.x86_64

[root@test02 bin]# rpm -e postgresql95-9.5.3-1PGDG.rhel6.x86_64

[root@test02 bin]# rpm -e postgresql95-libs-9.5.3-1PGDG.rhel6.x86_64

YUM

如果是默认yum 安装的话,会安装较低版本的PostgreSQL 8.4,这不符合我们的要求

我们使用PostgreSQL Yum Repository 来安装最新版本的PostgreSQL

To use the yum repository, you must first install the repository RPM. To do this, download the correct RPM from the repository RPM listing, and install it with commands like:

[root@test02 bin]# rpm -i https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

Once this is done, you can proceed to install and update packages the same way as the ones included in the distribution.

[root@test02 bin]# yum install postgresql95-server postgresql95-contrib

Loaded plugins: product-id, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

pgdg95                                                                                               | 3.7 kB     00:00

pgdg95/primary_db                                                                                    | 138 kB     00:01

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package postgresql95-contrib.x86_64 0:9.5.3-2PGDG.rhel6 will be installed

--> Processing Dependency: postgresql95-libs(x86-64) = 9.5.3-2PGDG.rhel6 for package: postgresql95-contrib-9.5.3-2PGDG.rhel6.x86_64

--> Processing Dependency: postgresql95(x86-64) = 9.5.3-2PGDG.rhel6 for package: postgresql95-contrib-9.5.3-2PGDG.rhel6.x86_64

--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql95-contrib-9.5.3-2PGDG.rhel6.x86_64

---> Package postgresql95-server.x86_64 0:9.5.3-2PGDG.rhel6 will be installed

--> Running transaction check

---> Package postgresql95.x86_64 0:9.5.3-2PGDG.rhel6 will be installed

---> Package postgresql95-libs.x86_64 0:9.5.3-2PGDG.rhel6 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================

Package                                Arch                     Version                               Repository                Size

======================================================================================================================================

Installing:

postgresql95-contrib                   x86_64                   9.5.3-2PGDG.rhel6                     pgdg95                   456 k

postgresql95-server                    x86_64                   9.5.3-2PGDG.rhel6                     pgdg95                   4.5 M

Installing for dependencies:

postgresql95                           x86_64                   9.5.3-2PGDG.rhel6                     pgdg95                   1.3 M

postgresql95-libs                      x86_64                   9.5.3-2PGDG.rhel6                     pgdg95                   205 k

Transaction Summary

======================================================================================================================================

Install       4 Package(s)

Total download size: 6.5 M

Installed size: 25 M

Is this ok [y/N]: y

Downloading Packages:

(1/4): postgresql95-9.5.3-2PGDG.rhel6.x86_64.rpm                                                               | 1.3 MB     00:27

(2/4): postgresql95-contrib-9.5.3-2PGDG.rhel6.x86_64.rpm                                                       | 456 kB     00:15

(3/4): postgresql95-libs-9.5.3-2PGDG.rhel6.x86_64.rpm                                                          | 205 kB     00:06

(4/4): postgresql95-server-9.5.3-2PGDG.rhel6.x86_64.rpm                                                        | 4.5 MB     01:32

--------------------------------------------------------------------------------------------------------------------------------------

Total                                                                                                  45 kB/s | 6.5 MB     02:26

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Warning: RPMDB altered outside of yum.

Installing : postgresql95-libs-9.5.3-2PGDG.rhel6.x86_64                                                                         1/4

Installing : postgresql95-9.5.3-2PGDG.rhel6.x86_64                                                                              2/4

Installing : postgresql95-contrib-9.5.3-2PGDG.rhel6.x86_64                                                                      3/4

Installing : postgresql95-server-9.5.3-2PGDG.rhel6.x86_64                                                                       4/4

Verifying  : postgresql95-contrib-9.5.3-2PGDG.rhel6.x86_64                                                                      1/4

Verifying  : postgresql95-server-9.5.3-2PGDG.rhel6.x86_64                                                                       2/4

Verifying  : postgresql95-libs-9.5.3-2PGDG.rhel6.x86_64                                                                         3/4

Verifying  : postgresql95-9.5.3-2PGDG.rhel6.x86_64                                                                              4/4

Installed:

postgresql95-contrib.x86_64 0:9.5.3-2PGDG.rhel6                    postgresql95-server.x86_64 0:9.5.3-2PGDG.rhel6

Dependency Installed:

postgresql95.x86_64 0:9.5.3-2PGDG.rhel6                         postgresql95-libs.x86_64 0:9.5.3-2PGDG.rhel6

Complete!

查看安装

[root@test02 bin]# rpm -qa|grep postgres

postgresql95-9.5.3-2PGDG.rhel6.x86_64

postgresql95-server-9.5.3-2PGDG.rhel6.x86_64

postgresql95-libs-9.5.3-2PGDG.rhel6.x86_64

postgresql95-contrib-9.5.3-2PGDG.rhel6.x86_64

初始化并启动数据库(root用户)

[root@test02 9.5]# /etc/init.d/postgresql-9.5 initdb

Initializing database:                                     [  OK  ]

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

Starting postgresql-9.5 service:                           [  OK  ]

[root@test02 9.5]# ps hf -u postgres -o cmd

/usr/pgsql-9.5/bin/postmaster -D /var/lib/pgsql/9.5/data

\_ postgres: logger process

\_ postgres: checkpointer process

\_ postgres: writer process

\_ postgres: wal writer process

\_ postgres: autovacuum launcher process

\_ postgres: stats collector process

[root@test02 9.5]# su - postgres

-bash-4.1$ psql

psql (9.5.3)

Type "help" for help.

postgres=# \l

List of databases

Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges

-----------+----------+----------+-------------+-------------+-----------------------

postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |

template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +

|          |          |             |             | postgres=CTc/postgres

template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +

|          |          |             |             | postgres=CTc/postgres

(3 rows)

源码安装

1.下载源代码

[root@test02 ~]# wget https://ftp.postgresql.org/pub/source/v9.5.3/postgresql-9.5.3.tar.gz

--2016-06-03 00:29:29--  https://ftp.postgresql.org/pub/source/v9.5.3/postgresql-9.5.3.tar.gz

Resolving ftp.postgresql.org... 174.143.35.246, 213.189.17.228, 217.196.149.55, ...

Connecting to ftp.postgresql.org|174.143.35.246|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 24134415 (23M) [application/x-gzip]

Saving to: ?.ostgresql-9.5.3.tar.gz?

100%[============================================================================================>] 24,134,415  37.3K/s   in 9m 58s

2016-06-03 00:39:29 (39.4 KB/s) - ?.ostgresql-9.5.3.tar.gz?.saved [24134415/24134415]

2.解压PostgreSQL源码包 :tar zxvf postgresql-9.2.4.tar.gz

或 tar jxvf postgresql-9.5.3.tar.bz2

3,切换到刚刚解压的目录下:cd postgresql-9.5.3

4. ./configure

如果遇到错误,则需要如下安装依赖工具包(按需安装)

yum install gcc

yum install readline

yum install flex

yum install zlib

在执行./configure

gmake world

gmake install-world

安装完毕

然后启动数据库

到安装目录(默认为/usr/local/postgres)

在该目录下建立data目录 (存放数据库相关文件)

启动数据库需要非root用户

/usr/local/pgsql//bin

初始化数据库

./initdb  -D ../data start

启动数据库

./pg_clt -D ../data start

启动后连接数据库:

在/usrl/local/pgsql/bin目录下

执行 ./psql 连接到默认的postgres数据

然后可以创建数据库,创建表,等操作了。

PostgreSQL run文件安装

[root@test01 home]# cd /opt/soft/

[root@test01 soft]# ll

total 97804

-rw-r--r--. 1 root root 38101062 May 27 17:57 postgresql-9.5.3-1-linux-x64.run

-rw-r--r--. 1 root root 37116313 May 27 18:05 postgresql-9.6.0-beta1-linux-x64.run

-rw-r--r--. 1  500  500 24925549 May 25 01:29 postgresql-9.6beta1.tar.gz

[root@test01 soft]# chmod +x postgresql-9.5.3-1-linux-x64.run

[root@test01 soft]# ll

total 97804

-rwxr-xr-x. 1 root root 38101062 May 27 17:57 postgresql-9.5.3-1-linux-x64.run

-rw-r--r--. 1 root root 37116313 May 27 18:05 postgresql-9.6.0-beta1-linux-x64.run

-rw-r--r--. 1  500  500 24925549 May 25 01:29 postgresql-9.6beta1.tar.gz

[root@test01 soft]# ./postgresql-9.5.3-1-linux-x64.run

or

[root@test01 soft]# ./postgresql-9.5.3-1-linux-x64.run  --mode text

......

PostgreSQL installations的更多相关文章

  1. Measuring PostgreSQL Checkpoint Statistics

    Checkpoints can be a major drag on write-heavy PostgreSQL installations. The first step toward ident ...

  2. roundup配置

    原因:我需要一个简单的issue tracker why roundup: python,简单 找了半天的文档,找不到文档,只能自己慢慢试,试到现在,可以打开tracker页面,用户注册的时候可以发邮 ...

  3. Freezing Your Tuples Off 之 vacuum_freeze_min_age

    The vacuum_freeze_min_age setting determines the youngest XID which will be changed to FrozenXID on ...

  4. shared memory segment exceeded your kernel's SHMMAX parameter

    http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server IpcMemoryCreate: shmget(key=5432001, s ...

  5. PostgreSQL源码安装文档

    This document describes the installation of PostgreSQL using the source    code distribution. (If yo ...

  6. postgresql 基本语法

    postgresql数据库创建/修改/删除等写入类代码语法总结: 1,创建库 2,创建/删除表 2.1 创建表 create table myTableName 2.2 如果表不存在则创建表 crea ...

  7. postgresql无法安装pldbgapi的问题

    要对函数进行调试需要安装插件pldbgapi,当初在windows上面的postgresql实例中执行了一下语句就安装上了: create extension pldbgapi; 但是在linux中执 ...

  8. ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库

    前段时间在园子里看到了小蝶惊鸿 发布的有关绿色版的Linux.NET——“Jws.Mono”.由于我对.Net程序跑在Linux上非常感兴趣,自己也看了一些有关mono的资料,但是一直没有时间抽出时间 ...

  9. MongoDB与PostgresQL无责任初步测试

    PostgresQL一秒能插入多少条记录,MongoDB呢?读取的情况又如何?我写了一些简单的程序,得出了一些简单的数据,贴在这里分享,继续往下阅读前请注意下本文标题中的“无责任”,这表示此测试结果不 ...

随机推荐

  1. jmeter仅一次控制器

    仅针对 1个线程的 多线程的那个不生效  想实现多次执行某个请求只执行一次 需要设置为单线程 循环次数设置为多次就可以了 

  2. NOI 题库 6264

    6264  走出迷宫 描述 当你站在一个迷宫里的时候,往往会被错综复杂的道路弄得失去方向感,如果你能得到迷宫地图,事情就会变得非常简单. 假设你已经得到了一个n*m的迷宫的图纸,请你找出从起点到出口的 ...

  3. NOI 题库 7084

    7084  迷宫问题 描述 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, ...

  4. eclipse安装maven

    maven3 安装: 安装 Maven 之前要求先确定你的 JDK 已经安装配置完成.Maven是 Apache 下的一个项目, 首先去官网下载 Maven: 下载完成之后将其解压,解压后的文件夹重命 ...

  5. HDU1541 树状数组

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. 《UML大战需求分析》阅读笔记04

    在学习了前面的几种UML图并不能满足所有情况的建模,如当流程图涉及到多种角色,并且通过对多种角色交互展开时,顺序图才是不二选择.顺序图就如同中文语法的说话语言相似,描述的是一种事件发生的顺序.顺序图分 ...

  7. spring接收json格式的多个对象参数(变通法)

    两种方法 方法1 如果使用spring mvc同客户端通信,完全使用json数据格式,需要如下定义一个RequestMapping @Controller public class TestContr ...

  8. 用js加密你的重要信息

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. Oracle知识分类之常见规范

    命名规范 变量规范 1.入参,统一以I_前缀开头,且不能省略IN 2.出参,统一以O_前缀开头 3.局部变量,统一以V_前缀开头 4.常量,统一以CN_前缀开头 5.游标,统一以CUR_前缀开头 组成 ...

  10. 两个NOI题目的启迪8皇后和算24

    论出于什么原因和目的,学习C++已经有一个星期左右,从开始就在做NOI的题目,到现在也没有正式的看<Primer C++>,不过还是受益良多,毕竟C++是一种”低级的高级语言“,而且NOI ...