Linux下源碼編譯安裝PostgreSQL

Installation possible dependencies


  1. yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel ssse2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gettext-devel libXpm-devel libtool  pacemaker corosync drbd83 kmod-drbd83 heartbeat gcc perl-mailtools perl-dbi php-pgsql tcl*  


create "postgres" user



  1. [root@db01 opt]# groupadd postgres  

  2. [root@db01 opt]# useradd -g postgres -d /data/pgsql -m postgres  

  3. [root@db01 opt]# passwd postgres  

  4. Changing password for user postgres.  

  5. New UNIX password:  

  6. BAD PASSWORD: it is based on a dictionary word  

  7. Retype new UNIX password:  

  8. passwd: all authentication tokens updated successfully.  


installation



  1. [root@db01 postgresql-9.2.2]# ./configure --prefix=/data/pgsql --with-segsize=8 --with-wal-segsize=64 --with-pgport=1521 --with-tcl --with-libedit-preferred  --with-perl --with-python --with-pam --with-openssl --with-ldap --with-libxml --enable-profiling --with-libxslt --enable-thread-safety  

  1. [root@db01 postgresql-9.2.2]# make && make install  


Initialization data



  1. [root@db01 postgresql-9.2.2]# su - postgres  

  2. [postgres@db01 ~]$ pwd  

  3. /data/pgsql  

  4. [postgres@db01 ~]$ ls -l  

  5. total 16  

  6. drwxr-xr-x 2 root root 4096 Jan 14 17:05 bin  

  7. drwxr-xr-x 6 root root 4096 Jan 14 17:05 include  

  8. drwxr-xr-x 3 root root 4096 Jan 14 17:05 lib  

  9. drwxr-xr-x 6 root root 4096 Jan 14 17:05 share  

  10. [postgres@db01 ~]$ /data/pgsql/bin/initdb -D /data/pgsql/data --locale=C --encoding=UTF8  

  11. The files belonging to this database system will be owned by user "postgres".  

  12. This user must also own the server process.  

  13. The database cluster will be initialized with locale "en_US.UTF-8".  

  14. The default database encoding has accordingly been set to "UTF8".  

  15. The default text search configuration will be set to "english".  

  16. creating directory /data/pgsql/data ... ok  

  17. creating subdirectories ... ok  

  18. selecting default max_connections ... 100  

  19. selecting default shared_buffers ... 32MB  

  20. creating configuration files ... ok  

  21. creating template1 database in /data/pgsql/data/base/1 ... ok  

  22. initializing pg_authid ... ok  

  23. initializing dependencies ... ok  

  24. creating system views ... ok  

  25. loading system objects' descriptions ... ok  

  26. creating collations ... ok  

  27. creating conversions ... ok  

  28. creating dictionaries ... ok  

  29. setting privileges on built-in objects ... ok  

  30. creating information schema ... ok  

  31. loading PL/pgSQL server-side language ... ok  

  32. vacuuming database template1 ... ok  

  33. copying template1 to template0 ... ok  

  34. copying template1 to postgres ... ok  

  35. WARNING: enabling "trust" authentication for local connections  

  36. You can change this by editing pg_hba.conf or using the option -A, or  

  37. --auth-local and --auth-host, the next time you run initdb.  

  38. Success. You can now start the database server using:  

  39.    /data/pgsql/bin/postgres -D /data/pgsql/data  

  40. or  

  41.    /data/pgsql/bin/pg_ctl -D /data/pgsql/data -l logfile start  

  42. [postgres@db01 ~]$ ls -l  

  43. total 48  

  44. drwxr-xr-x  2 root     root      4096 Jan 14 17:05 bin  

  45. drwx------ 15 postgres postgres  4096 Jan 14 17:07 data  

  46. -rw-rw-r--  1 postgres postgres 25441 Jan 14 17:07 gmon.out  

  47. drwxr-xr-x  6 root     root      4096 Jan 14 17:05 include  

  48. drwxr-xr-x  3 root     root      4096 Jan 14 17:05 lib  

  49. drwxr-xr-x  6 root     root      4096 Jan 14 17:05 share  


Changing the configuration file and the client to access the files



  1. [postgres@db01 ~]$ echo 'host all all 192.168.0.0/16 md5' >> /data/pgsql/data/pg_hba.conf  

  1. [postgres@db01 ~]$ cd data/  

  2. [postgres@db01 data]$ cp -p postgresql.conf postgresql.conf.bak  

  3. [postgres@db01 data]$ cat postgresql.conf  

  4. data_directory = '/data/pgsql/data'  

  5. hba_file = '/data/pgsql/data/pg_hba.conf'  

  6. port = 1521  

  7. max_connections = 300  

  8. shared_buffers = 32MB  

  9. log_directory = '/data/pgsql/data/pg_log'  

  10. log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'  

  11. log_checkpoints = on  

  12. log_connections = on  

  13. log_timezone = 'PRC'  

  14. autovacuum = on  

  15. datestyle = 'iso, mdy'  

  16. timezone = 'PRC'  

  17. lc_messages = 'en_US.UTF-8'  

  18. lc_monetary = 'en_US.UTF-8'  

  19. lc_numeric = 'en_US.UTF-8'  

  20. lc_time = 'en_US.UTF-8'  

  21. default_text_search_config = 'pg_catalog.english'  



  1. listen_addresses = '*'  

  1. archive_mode = on  

  2. archive_command = 'cp "%p" /data/pgsql/data/pg_xlog/archive_status/"%f"'  

  3. archive_timeout = 500  

  4. wal_level = 'archive'  



