========================================
PostgreSQL安装(Linux)一
- 执行 #cat /etc/redhat-release #uname -m 查看linux系统版本,去网站http://yum.pgrpms.org/repopackages.php下载对应的linux版本的pg rpm包"pgdg-centos90-9.0-5.noarch.rpm"
#cat /etc/redhat-release
CentOS release 6.5 (Final)
#uname -m
x86_64
- 进入liunx安装目录,上传刚下载的rpm到linux目录,执行命令
rpm -Uvh pgdg-centos-9.0-2.noarch.rpm
- 修改原始的yum仓库配置,在[base]和[updates]部分的尾部追加exclude=postgresql*用以取消从默认仓库安装和更新PostgreSQL。
# vi CentOS-Base.repo
- 安装或者升级postgresql-libs
- 安装PostgreSQL Server
- 初始化数据库,默认路径为arb/pgsql/9.0/data
- 启动服务
- 连接到数据库,修改管理员密码,改为password
# psql -U postgres
postgres=# ALTER USER postgres WITH PASSWORD 'password';
- 重启服务
- 退出
postgresql90-9.0.19-1PGDG.rhel6.x86_64
卸载pg
[root@99 yum.repos.d]# rpm -ev --nodeps postgresql90-libs-9.0.19-1PGDG.rhel6.x86_64
[root@99 yum.repos.d]# rpm -ev --nodeps postgresql90-server-9.0.19-1PGDG.rhel6.x86_64
[root@99 yum.repos.d]# rpm -ev --nodeps postgresql90-9.0.19-1PGDG.rhel6.x86_64
[root@99 yum.repos.d]# rpm -qa | grep postgres
[root@99 yum.repos.d]#
========================================
PostgreSQL安装(Linux)二
一、安装文件:postgresql-9.3.5-3-linux-x64.run
1、开始安装,如下:
[root@dev224 ~]# chmod +x postgresql-9.3.5-3-linux-x64.run
[root@dev224 ~]# ./postgresql-9.3.5-3-linux-x64.run
----------------------------------------------------------------------------
Welcome to the PostgreSQL Setup Wizard.
----------------------------------------------------------------------------
Please specify the directory where PostgreSQL will be installed.
Installation Directory [/opt/PostgreSQL/9.3]:
----------------------------------------------------------------------------
Please select a directory under which to store your data.
Data Directory [/opt/PostgreSQL/9.3/data]:
----------------------------------------------------------------------------
Please provide a password for the database superuser (postgres). A locked Unix
user account (postgres) will be created if not present.
Password :
Retype password :
----------------------------------------------------------------------------
Please select the port number the server should listen on.
Port [5432]:
----------------------------------------------------------------------------
Advanced Options
Select the locale to be used by the new database cluster.
Locale
[1] [Default locale]
...(很多选项省略)
[718] zu_ZA.utf8
Please choose an option [1] :
----------------------------------------------------------------------------
Setup is now ready to begin installing PostgreSQL on your computer.
Do you want to continue? [Y/n]: y
----------------------------------------------------------------------------
Please wait while Setup installs PostgreSQL on your computer.
Installing
0% ______________ 50% ______________ 100%
#########################################
----------------------------------------------------------------------------
Setup has finished installing PostgreSQL on your computer.
确认postgres服务是否启动
[root@dev224 ~]# chkconfig --list|grep postgres
postgresql-9.3 0:off 1:off 2:on 3:on 4:on 5:on 6:off
RPM包安装方式安装后,
需要进行初始化后,进行启动。
# service postgresql-9.3 initdb
2、PostgreSQL 数据库默认会创建一个postgres的数据库用户作为数据库的管理员,按照以下安装后的步骤来创建数据库。
[root@dev224 ~]# su - postgres
-bash-4.1$ bin/createdb iov
-bash-4.1$ bin/psql iov
iov=# select * from pg_shadow ;(输入测试命令测试)
usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valuntil | useconfig
----------+----------+-------------+----------+-----------+---------+-------------------------------------+----------+-----------
postgres | 10 | t | t | t | t | md54a7f5b8ce769752c89b7c27ef71416cc | |
(1 row)
3、修改PostgresSQL 数据库配置实现远程访问 :
修改postgresql.conf 文件
# vi /opt/PostgreSQL/9.3/data/postgresql.conf
<!--[endif]-->
如果想让PostgreSQL 监听整个网络的话,将listen_addresses 前的#去掉,并将 listen_addresses = 'localhost' 改成 listen_addresses = '*'
修改客户端认证配置文件pg_hba.conf
将需要远程访问数据库的IP地址或地址段加入该文件。
# vi /opt/PostgreSQL/9.3/data/pg_hba.conf
重启服务以使设置生效
[root@dev224 ~]# service postgresql-9.3 restart
Restarting PostgreSQL 9.3:
waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
PostgreSQL 9.3 restarted successfully
二、客户端连接,使用pgAdmin或Navicat for PostgreSQL
新建一个服务器连接,连接远程linux服务器上的PostgreSQL数据库:
<!--[endif]-->
得到数据库属性如下图所示:
<!--[endif]-->
========================================