PostgreSQL源码安装

1、安装前准备
1.1、主机硬件配置
4G内存,40G磁盘

1.2、配置OS内核参数
kernel.shmall、kernel.shmmax、kernel.shmmni共享内存相关参数,在9.2以及以前的版本,数据库启动时,对共享内存段的内存需求非常大。后期版本要求不大,但可参考此设置。
1.3、配置OS资源限制

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 500000000
  • hard memlock 500000000
    1.4、配置OS防火墙
    iptables -F

1.5、selinux
如果没这方面需求,建议关闭。

vi /etc/sysconfig/selinux

SELINUX=disabled
SELINUXTYPE=targeted
1.6、创建用户
useradd pg12

2、数据库安装
2.1、下载postgresql源码
前往https://www.postgresql.org/ftp/source/ ,下载相关源码包

2.2、安装postgresql
安装依赖包:
root用户下,使用yum 安装依赖包

yum -y install coreutils glib2 lrzsz mpstat dstat sysstat e4fsprogs xfsprogs ntp readline-devel zlib-devel openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc make smartmontools flex bison perl-devel perl-Ext
Utils* openldap-devel jadetex openjade bzip2
编译安装postgresql:
pg12用户下,编译安装PostgreSQL,

su - pg12
[pg12@oracle ~]$ tar -jxvf postgresql-12beta2.tar.bz2
[pg12@oracle ~]$ cd postgresql-12.2
[pg12@oracle postgresql-12.2]$ ./configure --prefix=/home/pg12/pgsql12.2 --with-perl --with-python
[pg12@oracle postgresql-12.2]$ make world -j 8
[pg12@oracle postgresql-12.2]$ make install-world
注: 如果不需要调用perl和python编写函数,可以不添加—with-perl —with-python。

2.3、配置linux用户环境变量
在pg12用户下配置环境变量:

su - pg12
vi ~/.bash_profile

追加

export PS1="$USER@/bin/hostname -s-> "

export PGPORT=1921
export PGDATA=/home/pg12/pgdata
export LANG=en_US.utf8
export PGHOME=/home/pg12/pgsql12.2
export LD_LIBRARY_PATH= P G H O M E / l i b : / l i b 64 : / u s r / l i b 64 : / u s r / l o c a l / l i b 64 : / l i b : / u s r / l i b : / u s r / l o c a l / l i b : PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib: PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:LD_LIBRARY_PATH

export PATH= P G H O M E / b i n : PGHOME/bin: PGHOME/bin:PATH:.

export DATE=date +"%Y%m%d%H%M"
export MANPATH= P G H O M E / s h a r e / m a n : PGHOME/share/man: PGHOME/share/man:MANPATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres
alias rm=‘rm -i’
alias ll=‘ls -lh’

使环境变量生效:
[pg12@oracle ~]$ source ~/.bash_profile

2.4、初始化数据库集群
pg12@oracle-> cd pgsql12,2/bin/

pg12@oracle-> initdb -D $PGDATA -E UTF8 —locale=C -U postgres

2.5、配置数据库
配置文件在$PGDATA目录中
pg12@oracle-> vi postgresql.conf

追加

listen_addresses = ‘0.0.0.0’
port = 1921
max_connections = 200
unix_socket_directories = ‘.’
tcp_keepalives_idle = 60
tcp_keepalives_interval = 10
tcp_keepalives_count = 10
shared_buffers = 512MB
dynamic_shared_memory_type = posix
vacuum_cost_delay = 0
bgwriter_delay = 10ms
bgwriter_lru_maxpages = 1000
bgwriter_lru_multiplier = 10.0
bgwriter_flush_after = 0
old_snapshot_threshold = -1
backend_flush_after = 0
wal_level = replica
synchronous_commit = off
full_page_writes = on
wal_buffers = 16MB
wal_writer_delay = 10ms
wal_writer_flush_after = 0
checkpoint_timeout = 30min
max_wal_size = 2GB
min_wal_size = 128MB
checkpoint_completion_target = 0.05
checkpoint_flush_after = 0
random_page_cost = 1.3
log_destination = ‘csvlog’
logging_collector = on
log_truncate_on_rotation = on
log_checkpoints = on
log_connections = on
log_disconnections = on
log_error_verbosity = verbose
autovacuum = on
log_autovacuum_min_duration = 0
autovacuum_naptime = 20s
autovacuum_vacuum_scale_factor = 0.05
autovacuum_freeze_max_age = 1500000000
autovacuum_multixact_freeze_max_age = 1600000000
autovacuum_vacuum_cost_delay = 0
vacuum_freeze_table_age = 1400000000
vacuum_multixact_freeze_table_age = 1500000000
datestyle = ‘iso, mdy’
timezone = ‘PRC’
lc_messages = ‘C’
lc_monetary = ‘C’
lc_numeric = ‘C’
lc_time = ‘C’
default_text_search_config = ‘pg_catalog.english’
shared_preload_libraries=‘pg_stat_statements’
配置pg_hba.conf:

pg12@oracle-> vi pg_hba.conf
追加
host all all 0.0.0.0/0 md5
2.6、启动数据库集群
pg12@oracle-> pg_ctl start
看到提示’server started’则表示启动成功。

2.7、连接数据库
pg12@oracle-> psql
psql (12beta2)
Type “help” for help.

postgres=#\l

你可能感兴趣的:(postgresql)