Create logfile directory


  1. [postgres@db01 data]$ pwd  

  2. /data/pgsql/data  

  3. [postgres@db01 data]$ mkdir pg_log  

  4. [postgres@db01 data]$ chmod 700 pg_log/  

  5. [postgres@db01 data]$ ls -l  

  6. total 96  

  7. drwx------  5 postgres postgres  4096 Jan 14 17:07 base  

  8. drwx------  2 postgres postgres  4096 Jan 14 17:07 global  

  9. drwx------ 19 postgres postgres  4096 Jan 14 17:07 gprof  

  10. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_clog  

  11. -rw-------  1 postgres postgres  4508 Jan 14 17:08 pg_hba.conf  

  12. -rw-------  1 postgres postgres  1636 Jan 14 17:07 pg_ident.conf  

  13. drwx------  2 postgres postgres  4096 Jan 14 17:15 pg_log  

  14. drwx------  4 postgres postgres  4096 Jan 14 17:07 pg_multixact  

  15. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_notify  

  16. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_serial  

  17. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_snapshots  

  18. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_stat_tmp  

  19. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_subtrans  

  20. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_tblspc  

  21. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_twophase  

  22. -rw-------  1 postgres postgres     4 Jan 14 17:07 PG_VERSION  

  23. drwx------  3 postgres postgres  4096 Jan 14 17:07 pg_xlog  

  24. -rw-------  1 postgres postgres   500 Jan 14 17:14 postgresql.conf  

  25. -rw-------  1 postgres postgres 19610 Jan 14 17:07 postgresql.conf.bak  


Set environment variable


  1. [postgres@db01 data]$ cd  

  2. [postgres@db01 ~]$ pwd  

  3. /data/pgsql  

  4. [postgres@db01 ~]$ vi .bash_profile  

  5. [postgres@db01 ~]$ source .bash_profile  

  6. [postgres@db01 ~]$ cat .bash_profile  

  7. # .bash_profile  

  8. # Get the aliases and functions  

  9. if [ -f ~/.bashrc ]; then  

  10.    . ~/.bashrc  

  11. fi  

  12. # User specific environment and startup programs  

  13. PATH=$PATH:$HOME/bin  

  14. export PATH  

  15. LD_LIBRARY_PATH=/data/pgsql/lib  

  16. export LD_LIBRARY_PATH  

  17. PATH=/data/pgsql/bin:$PATH  

  18. export PATH  

  19. MANPATH=/data/pgsql/man:$MANPATH  

  20. export MANPATH  

  21. export PGDATA=/data/pgsql/data  

  22. export PGLOG=$PGDATA/pg_log  

  23. alias pgstart="pg_ctl -D $PGDATA -l $PGLOG/postgresql-`date +%F%H%M%S`.log start"  

  24. alias pgstop='pg_ctl kill INT `head -1 $PGDATA/postmaster.pid`'  

  25. alias pgstatus='pg_ctl status'  


