installing PostgreSQL database no necessary require root user permissions, also can use general user. There are many ways to install, compile installation, binary installation and various Linux system installation.
1.Compile installation
-overall process
./configure
gmake
su
gmake install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
2. Prepare to install pre additions
Request one:
Request have GNU make, the version big than or equal 3.76.1, this is the way to check gmake:
gmake --version
Request two:
The compilers requirements are ISO/ANSI C compliant compilers, comply with C89 standard. if use gcc, can support this twice conditions. however, the gcc support most UNIX environments, for example, Linux, AIX, PHUX, Solaris etc.
Request three:
Due to original code package's format was .tar.gz or .tar.bz2. so require can unzip original code package tar and gzip tools below of platform.
Request four(no force):
PostgreSQL uses the GNU Readline library by default. You can use the cursor key up down to scroll through the history commands on the psql command lines. of course, if without GNU Readline library, need to add without-readline option after ./configure command. certainly, after you do this will lose the function that use the cursor key un down to scroll through the history commands. Also can use the libedit library (BSD-licensed) provide similar functions, and now need to after ./configure add --with-libedit-preferred option. The Linux issued common version has frequently installed GNU Readline library. To check the system whether installed Readline library using below command.
[root@osdba /usr/src/postgresql-8.4.3]#rpm -qa |grep readline
readline-5.2-13.fc9.i386
Request five(no force):
PostgreSQL default used zlib compression library, in order to pg_dump and pg_restore this twice import-export tools to use zlib compression library. Specify configuration options --without-zlib could no to use the zlib library, of course, such pg_dump and pg_restore then no more compression options.
Request six(no force):
main you need service language, such as PL/Perl, PL/Python PL/Tcl, of course, you have to install Perl, Python, Tcl.
If you need PostgreSQL can prompt Chinese, you must implement Gettext API.
3.download PostgreSQL original code packages.
go to download original code packages on the www.postgresql.org website, then unzip below of one directory.
gunzip postgresql-8.4.3.tar.gz
tar xvf postgresql-8.4.3.tar
if on the LInux, can further unzip:
tar zxvf postgresql-8.4.3.tar.gz
if was .tar.bz2 package:
tar jxvf postgresql-8.4.3.tar.bz2
4.installation process
⑴ ./configure
The command can follow many options as we have told, such --with-libedit-preferred :
./configure --with-libedit-preferred
This command can follow many options, specify you could refer that PostgreSQL provided official handbook, here are introducing several common options:
--prefix=PREFIX: provide installation PostgreSQL catalog, if not specified , then install below to /usr/local/pgsql.
--with-pgport=NUMBER: specify PostgreSQL's listener port, default is 5432.
--with-wal-segsize=SEGSIZE: specify WAL log file size.
--with-wal-blocksize=BLOCKSIZE: specify WAL log block size.
--enable-thread-safety: allow client's library function is thread safety.
Could be view below the line when executed:
configure: error: readline library not found
because of no installed readline, only if installed this library has been done, if on the ubuntu10.04 you can:
aptitude install libreadline6-dev
⑵ compile original code
gmake
It is possible that your machine does not have the gmake command, but make was gnu make, and now execute make compile:
make
⑶install the compile generate files
gmake install
if only install the client program;
gmake -C src/bin install
gmake -C src/include install
gmake -C src/interfaces install
gmake -C doc install
if on the windows platform, you can register event log:
regsvr32 pgsql_library_directory/pgevent.dll
⑷ uninstall
gmake uninstall
5.Set environment variable and share library path and executable file path
It is possible to put below content into UNIX user's ~/.bash_profile or ~/.profile files, or if it works for all users, could add into /etc/profile file:
On the Bourne shells (sh, ksh, bash, zsh):
LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH
PATH=/usr/local/pgsql/bin:$PATH
export PATH
MANPATH=/usr/local/pgsql/man:$MANPATH
export MANPATH
or in csh or tcsh:
setenv LD_LIBRARY_PATH /usr/local/pgsql/lib
set path = ( /usr/local/pgsql/bin $path )
On the BSD/OS, Linux, or SunOS 4 platform, execute by root user:
/sbin/ldconfig /usr/local/pgsql/lib
On FreeBSD, NetBSD, and OpenBSD:
/sbin/ldconfig -m /usr/local/pgsql/lib
6.Install some tools on the contrib catalog
On the original code catalog have a contrib catalog, that was some tool code contribution by Third-part organization, that tools were usefully on the routine maintenance, suggest to install.
cd /usr/src/postgresql-8.4.3/contrib
make
make install
7.Create database
Create postgres user:
useradd -m -u 701 postgres
Create postgres database's catalog, suppose database catalog was create on the directory /opt/pgdata:
mkdir /opt/pgdata
chown postgres:postgres /opt/pgdata
Add below content in the postgres user's .bash_profile file, that was convenient to startup and shutdown database on the later:
su - postgres
export PGDATA=/opt/pgdata
alias pgstart='pg_ctl -D $PGDATA start'
alias pgstop='pg_ctl kill INT `head -1 $PGDATA/postmaster.pid`'
If you want to create utf8 coding database, must attention setup LANG environment variables as utf8, put below content to .bash_profile file:
export LANG=en_US.utf8
Initialization database catalog:
su - postgres
/usr/local/pgsql/bin/initdb -D $PGDATA
Update database parameter:
according require update parameter on the $PGDATA/postgresql.conf, for example:
logging_collector = on
log_rotation_age = 1d
log_rotation_size = 10MB
Startup databse
/usr/local/pgsql/bin/pg_ctl -D $PGDATA start
And now you can access plsql command line:
[postgres@pghost pgdata]$ psql
psql (8.4.3)
Type "help" for help.
postgres=#
Now you can create database user:
CREATE DATABASE mydb
2.Figure install
This part was to introduce PostgreSQL program's installation process. Base on SuperMap SDX+ for PostgreSQL not support for PostgreSQL 8.2 version,suggest to install above PostgreSQL 8.3 version.
1.Installation home page
After open PostgreSQL product install catalog, double click “postgresql-9.0.2-1-windows.exe” program, appear below pictures was PostgreSQL install home page, click "Next" button continues to install.
2. Specify installation catalog
As below picture show, specify PostgreSQL install catalog, then, click "Next" button continues to install.
figure: specify the install-catalog
install PostgreSQL partitions better using NTFS formats. The PostgreSQL first task is guaranteed data integrity, but FAT32 filesystem couldn't be provided such as reliability guarantee, and FAT32 filesystem was lacked safe guarantee, cannot guarantee original data has changed in the unauthorized situation. moreover, PostgreSQL couldn't implement "multiple points" function to completed tablespace feature in the FAT32 filesystem.
However, in any other system, only have one FAT32 disk partition. on this situation, also can normally install PostgreSQL, but not might get on database initialization works. After completed install, manual execution initdb.exe program on the FAT32 filesystem partition, but cannot guarantee this safety and reliability, and create tablespace would fail.
3.specify the database storage catalog
As below figure shows, in order to database storage area specify the installation area. then, click "Next" button continues to install.
figure: specify database storage catalog
4.Set database superuser and service account password
Database superuser is a non-administration account, reducing that the hack utilize PostgreSQL find a defect in the system to causing damage, therefore, we need to set a password for database superuser, like below picture shows, install program auto create service user name default was postgres. then, click "Next" button continues to install.
Figure: set service account password
5.Set service listening port
As below figure shows, specify the database service port, the default is "5432", and the user could get on to set port according to self-port use situation. then, click "Next" button continues to install.
6.choice running language environment
As below figure shows, choose database storage area running language environment. then, click "Next" button, access install process page, waiting for PostgreSQL complete install.
Attention, on the choice language environment, if choose "default locale' would be resulting installation incorrect; At the same time, PostgreSQL can't support GBK and GB18030 as the character set.
7.End install
After completed install the above steps, would appear below picture is a complete dialog. Here could choose whether to run Stack Builder guide to install attach software, for complete PostgreSQL installation. this operation must be executed on the online state.
figure:end install