本文整理自网络,侵删。
一、PostgreSQL简介
1、什么是PostgreSQL
PostgreSQL数据库是目前功能最强大的开源数据库,支持丰富的数据类型(如JSON何JSONB类型,数组类型)和自定义类型。而且它提供了丰富的接口,可以很容易地扩展它的功能,如可以在GiST框架下实现自己的索引类型等,它还支持使用C语言写自定义函数、触发器,也支持使用流行的语言写自定义函数,比如其中的PL/Perl提供了使用Perl语言写自定义函数的功能,当然还有PL/Python、PL/Tcl,等等。
2、PostgreSQL数据库的优势
PostgreSQL数据库是目前功能最强大的开源数据库,它是最接近工业标准SQL92的查询语言,并且正在实现新的功能已兼容最新的SQL标准:SQL2003.
稳定可靠:PostgreSQL是唯一能做到数据零丢失的开源数据库。有报道称国外的部分银行也在使用PostgreSQL。
开源省钱:PostgreSQL数据库是开源的、免费的,而且是BSD协议,在使用和二次开发上基本没有限制。
支持广泛:PostgreSQL数据库支持大量的主流开发语言,包括C、C++、Perl、Python、Java、Tcl,和PHP等。
PostgreSQL社区活跃:PostgreSQL基本上每三个月推出一个补丁版本,这意味着已知的BUG很快会被修复,有应用场景的需求也会及时得到响应。
二、PostgreSQL安装与配置
#安装前准备:
1、系统版本
[root@node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
2、yum安装(在官网上找到对应版本的yum源,之后安装到本地。
[root@node1 ~]# yum -y install pgdg-centos96-9.6-3.noarch.rpm #yum源安装 [root@node1 ~]# yum -y install postgresql-server #安装postgreesql #安装生成的文件 [root@node1 ~]# rpm -ql postgresql-server /etc/pam.d/postgresql /usr/bin/initdb /usr/bin/pg_basebackup /usr/bin/pg_controldata /usr/bin/pg_ctl /usr/bin/pg_receivexlog /usr/bin/pg_resetxlog /usr/bin/postgres /usr/bin/postgresql-check-db-dir /usr/bin/postgresql-setup /usr/bin/postmaster /usr/lib/systemd/system/postgresql.service /usr/lib/tmpfiles.d/postgresql.conf /var/lib/pgsql /var/lib/pgsql/.bash_profile /var/lib/pgsql/backups /var/lib/pgsql/data /var/run/postgresql、 #启动postgresql #直接启动会报错: [root@node1 ~]# systemctl start postgresql.service Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details. #上面是提示数据库还没有初始化,所以我们先初始化一下 postgresql-setup initdb Initializing database ... OK #提示初始化成功 #重新启动Postgresql [root@node1 ~]# systemctl start postgresql.service [root@node1 ~]# netstat -tnlp Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1512/postgres tcp6 0 0 ::1:5432 :::* LISTEN 1512/postgres #查看运行状态 [root@node1 ~]# systemctl status postgresql.service ● postgresql.service - PostgreSQL database server Active: active (running) since Sat 2016-11-26 22:49:07 CST; 1min 33s ago #切换到操作系统下的“postgres”用户,登录数据库 [root@node1 ~]# su - postgres -bash-4.2$ psql psql (9.2.15) 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 #到此为止,基本安装已经完成。
3、源码安装
相关阅读 >>
mysql查询今天、昨天、近7天、近30天、本月、上一月的sql语句
更多相关阅读请进入《sql》频道 >>
数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。