源码安装postgresql9.5.1

一.下载
在官网下载软件,我选择的是最新的版本进行安装postgresql95,地址如下:
下载源码.tar.gz的软件包
二.进行解压缩
    
    
[root@pg1 soft]# tar zxvf postgresql-9.5.1.tar.gz
.....
.....
.....
postgresql-9.5.1/doc/src/sgml/problems.sgml
postgresql-9.5.1/doc/src/sgml/arch-dev.sgml
postgresql-9.5.1/doc/src/sgml/pageinspect.sgml
postgresql-9.5.1/doc/src/sgml/info.sgml
postgresql-9.5.1/doc/src/sgml/installation.sgml
postgresql-9.5.1/doc/src/sgml/xplang.sgml
postgresql-9.5.1/doc/src/Makefile
postgresql-9.5.1/doc/KNOWN_BUGS
postgresql-9.5.1/doc/Makefile
postgresql-9.5.1/doc/TODO
postgresql-9.5.1/doc/MISSING_FEATURES
postgresql-9.5.1/doc/bug.template
postgresql-9.5.1/HISTORY
postgresql-9.5.1/Makefile
postgresql-9.5.1/README
postgresql-9.5.1/COPYRIGHT
postgresql-9.5.1/GNUmakefile.in
postgresql-9.5.1/.gitattributes
postgresql-9.5.1/aclocal.m4
postgresql-9.5.1/configure.in
postgresql-9.5.1/INSTALL
三.开始安装
进入解压缩的目录,可以执行./configure --help查看配置选项,--prefix指定安装目录,因为我最近在学习python,所以我把python插件也安装上了
    
    
[root@pg1 postgresql-9.5.1]# ./configure --prefix=/usr/local/pgsql95 --with-python
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit integer date/time support... yes
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
...
...
安装使用gmake world 和gmake install-world,带上world关键字会把一些第三方的插件也安装上,建议带上world,如果一开始没有安装上,可以手工在解压缩目录下的contrib目录下执行make&&make install
    
    
[root@pg1 postgresql-9.5.1]# gmake world && gmake install-world
...
...
...
gmake[2]: Leaving directory `/root/soft/postgresql-9.5.1/contrib/unaccent'
gmake -C vacuumlo install
gmake[2]: Entering directory `/root/soft/postgresql-9.5.1/contrib/vacuumlo'
/bin/mkdir -p '/usr/local/pgsql95/bin'
/usr/bin/install -c vacuumlo '/usr/local/pgsql95/bin'
gmake[2]: Leaving directory `/root/soft/postgresql-9.5.1/contrib/vacuumlo'
gmake -C hstore_plpython install
gmake[2]: Entering directory `/root/soft/postgresql-9.5.1/contrib/hstore_plpython'
/bin/mkdir -p '/usr/local/pgsql95/lib'
/bin/mkdir -p '/usr/local/pgsql95/share/extension'
/bin/mkdir -p '/usr/local/pgsql95/share/extension'
/usr/bin/install -c -m 755 hstore_plpython2.so '/usr/local/pgsql95/lib/hstore_plpython2.so'
/usr/bin/install -c -m 644 ./hstore_plpythonu.control ./hstore_plpython2u.control ./hstore_plpython3u.control '/usr/local/pgsql95/share/extension/'
/usr/bin/install -c -m 644 ./hstore_plpythonu--1.0.sql ./hstore_plpython2u--1.0.sql ./hstore_plpython3u--1.0.sql '/usr/local/pgsql95/share/extension/'
gmake[2]: Leaving directory `/root/soft/postgresql-9.5.1/contrib/hstore_plpython'
gmake -C ltree_plpython install
gmake[2]: Entering directory `/root/soft/postgresql-9.5.1/contrib/ltree_plpython'
/bin/mkdir -p '/usr/local/pgsql95/lib'
/bin/mkdir -p '/usr/local/pgsql95/share/extension'
/bin/mkdir -p '/usr/local/pgsql95/share/extension'
/usr/bin/install -c -m 755 ltree_plpython2.so '/usr/local/pgsql95/lib/ltree_plpython2.so'
/usr/bin/install -c -m 644 ./ltree_plpythonu.control ./ltree_plpython2u.control ./ltree_plpython3u.control '/usr/local/pgsql95/share/extension/'
/usr/bin/install -c -m 644 ./ltree_plpythonu--1.0.sql ./ltree_plpython2u--1.0.sql ./ltree_plpython3u--1.0.sql '/usr/local/pgsql95/share/extension/'
gmake[2]: Leaving directory `/root/soft/postgresql-9.5.1/contrib/ltree_plpython'
gmake[1]: Leaving directory `/root/soft/postgresql-9.5.1/contrib'
PostgreSQL, contrib, and documentation installation complete.
四.创建用户
默认超级用户是不能启动pg的所以需要创建一个普通用户来启动数据库
    
    
[root@pg1 lib]# useradd postgres
修改postgres用户的环境变量,并且记得将pg的数据目录所属改成postgres
    
    
export PGPORT=5432
export PGDATA=/pgdata
export LANG=en_US
export PGHOME=/usr/local/pgsql95
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres
使用postgres用户登录系统,查看环境变量是否正确,输入psql -V查看pg的版本
    
    
[postgres@pg1 ~]$ which psql
/usr/local/pgsql95/bin/psql
[postgres@pg1 ~]$ psql -V
psql (PostgreSQL) 9.5.1
五.初始化数据库
使用initdb来初始化数据库,可以使用initdb --help查看选项
initdb -D $PGDATA  -E UTF8 --locale=C  -U postgres  -W
其中-D指定数据目录,-E指定字符集,-locale指定区域,-U指定用户,-W指定密码,在初始化的时候会让你输入密码
    
    
[postgres@pg1 ~]$ initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
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 "C".
The default text search configuration will be set to "english".
 