startup


  1. [postgres@db01 ~]$ pgstart  

  2. server starting  

  3. [postgres@db01 ~]$ cd data/  

  4. [postgres@db01 data]$ ll  

  5. total 104  

  6. drwx------  5 postgres postgres  4096 Jan 14 17:07 base  

  7. drwx------  2 postgres postgres  4096 Jan 14 17:17 global  

  8. drwx------ 20 postgres postgres  4096 Jan 14 17:17 gprof  

  9. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_clog  

  10. -rw-------  1 postgres postgres  4508 Jan 14 17:08 pg_hba.conf  

  11. -rw-------  1 postgres postgres  1636 Jan 14 17:07 pg_ident.conf  

  12. drwx------  2 postgres postgres  4096 Jan 14 17:17 pg_log  

  13. drwx------  4 postgres postgres  4096 Jan 14 17:07 pg_multixact  

  14. drwx------  2 postgres postgres  4096 Jan 14 17:17 pg_notify  

  15. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_serial  

  16. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_snapshots  

  17. drwx------  2 postgres postgres  4096 Jan 14 17:17 pg_stat_tmp  

  18. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_subtrans  

  19. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_tblspc  

  20. drwx------  2 postgres postgres  4096 Jan 14 17:07 pg_twophase  

  21. -rw-------  1 postgres postgres     4 Jan 14 17:07 PG_VERSION  

  22. drwx------  3 postgres postgres  4096 Jan 14 17:07 pg_xlog  

  23. -rw-------  1 postgres postgres   500 Jan 14 17:14 postgresql.conf  

  24. -rw-------  1 postgres postgres 19610 Jan 14 17:07 postgresql.conf.bak  

  25. -rw-------  1 postgres postgres    49 Jan 14 17:17 postmaster.opts  

  26. -rw-------  1 postgres postgres    74 Jan 14 17:17 postmaster.pid  

  27. [postgres@db01 data]$ ps -ef|grep postgres  

  28. root     29657 19120  0 17:06 pts/1    00:00:00 su - postgres  

  29. postgres 29658 29657  0 17:06 pts/1    00:00:00 -bash  

  30. postgres 29758     1  0 17:17 pts/1    00:00:00 /data/pgsql/bin/postgres -D /data/pgsql/data  

  31. postgres 29760 29758  0 17:17 ?        00:00:00 postgres: checkpointer process                

  32. postgres 29761 29758  0 17:17 ?        00:00:00 postgres: writer process                      

  33. postgres 29762 29758  0 17:17 ?        00:00:00 postgres: wal writer process                  

  34. postgres 29763 29758  0 17:17 ?        00:00:00 postgres: autovacuum launcher process        

  35. postgres 29764 29758  0 17:17 ?        00:00:00 postgres: stats collector process            

  36. postgres 29767 29658  0 17:17 pts/1    00:00:00 ps -ef  

  37. postgres 29768 29658  0 17:17 pts/1    00:00:00 grep postgres  

  38. [postgres@db01 data]$ cat postmaster.pid  

  39. 29758  

  40. /data/pgsql/data  

  41. 1358155026  

  42. 1521  

  43. /tmp  

  44. localhost  

  45.  1521001   6488069  

  46. [postgres@db01 data]$  

  1. [postgres@db01 data]$ cat pg_log/postgresql-2013-01-14171634.log  

  2. LOG:  database system was shut down at 2013-01-14 17:07:08 CST  

  3. LOG:  autovacuum launcher started  

  4. LOG:  database system is ready to accept connections  


test


  1. [postgres@db01 ~]$ psql  

  2. psql (9.2.2)  

  3. Type "help" for help.  

  4. postgres=# help  

  5. You are using psql, the command-line interface to PostgreSQL.  

  6. Type:  \copyright for distribution terms  

  7.       \h for help with SQL commands  

  8.       \? for help with psql commands  

  9.       \g or terminate with semicolon to execute query  

  10.       \q to quit  

  11. postgres=#  

  12. postgres=# \q  

  13. [postgres@db01 ~]$  

  14. [postgres@db01 ~]$ psql -h 127.0.0.1 -p 1521 -U postgres  

  15. psql (9.2.2)  

  16. Type "help" for help.  

  17. postgres=# alter role postgres with password 'postgrespwd';  

  18. ALTER ROLE  

  19. postgres=# select count(*) from pg_class;  

  20. count  

  21. -------  

  22.   288  

  23. (1 row)  

  24. postgres=#  


Remote client access


  1. [root@db02 ~]# which psql  

  2. /usr/bin/psql  

  3. [root@db02 ~]# psql -h 192.168.1.201 -p 1521 -U postgres  

  4. Password for user postgres:  

  5. Welcome to psql 8.1.23 (server 9.2.2), the PostgreSQL interactive terminal.  

  6. Type:  \copyright for distribution terms  

  7.       \h for help with SQL commands  

  8.       \? for help with psql commands  

  9.       \g or terminate with semicolon to execute query  

  10.       \q to quit  

  11. WARNING:  You are connected to a server with major version 9.2,  

  12. but your psql client is major version 8.1.  Some backslash commands,  

  13. such as \d, might not work properly.  

  14. postgres=# select count(*) from pg_class;  

  15. count  

  16. -------  

  17.   288  

  18. (1 row)  

  19. postgres=#  



sysctl.conf


  1. net.ipv4.ip_forward = 0  

  2. net.ipv4.conf.default.rp_filter = 1  

  3. net.ipv4.conf.default.accept_source_route = 0  

  4. kernel.sysrq = 0  

  5. kernel.core_uses_pid = 1  

  6. net.ipv4.tcp_syncookies = 1  

  7. kernel.msgmnb = 65536  

  8. kernel.msgmax = 65536  

  9. kernel.shmmax = 68719476736  

  10. kernel.shmall = 4294967296  

  11. fs.aio-max-nr = 1048576  

  12. fs.file-max = 6815744  

  13. kernel.shmmni = 4096  

  14. kernel.sem = 250 32000 100 128  

  15. net.ipv4.ip_local_port_range = 9000 65500  

  16. net.core.rmem_default = 262144  

  17. net.core.rmem_max = 4194304  

  18. net.core.wmem_default = 262144  

  19. net.core.wmem_max = 1048586  


limits.conf



  1. * soft nofile 131072  

  2. * hard nofile 131072  

  3. * soft nproc 131072  

  4. * hard nproc 131072  

  5. * soft core unlimited  

  6. * hard core unlimited  

  7. * soft memlock 50000000  

  8. * hard memlock 50000000  



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章