码迷,mamicode.com
首页 > 数据库 > 详细

postgresql9.5编译安装体验

时间:2019-10-28 23:53:18      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:mit   cti   host   createdb   dia   centos7   service   database   ice   

实验环境:

  • centos7.6
  • pgsql9.5 源码编译安装

实验目的:

体验源码编译安装pgsql

01、download

https://ftp.postgresql.org/pub/source/v9.5.19/postgresql-9.5.19.tar.bz2

02、requirement

yum install -y ncurses-devel readline-devel zlib-devel

03、add_user postgres && pgdata

useradd postgres
mkdir  -p /pgdata/{data,archive}    //创建数据及归档存储目录

su - postgres   //配置环境变量
tee <<-‘EOF‘ >>.bash_profile
export PGHOME=/pgdata
export PGDATA=/pgdata/data
export PATH=$PGHOME/bin:$PATH
export LD_LIBRARY_PATH=$PGHOME/lib
EOF
source .bash_profile

04、compile/setup

[root@lab-250 ~]# tar jxf postgresql-9.5.19.tar.bz2      //解压
[root@lab-250 ~]# cd postgresql-9.5.19
[root@lab-250 postgresql-9.5.19]#

[root@lab-210 postgresql-9.5.19]# ./configure --help    //查看编译参数
./configure   -q --prefix=/pgdata
make -s -j2
make -s  install

//ignore warning
Without Bison you will not be able to build PostgreSQL from Git
chown -R postgres:postgres /pgdata

05、init pgsql_instance

su - postgres
initdb -A md5 -U postgres -W  -E ‘utf-8‘ -D $PGDATA

###更加颗粒度,设置super user pwd
initdb --auth=trust --auth-host=md5 --auth-local=trust \
--pgdata=$PGDATA --encoding=‘UTF-8‘ \
--username=postgres --pwprompt

[postgres@lab-210 ~]$ initdb --help    //查看帮助
initdb initializes a PostgreSQL database cluster.
Usage:
initdb [OPTION]... [DATADIR]
Options:
-A, --auth=METHOD default authentication method for local connections
--auth-host=METHOD default authentication method for local TCP/IP connections
--auth-local=METHOD default authentication method for local-socket connections
[-D, --pgdata=]DATADIR location for this database cluster
-E, --encoding=ENCODING set default encoding for new databases
-U, --username=NAME database superuser name
-W, --pwprompt prompt for a password for the new superuser
....

 

pg_ctl -D /pgdata/data -l logfile start    //启动pgsql -D 默认读取$PGDATA
pg_ctl start
ps -ef | grep postgres //查看pgsql进程
pg_ctl status //查看数据状态
pg_ctl stop -m fast //停止数据库

[postgres@lab-210 ~]$ pg_ctl --help     //查看参数
pg_ctl is a utility to initialize, start, stop, or control a PostgreSQL server.
Usage:
pg_ctl init[db] [-D DATADIR] [-s] [-o "OPTIONS"]
pg_ctl start [-w] [-t SECS] [-D DATADIR] [-s] [-l FILENAME] [-o "OPTIONS"]
pg_ctl stop [-W] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
pg_ctl restart [-w] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
[-o "OPTIONS"]
pg_ctl reload [-D DATADIR] [-s]
pg_ctl status [-D DATADIR]
pg_ctl promote [-D DATADIR] [-s]
pg_ctl kill SIGNALNAME PID

Common options:
-D, --pgdata=DATADIR location of the database storage area
-s, --silent only print errors, no informational messages
-t, --timeout=SECS seconds to wait when using -w option
-V, --version output version information, then exit
-w wait until operation completes
-W do not wait until operation completes
-?, --help show this help, then exit
(The default is to wait for shutdown, but not for start or restart.)

If the -D option is omitted, the environment variable PGDATA is used.

Options for start or restart:
-c, --core-files allow postgres to produce core files
-l, --log=FILENAME write (or append) server log to FILENAME
-o OPTIONS command line options to pass to postgres
(PostgreSQL server executable) or initdb
-p PATH-TO-POSTGRES normally not necessary

Options for stop or restart:
-m, --mode=MODE MODE can be "smart", "fast", or "immediate"

Shutdown modes are:
smart quit after all clients have disconnected
fast quit directly, with proper shutdown
immediate quit without complete shutdown; will lead to recovery on restart

06、express pgsql

createdb test
psql test
test=#
help

07、开启归档及日志记录

技术图片

###追加到配置文件中

tee <<-‘EOF‘ >> postgresql.auto.conf
listen_addresses = ‘*‘
port = 5432
wal_level = hot_standby
archive_mode = on
archive_command = ‘cp %p /pgdata/archive/%f‘
#max_wal_senders = 10
logging_collector = on
EOF

技术图片

 08、设置为service管理postgres

###脚本在源码编译的位置存放

技术图片

 copy到init.d/及给予权限

技术图片

 修改prefix/pgdata

技术图片

 启动验证

技术图片

postgresql9.5编译安装体验

标签:mit   cti   host   createdb   dia   centos7   service   database   ice   

原文地址:https://www.cnblogs.com/xiaochina/p/11756154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!