centos 下源碼安裝postgresql 9.4

[root@localhost ~]# cd /home
[root@localhost home]# ls
postgresql-9.4.1.tar  test
[root@localhost home]# tar xf postgresql-9.4.1.tar 
[root@localhost home]# cd postgresql-9.4.1
[root@localhost postgresql-9.4.1]# ls
aclocal.m4  config  configure  configure.in  contrib  COPYRIGHT  doc  GNUmakefile.in  HISTORY  INSTALL  Makefile  README  src
[root@localhost postgresql-9.4.1]# ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit integer date/time support... yes
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc supports -Wdeclaration-after-statement... yes
checking whether gcc supports -Wendif-labels... yes
checking whether gcc supports -Wmissing-format-attribute... yes
checking whether gcc supports -Wformat-security... yes
checking whether gcc supports -fno-strict-aliasing... yes
checking whether gcc supports -fwrapv... yes
checking whether gcc supports -fexcess-precision=standard... no
checking whether gcc supports -funroll-loops... yes
checking whether gcc supports -ftree-vectorize... yes
checking whether the C compiler still works... yes
checking how to run the C preprocessor... gcc -E
checking allow thread-safe client libraries... yes
checking whether to build with Tcl... no
checking whether to build Perl modules... no
checking whether to build Python modules... no
checking whether to build with GSSAPI support... no
checking whether to build with PAM support... no
checking whether to build with LDAP support... no
checking whether to build with Bonjour support... no
checking whether to build with OpenSSL support... no
checking whether to build with SELinux support... no
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for ranlib... ranlib
checking for strip... strip
checking whether it is possible to strip libraries... yes
checking for ar... ar
checking for a BSD-compatible install... /usr/bin/install -c
checking for tar... /bin/tar
checking whether ln -s works... yes
checking for gawk... gawk
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for bison... /usr/bin/bison
configure: using bison (GNU Bison) 2.4.1
checking for flex... no
configure: WARNING:
*** Without Flex you will not be able to build PostgreSQL from Git nor
*** change any of the scanner definition files.  You can obtain Flex from
*** a GNU mirror site.  (If you are using the official distribution of
*** PostgreSQL then you do not need to worry about this because the Flex
*** output is pre-generated.)
checking for perl... /usr/bin/perl
configure: using perl 5.10.1
checking for main in -lm... yes
checking for library containing setproctitle... no
checking for library containing dlopen... -ldl
checking for library containing socket... none required
checking for library containing shl_load... no
checking for library containing getopt_long... none required
checking for library containing crypt... -lcrypt
checking for library containing shm_open... -lrt
checking for library containing shm_unlink... none required
checking for library containing fdatasync... none required
checking for library containing gethostbyname_r... none required
checking for library containing shmget... none required
checking for library containing readline... no
configure: error: readline library not found
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 library
#檢查系統是否安裝readlilne包
[root@localhost postgresql-9.4.1]# rpm -qa | grep readline
readline-6.0-4.el6.x86_64
 
#經過yum搜索相關的readline包
[root@localhost postgresql-9.4.1]# yun search readline
-bash: yun: command not found
[root@localhost postgresql-9.4.1]# yum search readline
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
* base: mirror.bit.edu.cn
* extras: mirrors.btte.net
* updates: mirror.bit.edu.cn
base                                                                                                     | 3.7 kB     00:00    
extras                                                                                                   | 3.4 kB     00:00    
extras/primary_db                                                                                        |  31 kB     00:00    
updates                                                                                                  | 3.4 kB     00:00    
updates/primary_db                                                                                       | 4.4 MB     00:17    
==================================================== N/S Matched: readline =====================================================
compat-readline5-devel.i686 : Files needed to develop programs which use the readline library
compat-readline5-devel.x86_64 : Files needed to develop programs which use the readline library
compat-readline5-static.x86_64 : Static libraries for the readline library
libreadline-java-javadoc.x86_64 : Javadoc for libreadline-java
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
readline-static.x86_64 : Static libraries for the readline library
compat-readline5.i686 : A library for editing typed command lines
compat-readline5.x86_64 : A library for editing typed command lines
libreadline-java.x86_64 : Java wrapper for the EditLine library
perl-Term-UI.x86_64 : Term::ReadLine UI made easy
readline.i686 : A library for editing typed command lines
readline.x86_64 : A library for editing typed command lines

  Name and summary matches only, use "search all" for everything.
 
#安裝readline-devel包
[root@localhost postgresql-9.4.1]# yum -y install -y readline-devel.x86_64
 
再次執行configure成功。
 
---------------------------
 
[root@localhost postgresql-9.4.1]# adduser postgres
[root@localhost postgresql-9.4.1]# mkdir /data/pgsql
[root@localhost postgresql-9.4.1]# mkdir /log
[root@localhost postgresql-9.4.1]# mkdir /data/log
[root@localhost postgresql-9.4.1]# mkdir /data/log/pgsql
[root@localhost postgresql-9.4.1]# chown -R postgres.postgres /data/pgsql
[root@localhost postgresql-9.4.1]# chown -R postgres.postgres /data/log/pgsql
[root@localhost postgresql-9.4.1]# su postgres
[postgres@localhost postgresql-9.4.1]$ cd /usr/local/pgsql/bin
[postgres@localhost bin]$ ls
clusterdb   createuser  dropuser  pg_basebackup   pg_ctl      pg_isready      pg_resetxlog  postmaster  vacuumdb
createdb    dropdb      ecpg      pg_config       pg_dump     pg_receivexlog  pg_restore    psql
createlang  droplang    initdb    pg_controldata  pg_dumpall  pg_recvlogical  postgres      reindexdb
[postgres@localhost bin]$ ./initdb -D /data/pgsql
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /data/pgsql ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /data/pgsql/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    ./postgres -D /data/pgsql
or
    ./pg_ctl -D /data/pgsql -l logfile start

[postgres@localhost bin]$ ./postgres -D /data/pgsql > /data/log/pgsql/logfile 2>&1 &
 
服務啓動。接下來設置環境變量。
 
 

每次啓動數據庫服務都要進入PG的bin目錄,再敲一堆命令什麼的也不方便,不如直接將bin下的可執行程序加到用戶環境變量當中。可經過下列方式實現。java

 

打開用戶的環境配置文件,是/home/postgres/下的.profile,經過vim命令打開(若是沒裝vim能夠經過sudo apt-get install vim來安裝)。在末尾處加上:linux

 

export PGDATA=/data/pgsqlsql

export PATH=$PATH:/usr/local/pgsql/bin數據庫

 

PGDATA是postgres –D後面指定的數據庫文件存放目錄,經過這樣的設置,若是直接運行postgres或pg_ctl start那麼數據庫文件會默認存放在/data/pgsql目錄中的。vim

 

至此,PG的安裝結束,用戶在開啓數據庫服務的狀態下,可使用psql客戶端來鏈接並訪問數據庫,經過SQL語言來操做。
相關文章
相關標籤/搜索