postgresql 9.3.1 编译安装

postgresql 9.3.1 编译安装

1 编译、安装
tar -xvf postgresql-9.3.1.tar 
cd postgresql-9.3.1
./configure --prefix=/opt/soft/postgresql-9.3.1/ --with-perl --with-python --with-blocksize=32 --with-wal-blocksize=32 --with-wal-segsize=64
make
make install
 
2 创建用户及组
groupadd postgres
useradd -g postgres postgres
passwd postgres


3 环境设置
 mkdir /usr/local/pgsql/data
 chown postgres:postgres -R /usr/local/pgsql/
 su - postgres
 vi .bash_profile
 添加:
export PGHOME=/usr/local/pgsql
export PGDATA=$PGHOME/data
export PATH=$PATH:$HOME/bin:$PGHOME/bin
 $source .bash_profile
 
4 初始化数据库
 $initdb -D $PGDATA

5 启动postgres数据库
pg_ctl -D /usr/local/pgsql/data start 


6 系统服务配置及开机自动启动
cd /opt/soft/postgresql-9.3.1/contrib/start-scripts
 cp linux /etc/init.d/postgresql
 #chmod u+x /etc/init.d/postgresql
 #service postgresql status--(start | stop)

7 修改postgres数据库为归档模式
vi postgresql.conf
wal_level = archive
# - Archiving -

archive_mode = on               # allows archiving to be done
                                # (change requires restart)
archive_command = 'cp %p /usr/local/pgsql/archive/%f'           # command to use to archive a logfile segment
                                # placeholders: %p = path of file to archive
                                #               %f = file name only
                                # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
#archive_timeout = 0            # force a logfile segment switch after this
                                # number of seconds; 0 disables
# - Archiving -

archive_mode = on               # allows archiving to be done
                                # (change requires restart)
archive_command = 'cp %p /usr/local/pgsql/archive/%f'           # command to use to archive a logfile segment
                                # placeholders: %p = path of file to archive
                                #               %f = file name only
                                # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
#archive_timeout = 0            # force a logfile segment switch after this
                                # number of seconds; 0 disables
##切换归档
select pg_switch_xlog();
这个时候我们到归档日志的目录下去查看有没有归档日志生成
[09:39:25 postgres()@kiwi archive]$ ls
000000010000000000000001

其中archive_command中%p会自动识别为WAL目录,你不用管,%f你也不用管。这个archive_command在什么时候执行呢,即PostgreSQL在每次WAL日志16MB段满的时候才执行,即把其拷贝到/home/postgres/archive中.

此外,为了数据的安全性,我们还需要设置如下的参数

fsync = on
synchronous_commit = on
full_page_writes = on

关于这几个参数的测试,我们可以参考这篇博客

http://francs3.blog.163.com/blog/static/405767272015929115825898/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值