PG12 编译安装

安装 PG 12

  • root用户下安装依赖包

    * 卸载多余的rpm包
    rpm -qa | grep postgresql
    比如结果为postgresql-libs-8.4.20-8.el6_9.x86_64
    则 rpm -e postgresql-libs-8.4.20-8.el6_9.x86_64
    
    * 安装 rpm 包
    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-ExtUtils* openldap-devel jadetex  openjade bzip2 
    

目录规划

/postgresql/

​ |–> postgres-12.3

​ |–> pg12

​ |–> pgsql

​ |–> data

​ |–> pg_log

​ |–> pg 软连接到 pgsql12

创建目录并编译安装PG

# 创建目录
userdel -r pgsql
useradd pgsql

# 创建目录
mkdir -p /postgresql/pg12/{pgsql,data,pg_log,archive_log}
ln -s /postgresql/pg12 /postgresql/pg


# 解压安装包
tar zxvf /home/postgres/postgresql-12.3.tar.gz -C /postgresql
chmod -R 755 /postgresql/postgresql-12.3

# 编译安装
cd /postgresql/postgresql-12.3
./configure --prefix=/postgresql/pg/pgsql --with-python && make world -j 8  && make install-world
chown -R pgsql.pgsql /postgresql


设置环境变量

  • su - pgsql

  • vim .bash_profile追加如下内容

export PS1="$USER@`/bin/hostname -s`-> "  
export PGPORT=5432  
export LANG=en_US.utf8  
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH  
export PGHOME=/postgresql/pg12/pgsql
export PGDATA=/postgresql/pg12/data
export PGHOST=$PGDATA
export PATH=$PGHOME/bin:$PATH:.  
export DATE=`date +"%Y%m%d%H%M"`  
export MANPATH=$PGHOME/share/man:$MANPATH  
export PGUSER=postgres  
export PGDATABASE=postgres  
alias ll='ls -lh'
  • source .bash_profile

  • 初始化数据库集群

    initdb -D $PGDATA -E UTF8 --locale=C -U postgres 
    
  • vim $PGDATA/postgresql.conf 追加

    listen_addresses = '0.0.0.0'  
    port = 5432  
    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'  
    
    
    log_directory = '/postgresql/pg/pg_log'                 # directory where log files are written,
    
    
  • 配置pg_hba.conf: vim $PGDATA/pg_hba.conf 追加

    host all all 0.0.0.0/0 md5  
    
    
  • 启动PG

    pg_ctl start
    
  • 设置密码

    psql -c "alter user postgres with password 'passwd';"
    
    
  • 设置需要密码登录

    sed -i 's/trust/md5/g' /postgresql/pg12/data/pg_hba.conf
    pg_ctl restart
    psql
    

你可能感兴趣的:(PostgreSQL)