Linux下源码编译安装PostgreSQL
Installation possible dependenciesyum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib
·
Installation possible dependencies
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
[root@db01 opt]# groupadd postgres
[root@db01 opt]# useradd -g postgres -d /data/pgsql -m postgres
[root@db01 opt]# passwd postgres
Changing password for user postgres.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
installation
[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
[root@db01 postgresql-9.2.2]# make && make install
Initialization data
[root@db01 postgresql-9.2.2]# su - postgres
[postgres@db01 ~]$ pwd
/data/pgsql
[postgres@db01 ~]$ ls -l
total 16
drwxr-xr-x 2 root root 4096 Jan 14 17:05 bin
drwxr-xr-x 6 root root 4096 Jan 14 17:05 include
drwxr-xr-x 3 root root 4096 Jan 14 17:05 lib
drwxr-xr-x 6 root root 4096 Jan 14 17:05 share
[postgres@db01 ~]$ /data/pgsql/bin/initdb -D /data/pgsql/data --locale=C --encoding=UTF8
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".
creating directory /data/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /data/pgsql/data/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
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:
/data/pgsql/bin/postgres -D /data/pgsql/data
or
/data/pgsql/bin/pg_ctl -D /data/pgsql/data -l logfile start
[postgres@db01 ~]$ ls -l
total 48
drwxr-xr-x 2 root root 4096 Jan 14 17:05 bin
drwx------ 15 postgres postgres 4096 Jan 14 17:07 data
-rw-rw-r-- 1 postgres postgres 25441 Jan 14 17:07 gmon.out
drwxr-xr-x 6 root root 4096 Jan 14 17:05 include
drwxr-xr-x 3 root root 4096 Jan 14 17:05 lib
drwxr-xr-x 6 root root 4096 Jan 14 17:05 share
Changing the configuration file and the client to access the files
[postgres@db01 ~]$ echo 'host all all 192.168.0.0/16 md5' >> /data/pgsql/data/pg_hba.conf
[postgres@db01 ~]$ cd data/
[postgres@db01 data]$ cp -p postgresql.conf postgresql.conf.bak
[postgres@db01 data]$ cat postgresql.conf
data_directory = '/data/pgsql/data'
hba_file = '/data/pgsql/data/pg_hba.conf'
port = 1521
max_connections = 300
shared_buffers = 32MB
log_directory = '/data/pgsql/data/pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_checkpoints = on
log_connections = on
log_timezone = 'PRC'
autovacuum = on
datestyle = 'iso, mdy'
timezone = 'PRC'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
listen_addresses = '*'
archive_mode = on
archive_command = 'cp "%p" /data/pgsql/data/pg_xlog/archive_status/"%f"'
archive_timeout = 500
wal_level = 'archive'
Create logfile directory
[postgres@db01 data]$ pwd
/data/pgsql/data
[postgres@db01 data]$ mkdir pg_log
[postgres@db01 data]$ chmod 700 pg_log/
[postgres@db01 data]$ ls -l
total 96
drwx------ 5 postgres postgres 4096 Jan 14 17:07 base
drwx------ 2 postgres postgres 4096 Jan 14 17:07 global
drwx------ 19 postgres postgres 4096 Jan 14 17:07 gprof
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_clog
-rw------- 1 postgres postgres 4508 Jan 14 17:08 pg_hba.conf
-rw------- 1 postgres postgres 1636 Jan 14 17:07 pg_ident.conf
drwx------ 2 postgres postgres 4096 Jan 14 17:15 pg_log
drwx------ 4 postgres postgres 4096 Jan 14 17:07 pg_multixact
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_notify
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_serial
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_snapshots
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_stat_tmp
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_subtrans
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_tblspc
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_twophase
-rw------- 1 postgres postgres 4 Jan 14 17:07 PG_VERSION
drwx------ 3 postgres postgres 4096 Jan 14 17:07 pg_xlog
-rw------- 1 postgres postgres 500 Jan 14 17:14 postgresql.conf
-rw------- 1 postgres postgres 19610 Jan 14 17:07 postgresql.conf.bak
Set environment variable
[postgres@db01 data]$ cd
[postgres@db01 ~]$ pwd
/data/pgsql
[postgres@db01 ~]$ vi .bash_profile
[postgres@db01 ~]$ source .bash_profile
[postgres@db01 ~]$ cat .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 PATH
LD_LIBRARY_PATH=/data/pgsql/lib
export LD_LIBRARY_PATH
PATH=/data/pgsql/bin:$PATH
export PATH
MANPATH=/data/pgsql/man:$MANPATH
export MANPATH
export PGDATA=/data/pgsql/data
export PGLOG=$PGDATA/pg_log
alias pgstart="pg_ctl -D $PGDATA -l $PGLOG/postgresql-`date +%F%H%M%S`.log start"
alias pgstop='pg_ctl kill INT `head -1 $PGDATA/postmaster.pid`'
alias pgstatus='pg_ctl status'
startup
[postgres@db01 ~]$ pgstart
server starting
[postgres@db01 ~]$ cd data/
[postgres@db01 data]$ ll
total 104
drwx------ 5 postgres postgres 4096 Jan 14 17:07 base
drwx------ 2 postgres postgres 4096 Jan 14 17:17 global
drwx------ 20 postgres postgres 4096 Jan 14 17:17 gprof
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_clog
-rw------- 1 postgres postgres 4508 Jan 14 17:08 pg_hba.conf
-rw------- 1 postgres postgres 1636 Jan 14 17:07 pg_ident.conf
drwx------ 2 postgres postgres 4096 Jan 14 17:17 pg_log
drwx------ 4 postgres postgres 4096 Jan 14 17:07 pg_multixact
drwx------ 2 postgres postgres 4096 Jan 14 17:17 pg_notify
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_serial
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_snapshots
drwx------ 2 postgres postgres 4096 Jan 14 17:17 pg_stat_tmp
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_subtrans
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_tblspc
drwx------ 2 postgres postgres 4096 Jan 14 17:07 pg_twophase
-rw------- 1 postgres postgres 4 Jan 14 17:07 PG_VERSION
drwx------ 3 postgres postgres 4096 Jan 14 17:07 pg_xlog
-rw------- 1 postgres postgres 500 Jan 14 17:14 postgresql.conf
-rw------- 1 postgres postgres 19610 Jan 14 17:07 postgresql.conf.bak
-rw------- 1 postgres postgres 49 Jan 14 17:17 postmaster.opts
-rw------- 1 postgres postgres 74 Jan 14 17:17 postmaster.pid
[postgres@db01 data]$ ps -ef|grep postgres
root 29657 19120 0 17:06 pts/1 00:00:00 su - postgres
postgres 29658 29657 0 17:06 pts/1 00:00:00 -bash
postgres 29758 1 0 17:17 pts/1 00:00:00 /data/pgsql/bin/postgres -D /data/pgsql/data
postgres 29760 29758 0 17:17 ? 00:00:00 postgres: checkpointer process
postgres 29761 29758 0 17:17 ? 00:00:00 postgres: writer process
postgres 29762 29758 0 17:17 ? 00:00:00 postgres: wal writer process
postgres 29763 29758 0 17:17 ? 00:00:00 postgres: autovacuum launcher process
postgres 29764 29758 0 17:17 ? 00:00:00 postgres: stats collector process
postgres 29767 29658 0 17:17 pts/1 00:00:00 ps -ef
postgres 29768 29658 0 17:17 pts/1 00:00:00 grep postgres
[postgres@db01 data]$ cat postmaster.pid
29758
/data/pgsql/data
1358155026
1521
/tmp
localhost
1521001 6488069
[postgres@db01 data]$
[postgres@db01 data]$ cat pg_log/postgresql-2013-01-14171634.log
LOG: database system was shut down at 2013-01-14 17:07:08 CST
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
test
[postgres@db01 ~]$ psql
psql (9.2.2)
Type "help" for help.
postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
postgres=#
postgres=# \q
[postgres@db01 ~]$
[postgres@db01 ~]$ psql -h 127.0.0.1 -p 1521 -U postgres
psql (9.2.2)
Type "help" for help.
postgres=# alter role postgres with password 'postgrespwd';
ALTER ROLE
postgres=# select count(*) from pg_class;
count
-------
288
(1 row)
postgres=#
Remote client access
[root@db02 ~]# which psql
/usr/bin/psql
[root@db02 ~]# psql -h 192.168.1.201 -p 1521 -U postgres
Password for user postgres:
Welcome to psql 8.1.23 (server 9.2.2), the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
WARNING: You are connected to a server with major version 9.2,
but your psql client is major version 8.1. Some backslash commands,
such as \d, might not work properly.
postgres=# select count(*) from pg_class;
count
-------
288
(1 row)
postgres=#
sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
limits.conf
* soft nofile 131072
* hard nofile 131072
* soft nproc 131072
* hard nproc 131072
* soft core unlimited
* hard core unlimited
* soft memlock 50000000
* hard memlock 50000000
更多推荐
已为社区贡献4条内容
所有评论(0)