数据库教程:PostgreSQL入门简介

postgresql简介postgresql是一个免费的对象-关系型数据库服务器(ordbms),遵循灵活的开源协议bsd。postgresql开发者将其念作post-gres-q-l。postgre

postgresql简介

PostgreSQL入门简介

postgresql是一个免费的对象-关系型数据库服务器(ordbms),遵循灵活的开源协议bsd。

postgresql开发者将其念作post-gres-q-l。

postgresql目前是世界上最先进的开源关系型数据库,支持丰富的数据类型(如json、jsonb、数组类型及二进制大对象)和自定义类型。提供了丰富的接口。很容易拓展它的功能,如可以在gist框架下实现自己的索引类型等。

postgresql是完全的事务安全性数据库,完整地支持外键、视图、触发器和存储过程(函数),并支持多种语言开发存储过程,如pl/pgsql、perl、python等。

postgresql对很多高级开发语言有原生的编程接口,如c/c++、java、.net、perl、python、ruby、tcl 和odbc以及其他语言等。

在中国,瀚高数据库是唯一的postgresql商业发行版公司。

什么是数据库?

数据库(database)是按照数据结构来组织、存储和管理数据的仓库。

每个数据库都有一个或多个不同的 api 用于创建,访问,管理,搜索和复制所保存的数据。

我们也可以将数据存储在文件中,但是在文件中读写数据速度相对较慢。

所以,现在我们使用关系型数据库管理系统(rdbms)来存储和管理的大数据量。所谓的关系型数据库,是建立在关系模型基础上的数据库,借助于集合代数等数学概念和方法来处理数据库中的数据。

rdbms 是关系数据库管理系统,是建立实体之间的联系,最后得到的是关系表。

ordbms(对象关系数据库系统)是面向对象技术与传统的关系数据库相结合的产物,查询处理是 ordbms 的重要组成部分,它的性能优劣将直接影响到dbms 的性能。ordbms在原来关系数据库的基础上,增加了一些新的特性。

oodbms 面向对象数据库管理系统,将所有实体都看着对象,并将这些对象类进行封装,对象之间的通信通过消息 oodbms 对象关系数据库在实质上还是关系数据库 。

一、postgresql数据库安装

 1)yum安装

  * 安装存储库  sudo yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat-repo-42.0-11.noarch.rpm  * 安装客户端  sudo yum install postgresql	    * 安装服务端  sudo yum install postgresql-server     * 安装拓展包  sudo yum install postgresql-devel.x86_64   * 安装附加模块  sudo yum install postgresql-contrib.x86_64 

2)验证postgresql安装

  # rpm -qa | grep postgresql  postgresql-libs-9.2.23-3.el7_4.x86_64  postgresql-9.2.23-3.el7_4.x86_64  postgresql-server-9.2.23-3.el7_4.x86_64

3)配置数据库

  * 初始化数据库  sudo /usr/bin/postgresql-setup initdb     * 启动postgresql服务  sudo systemctl start postgresql      * 设置开机自启动  sudo systemctl enable postgresql    * 登录postgresql  su - postgres  psql -u postgres    * 修改postgres用户密码  alter user postgres with encrypted password 'postgres';

4)远程配置 开启远程访问
sudo vi /var/lib/pgsql/data/postgresql.conf

  listen_addresses = '*'     # what ip address(es) to listen on;

信任远程连接
sudo vi /var/lib/pgsql/data/pg_hba.conf

  # ipv4 local connections:  host  all       all       127.0.0.1/32      trust  host  all       all       192.168.9.139/32    trust

重启postgresql服务
systemctl restart postgresql 5)psql连接 连接命令

  psql -d postgres -h 192.168.9.139 -p 5432 -u postgres

6)用户管理

  -- 创建用户  create user admin with password '123456';	  -- 修改密码  alter user admin with encrypted password 'admin';

连接验证
psql -d postgres -h 192.168.9.139 -p 5432 -u admin

二、数据库操作

1)创建数据库

  * 普通创建    create database pgdb;    * 创建指定用户数据库    create database pgadmindb owner admin;	    grant all privileges on database pgadmindb to admin;

2)删除数据库

  * 普通删除    drop database pgdb;    * 判断数据库存在后再删除    drop database if exists pgdb;

3)其它操作

  * 切换数据库    c pgdb;    * 退出数据库    q

三、数据表操作

1)创建表

  create table numerical (   "a" int4,   "b" int4  );

2)删除表

  drop table if exists numerical;

3)加载数据

  insert into numerical (select i, i + 1 from generate_series(1, 10000) as i);

4)清空数据表

  truncate table numerical;

5)查询

  * 统计查询  select count(1) from numerical;    * 累计查询  select sum(a) from numerical;    * 平均查询  select sum(a)/count(1) from numerical;

到此这篇关于postgresql入门简介的文章就介绍到这了,更多相关postgresql入门内容请搜索<计算机技术网(www.ctvol.com)!!>以前的文章或继续浏览下面的相关文章希望大家以后多多支持<计算机技术网(www.ctvol.com)!!>!

需要了解更多数据库技术:PostgreSQL入门简介,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/dtteaching/632040.html

(0)
上一篇 2021年5月31日
下一篇 2021年5月31日

精彩推荐