Centos7下Postgresql源码编译安装

(一)Installation Procedure
(1) Install wget and gcc
yum -y install wget
yum -y install gcc

#####################################################
(2) Set path, download and decompress install files
[root@localhost My_Softwares]# mkdir Postgresql
[root@localhost My_Softwares]# cd Postgresql
[root@localhost Postgresql]# mkdir Source Build Install Data
[root@localhost Postgresql]# cd Source
[root@localhost Source]# wget https://ftp.postgresql.org/pub/source/v10.2/postgresql-10.2.tar.gz
[root@localhost Source]# tar -zxvf postgresql-10.2.tar.gz
[root@localhost Source]# dir
postgresql-10.2  postgresql-10.2.tar.gz
[root@localhost Source]# cd postgresql-10.2
[root@localhost postgresql-10.2]# ls
aclocal.m4  configure     contrib    doc             HISTORY  Makefile  src
config      configure.in  COPYRIGHT  GNUmakefile.in  INSTALL  README
[root@localhost postgresql-10.2]# 

#####################################################
(3) Set compile path and compile
[root@localhost Build]# ../Source/postgresql-10.2/configure --prefix=/home/My_Softwares/Postgresql/Install

configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

[root@localhost Build]# yum -y install readline

Package readline-6.2-10.el7.x86_64 already installed and latest version
Nothing to do

[root@localhost Build]# yum search readline
[root@localhost Build]# yum install readline-devel.x86_64

#####################################################
[root@localhost Build]# ../Source/postgresql-10.2/configure --prefix=/home/My_Softwares/Postgresql/Install

configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.

[root@localhost Build]# yum -y install zlib 
Package zlib-1.2.7-17.el7.x86_64 already installed and latest version
Nothing to do

[root@localhost Build]# yum -y search zlib
[root@localhost Build]# yum -y install zlib-devel.x86_64

#####################################################
(4) Make and Install
[root@localhost Build]# make -j8
[root@localhost Build]# make install -j8




#####################################################
#####################################################
(二) Set 
(1) set environment variables
[root@localhost Build]# vim /etc/profile 
export PATH=$PATH:/home/My_Softwares/Postgresql/Install/bin
[root@localhost Build]# source /etc/profile 
[root@localhost Build]# 

#####################################################
(2) add Centos7 system user and give permission
[root@localhost Build]# groupadd postgres
[root@localhost Build]# useradd -g postgres postgres
[root@localhost Build]# passwd postgres

chown -R postgres:postgres /home/My_Softwares/Postgresql/Data
chmod -R 0700 /home/My_Softwares/Postgresql/Data

#####################################################
(3) initial database
[postgres@localhost Build]$ initdb
initdb: no data directory specified
You must identify the directory where the data for this database system
will reside.  Do this with either the invocation option -D or the
environment variable PGDATA.
[postgres@localhost Build]$ initdb --help
initdb initializes a PostgreSQL database cluster.
Usage:
  initdb [OPTION]... [DATADIR]
Options:
  -D, --pgdata=]DATADIR     location for this database cluster

[postgres@localhost Build]$ initdb -D /home/My_Softwares/Postgresql/Data

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /home/My_Softwares/Postgresql/Data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /home/My_Softwares/Postgresql/Data -l logfile start

#####################################################
(4) start the database server
[postgres@localhost Data]$ pg_ctl -D /home/My_Softwares/Postgresql/Data -l logfile start
waiting for server to start.... done
server started
[postgres@localhost Data]$ su




#####################################################
#####################################################
(三) Use
(1)
[postgres@localhost Data]$ psql
psql (10.2)
Type "help" for help.

postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
postgres=# 

(2) create database user postgresql_zlf
postgres-# CREATE USER postgresql_zlf WITH PASSWORD '123';

(3) creare database for database user
postgres-# CREATE DATABASE Hllo_Postgresql OWNER postgresql_zlf

(4) grant all privileges of database to database user 
postgres-# GRANT ALL PRIVILEGES ON DATABASE Hllo_Postgresql TO postgresql_zlf


(5) create table
create table test( id integer,name varchar(32) )











  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值