PostgreSQL 11学习笔记(一):在Centos7.5上yum安装和编译安装PG11

一、修改主机名

hostnamectl set-hostname pgsql

二、关闭selinux

vim /etc/selinux/config
修改内容:
SELINUX=disabled
#SELINUXTYPE=targeted

三、创建用户

groupadd postgres
useradd -g postgres postgres
passwd postgres

四、创建目录

mkdir -p /mnt/db1/pgdata/pgsql /mnt/db1/pgdata/pgtbs /mnt/db1/archivelog /backups
chmod -R 775 /mnt/db1
chown -R postgres:postgres /mnt/db1

五、安装依赖包

yum install -y gcc gcc-c++  epel-release llvm5.0 llvm5.0-devel clang libicu-devel perl-ExtUtils-Embed zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel openldap-devel systemd-devel tcl-devel python-devel
yum install -y llvm5.0 llvm5.0-devel

六、yum安装

yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
yum install -y postgresql11*

七、编译安装

wget https://ftp.postgresql.org/pub/source/v11.0/postgresql-11.0.tar.gz
tar -zxvf postgresql-11.0.tar.gz
mkdir -p postgresql-11.0/build_dir
cd postgresql-11.0/build_dir

vim ../src/Makefile.global.in
修改以下行:
COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
修改为:
COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -emit-llvm -c

../configure --prefix=/usr/pgsql-11 --enable-nls --with-perl --with-python --with-tcl --with-gssapi --with-llvm LLVM_CONFIG='/usr/lib64/llvm5.0/bin/llvm-config' --with-icu --with-openssl --with-pam --with-ldap --with-systemd --with-libxml --with-libxslt
make world
make install

八、设置启动配置

注:如果是yum安装只要修改PGDATA的路径

vim /usr/lib/systemd/system/postgresql-11.service
添加内容:
[Unit]
Description=PostgreSQL 11 database server
Documentation=https://www.postgresql.org/docs/11/static/
After=syslog.target
After=network.target

[Service]
Type=notify
User=postgres
Group=postgres
Environment=PGDATA=/mnt/db1/pgdata/pgsql/
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
ExecStart=/usr/pgsql-11/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target

九、设置环境变量

vi /home/postgres/.bash_profile
添加内容:
export PGPORT=8432
export PGHOME=/usr/pgsql-11
export PGDATA=/mnt/db1/pgdata/pgsql
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.UTF-8
export DATE='date +"%Y%m%d%H%M"'
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres

十、初始化数据库

su - postgres
initdb -D $PGDATA -U postgres --locale=en_US.UTF8 -E UTF8

十一、修改数据库参数

vim /mnt/db1/pgdata/pgsql/postgresql.conf
修改内容:
listen_addresses = '*'
unix_socket_directories = '.'
port = 8432
vim /mnt/db1/pgdata/pgsql/pg_hba.conf
添加内容:
host all all 0.0.0.0/0 md5 # 其他用户登陆

十二、设置防火墙规则

exit #切换回root用户
firewall-cmd --zone=public --add-port=8432/tcp --permanent
firewall-cmd --reload

十三、设置开机自启动

systemctl enable postgresql-11.service
systemctl start postgresql-11.service

十四、设置postgres密码

su - postgres
psql
ALTER USER postgres WITH encrypted PASSWORD 'postgres';

 

 

 

 

 

你可能感兴趣的:(PostgreSQL,DBA)