標籤:源碼安裝postgresql
資料庫版本:
PostgreSQL 9.6.3
系統版本:
CentOS release 6.6 (Final)
下載軟體(Download software):
[[email protected] tools]# wget https://ftp.postgresql.org/pub/source/v9.6.3/postgresql-9.6.3.tar.gz
查看是否已經安裝(Check is not instatll):
[[email protected] tools]# ps -ef |grep pgsql
root 28590 18695 0 20:24 pts/0 00:00:00 grep pgsql
[[email protected] ~]$ rpm -qa |grep postgres
postgresql-libs-8.4.18-1.el6_4.x86_64
解壓(Extract software):
[[email protected] tools]# tar xf postgresql-9.6.3.tar.gz
編譯和安裝(Complie):
[[email protected] tools]# cd postgresql-9.6.3
[[email protected] postgresql-9.6.3]# ./configure --prefix=/usr/local/pgsql
編譯所有能編譯的東西,包括文檔(HTML和手冊頁)以及附加模組(contrib):
[[email protected] postgresql-9.6.3]# make world && make install-world
......
make[2]: Leaving directory `/home/tools/postgresql-9.6.3/contrib/vacuumlo‘
make[1]: Leaving directory `/home/tools/postgresql-9.6.3/contrib‘
PostgreSQL, contrib, and documentation installation complete.
建立用組和使用者(Create group and user)
[[email protected] ~]# groupadd -g 101 dba
[[email protected] ~]# cat /etc/group|grep dba
dba:x:101:
[[email protected] ~]# useradd -u 516 -g dba -G root -d /usr/local/pgsql postgres
[[email protected]ren2 ~]# id postgres
uid=516(postgres) gid=101(dba) groups=101(dba),0(root)
-u UID
-g 初始使用者組
-G次要使用者組
-m 建立使用者家目錄(系統使用者預設不建立家目錄)
-M 不建立使用者家目錄(普通使用者預設建立家目錄)
-s shell 預設是/bin/bash
-d指定家目錄
[[email protected] home]# groups postgres
postgres : dba root
配置postgres密碼
[[email protected] home]# passwd postgres
[[email protected] skel]# ls -al /etc/skel/
total 20
drwxr-xr-x. 2 root root 4096 Dec 20 2016 .
drwxr-xr-x. 84 root root 4096 Jul 11 22:27 ..
-rw-r--r--. 1 root root 18 Jul 18 2013 .bash_logout
-rw-r--r--. 1 root root 176 Jul 18 2013 .bash_profile
-rw-r--r--. 1 root root 124 Jul 18 2013 .bashrc
[[email protected] skel]# cp /etc/skel/.* /usr/local/pgsql/
建立資料目錄(Create data folder)
[[email protected] ~]# mkdir -p /usr/local/pgsql/data
配置.bash_profile(Configure .bash_profile)
[[email protected] pgsql]# cat /usr/local/pgsql/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PGHOME=/usr/local/pgsql
export PGDATA=/usr/local/pgsql/data
export PATH=$PATH:/usr/local/pgsql/bin
set umask to 022
umask 022
PS1=`uname -n`":"‘$USER‘":"‘$PWD‘":>"; export PS1
修改檔案許可權和所有者(Chmod and chown)
[[email protected] pgsql]# chmod -R 755 /usr/local/pgsql
[[email protected] pgsql]# chown -R postgres:dba /usr/local/pgsql
[[email protected] pgsql]# chmod -R 700 /usr/local/pgsql/data
配置postgresql服務啟動和設定自啟動(Configure postgresql service and boot auto start) --這步可不做
[[email protected] start-scripts]# cp /home/tools/postgresql-9.6.3/contrib/start-scripts/linux /etc/init.d/postgresql
[[email protected] start-scripts]# chmod +x /etc/init.d/postgresql
[[email protected] start-scripts]# chkconfig --list |grep postgresql
[[email protected] start-scripts]# chkconfig --add postgresql
[[email protected] start-scripts]# chkconfig --list |grep postgresql
postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
初始化資料和啟動(Initialize database and start database)
[[email protected] start-scripts]# su - postgres
[[email protected] start-scripts]$ cd
[[email protected] ~]$ pwd
/usr/local/pgsql
[[email protected] ~]$ . .bash_profile
#初始化產生資料檔案
Darren2:postgres:/usr/local/pgsql:>/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
#啟動資料庫
Darren2:postgres:/usr/local/pgsql:>pg_ctl start
server starting
Darren2:postgres:/usr/local/pgsql:>LOG: database system was shut down at 2017-07-12 00:49:17 CST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
建立使用者和資料庫(Create user and database)
psql
psql (9.6.3)
Type "help" for help.
postgres=# create user admin password‘admin‘ login;
CREATE ROLE
postgres=# create database testdb with owner=admin;
CREATE DATABASE
Darren2:postgres:/usr/local/pgsql:>pg_ctl status
pg_ctl: server is running (PID: 51498)
/usr/local/pgsql/bin/postgres
安裝過程中常見報錯
編譯時間候報錯:
[[email protected] postgresql-9.6.3]# ./configure --prefix=/usr/local/pgsql --without-zlib
......
configure: error: readline library not found --提示找不到readline
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn‘t looking in the proper directory.
Use --without-readline to disable readline support.
查看系統已經安裝readline:
[[email protected] postgresql-9.6.3]# rpm -qa |grep readline
compat-readline5-5.2-17.1.el6.x86_64
readline-6.0-4.el6.x86_64
通過yum search可以發現沒有安裝readline-devel:
[[email protected] postgresql-9.6.3]# yum search readline
......
readline-devel.i686 : Files needed to develop programs which use the readline library
readline-devel.x86_64 : Files needed to develop programs which use the readline library
......
通過yum安裝之後,在編譯即可通過:
[[email protected] postgresql-9.6.3]# yum install -y readline-devel
本文出自 “10979687” 部落格,請務必保留此出處http://10989687.blog.51cto.com/10979687/1971094
源碼安裝PostgreSQL