Data page checksums are disabled.
 
fixing permissions on existing directory /pgdata ... initdb: could not change permissions of directory "/pgdata": Operation not permitted
[postgres@pg1 ~]$ id postgres
uid=500(postgres) gid=500(postgres) groups=500(postgres)
[postgres@pg1 ~]$ initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
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 "C".
The default text search configuration will be set to "english".
 
Data page checksums are disabled.
 
fixing permissions on existing directory /pgdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /pgdata/base/1 ... ok
initializing pg_authid ... ok
Enter new superuser password:
Enter it again:
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... 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 /pgdata -l logfile start
进入到初始化指定的数据文件目录,就可以看到pg的目录结构
    
    
[root@pg1 local]# su - postgres
ls[postgres@pg1 ~]$ ls
[postgres@pg1 ~]$ cd /pgdata
[postgres@pg1 pgdata]$ ls -l
total 112
drwx------. 5 postgres postgres 4096 Feb 24 20:39 base
drwx------. 2 postgres postgres 4096 Feb 24 20:39 global
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_clog
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_commit_ts
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_dynshmem
-rw-------. 1 postgres postgres 4468 Feb 24 20:39 pg_hba.conf
-rw-------. 1 postgres postgres 1636 Feb 24 20:39 pg_ident.conf
drwx------. 4 postgres postgres 4096 Feb 24 20:39 pg_logical
drwx------. 4 postgres postgres 4096 Feb 24 20:39 pg_multixact
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_notify
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_replslot
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_serial
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_snapshots
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_stat
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_stat_tmp
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_subtrans
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_tblspc
drwx------. 2 postgres postgres 4096 Feb 24 20:39 pg_twophase
-rw-------. 1 postgres postgres 4 Feb 24 20:39 PG_VERSION
drwx------. 3 postgres postgres 4096 Feb 24 20:39 pg_xlog
-rw-------. 1 postgres postgres 88 Feb 24 20:39 postgresql.auto.conf
-rw-------. 1 postgres postgres 21673 Feb 24 20:39 postgresql.conf
base目录:表空间目录
global:全局变量
pg_hba.conf:访问控制配置

六.配置数据库
关闭防火墙和selinux
pg_hba.conf用于配置控制访问数据库的来源
postgresql.conf是pg的主配置文件
像oracle一样,最好也调整一下linux内核参数,添加sysctl.conf文件的配置
    
    
[root@pg1 postgresql-9.5.1]# vi /etc/sysctl.conf
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
kernel.shmmni = 4096
kernel.sem = 50100 64128000 50100 1280
fs.file-max = 7672460
net.ipv4.ip_local_port_range = 9000 65000
net.core.rmem_default = 1048576
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
[root@pg1 postgresql-9.5.1]# sysctl -p
同样配置limits.conf
    
    
[root@pg1 postgresql-9.5.1]# vi /etc/security/limits.conf
* soft nofile 131072
* hard nofile 131072
* soft nproc 131072
* hard nproc 131072
* soft core unlimited
* hard core unlimited
* soft memlock 50000000
* hard memlock 50000000
配置pg_hba.conf,默认是只允许本地访问pg,添加如下允许所有的ip访问所有的database
host all all 0.0.0.0/0 md5
配置postgresql.conf,最简单的配置需要配置监听端口号和ip地址如下:
    
    
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
七.启动连接数据库
使用pg_ctl start启动数据,如果一开始初始化的时候没有指定数据文件位置,启动需要指定数据文件位置
pg_ctl start -D $PGDATA
    
    
[postgres@pg1 ~]$ pg_ctl start
server starting
[postgres@pg1 ~]$ LOG: database system was shut down at 2016-02-24 20:39:35 CST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
启动完成之后就可以使用psql连接数据库了
    
    
[postgres@pg1 ~]$ psql
psql (9.5.1)
Type "help" for help.
postgres=# \db List of tablespaces Name | Owner | Location ------------+----------+---------- pg_default | postgres | pg_global | postgres | (2 rows)
postgres=# \q
[postgres@pg1 ~]$
停止 pg使用:
pg_ctl stop -m fast 或者指定数据文件位置:
pg_ctl stop -D $PGDATA -m fast
停止选项有三种分别为:fast,smart,immediate

其中fast类似于oracle中的immediate
smart类似于oracle中的normal
immediate类似于oracle中的abort









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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值