RUI个人博客 首页>>PostgreSQL>>PostgreSQL在linux平台下的安装

PostgreSQL在linux平台下的安装

实验环境:
OS:OEL 5.8  x86_64
PostgreSQL安装包:postgresql-9.3.9.tar.gz


PostgreSQL可以使用root用户安装也可以使用普通用户安装,这里我用的是普通用户进行安装:
    创建组及用户:

[root@edb1 ~]# groupadd pg
[root@edb1 ~]# useradd -g pg pg

解压安装包:

[root@edb1 ~]# su - pg
[pg@edb1 ~]$ cd /soft/
[pg@edb1 soft]$ tar -zxvf postgresql-9.3.9.tar.gz
[pg@edb1 soft]$ cd postgresql-9.3.9

安装过程(过程中注意有无报错):

configure

[pg@edb1 postgresql-9.3.9]$ ./configure -prefix=/home/pg/pgsql       --指定安装目录
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
......
make
[pg@edb1 postgresql-9.3.9]$ make
make -C src all
make[1]: Entering directory `/soft/postgresql-9.3.9/src'
make -C common all
make[2]: Entering directory `/soft/postgresql-9.3.9/src/common'
make -C ../backend submake-errcodes
......
make[1]: Leaving directory `/soft/postgresql-9.3.9/config'
All of PostgreSQL successfully made. Ready to install.
make install
[pg@edb1 postgresql-9.3.9]$ make install
make -C src install
make[1]: Entering directory `/soft/postgresql-9.3.9/src'
make -C common install
......
make[1]: Leaving directory `/soft/postgresql-9.3.9/config'
PostgreSQL installation complete.

修改pg用户环境变量,增加以下内容:

[pg@edb1 ~]$ vi .bash_profile
LD_LIBRARY_PATH=/home/pg/pgsql/lib
export LD_LIBRARY_PATH
PATH=/home/pg/pgsql/bin:$PATH
export PATH
PGDATA=/home/pg/pgsql/data

生效环境变量:

[pg@edb1 ~]$ . .bash_profile

创建PostgreSQL默认库:

[pg@edb1 ~]$ initdb -D $PGDATA
The files belonging to this database system will be owned by user "pg".
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".
......
Success. You can now start the database server using:

    postgres -D /home/pg/pgsql/data
or
    pg_ctl -D /home/pg/pgsql/data -l logfile start

创建完成之后也给出了数据库启动命令

启动数据库:

[pg@edb1 ~]$ ps -ef|grep post
pg       28350     1  0 01:15 pts/2    00:00:00 /home/pg/pgsql/bin/postgres -D /home/pg/pgsql/data
pg       28352 28350  0 01:15 ?        00:00:00 postgres: checkpointer process                    
pg       28353 28350  0 01:15 ?        00:00:00 postgres: writer process                          
pg       28354 28350  0 01:15 ?        00:00:00 postgres: wal writer process                      
pg       28355 28350  0 01:15 ?        00:00:00 postgres: autovacuum launcher process             
pg       28356 28350  0 01:15 ?        00:00:00 postgres: stats collector process                 
pg       28913 28406  0 01:35 pts/2    00:00:00 grep post

查看监听端口:

[pg@edb1 ~]$ netstat -natp|grep postgres
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:5432              0.0.0.0:*                   LISTEN      28350/postgres 

关闭数据库:

[pg@edb1 ~]$ pg_ctl -D /home/pg/pgsql/data stop
waiting for server to shut down.... done
server stopped


昵  称:
邮  箱:
评论内容:
验 证 码:
可用[code][/code]插入代码
点击刷新验证码