postgresql9.5編譯安裝體驗

實驗環境:

  • centos7.6
  • pgsql9.5 源碼編譯安裝

實驗目的:

體驗源碼編譯安裝pgsqlsql

0一、download

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

0二、requirement

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

0三、add_user postgres && pgdata

useradd postgres
mkdir  -p /pgdata/{data,archive}    //建立數據及歸檔存儲目錄centos

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_profilebash

0四、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]#app

[root@lab-210 postgresql-9.5.19]# ./configure --help    //查看編譯參數
./configure   -q --prefix=/pgdata
make -s -j2
make -s  installsocket

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

0五、init pgsql_instance

su - postgres
initdb -A md5 -U postgres -W  -E 'utf-8' -D $PGDATAui

###更加顆粒度,設置super user pwd
initdb --auth=trust --auth-host=md5 --auth-local=trust \
--pgdata=$PGDATA --encoding='UTF-8' \
--username=postgres --pwpromptthis

[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

0六、express pgsql

createdb test
psql test
test=#
help

0七、開啓歸檔及日誌記錄

###追加到配置文件中

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

 0八、設置爲service管理postgres

###腳本在源碼編譯的位置存放

 copy到init.d/及給予權限

 修改prefix/pgdata

 啓動驗證