实验环境:

  • 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

启动验证

最新文章

  1. mysql插入多条数据时间复杂度比较
  2. 0-1背包问题python解决
  3. PHP对图片按照一定比例缩放并生成图片文件
  4. 【linux】find删除指定时间之前的文件
  5. Android权限安全(1)自定义,检查,使用权限
  6. jquery获取对象
  7. ApplePay扩大全球发卡行合作,“苹果税”撑不住了?
  8. Source Insight 技巧总结
  9. ios音频视频资料--备用
  10. [转] java中注解的使用与实例
  11. ESFramework 通信框架安全机制的设计与实现
  12. Flutter获取屏幕宽高和Widget大小
  13. 2019南昌邀请赛网络预选赛 J.Distance on the tree(树链剖分)
  14. EXCEL(1)级联下拉框
  15. css3 的calc
  16. Qt中窗口退出事件
  17. IntelliJ IDEA(Ultimate版本)的下载、安装和WordCount的初步使用(本地模式和集群模式)
  18. 使用Autolayout xib实现动态高度的TableViewCell
  19. mysql的innodb存储引擎和myisam存储引擎的区别
  20. Win7删除远程连接历史记录

热门文章

  1. 转载-mysql中文编码问题
  2. valgrind memcheck使用方法及效果(转)
  3. bind 安装 和配置(master/slave)
  4. Java编程思想之十四 类型信息
  5. github执行clone操作时报错
  6. C#】通过遍历IFrame访问页面元素
  7. [环境部署] Linux搭建SVN服务器之Centos篇
  8. Python【每日一问】24
  9. linux阿里云服务器更换镜像的方法
  10. 在vue-cli中安装element