首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

RedHat 6.8安装postgresql 10

这个世界并不在乎你的自尊,只在乎你做出来的成绩,然后再去强调你的感受。------比尔.盖茨

一,访问官网

登陆postgresql官网下载地址,并根据自己操作系统信息进行配置下载。

我的操作系统为redhat 6.8,下载地址为:https://www.postgresql.org/download/linux/redhat/

二,下载安装(在联网的状态下)

2.1,选择配置

2.2, Install the repository RPM:

[root@postgredb 桌面]#yum installhttps://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-redhat10-10-2.noarch.rpm

2.3, Install the client packages:

[root@postgredb 桌面]#yum install postgresql10

2.4, Optionally install the server packages:

[root@postgredb 桌面]#yum install postgresql10-server

三,初始化和启动postgresql

[root@postgredb 桌面]# service postgresql-10 initdb

[root@postgredb 桌面]# chkconfig postgresql-10 on

[root@postgredb 桌面]# service postgresql-10 start

四,访问postgresql

4.1,切换用户

postgresql安装过程中,会自动创建用户postgres用户,该用户作为独立用户用来进行postgresql管理

[root@postgredb 桌面]#su - postgres

4.2,登陆数据库

-bash-4.1$ psql

psql (8.4.20, 服务器 10.3)

警告:psql 版本8.4, 服务器版本10.0.

一些psql功能可能无法工作.

输入 "help" 来获取帮助信息.

注:默认情况下psql执行成功后,登陆的数据库为postgres

postgres-# \l

资料库列表

名称 | 拥有者 | 字元编码 | 排序规则 | Ctype | 存取权限

-----------+----------+----------+-------------+-------------+------------------

-----

postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |

template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres

: postgres=CTc/post

gres

template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres

: postgres=CTc/post

gres

(3 行记录)

五,基本操作

5.1,创建数据库

-bash-4.1$ createdb mydb

5.2,删除数据库

-bash-4.1$ dropdb mydb

5.3,登陆创建数据库

-bash-4.1$ psql mydb

5.4,切换数据库

-bash-4.1$ \c postgres

5.5,创建表

mydb=# create table frm_users(id int primary key,name varchar(20));

CREATE TABLE

5.6,查看表

mydb=# \d

关联列表

架构模式 | 名称 | 型别 | 拥有者

----------+-----------+--------+----------

public | frm_users | 资料表 | postgres

(1 行记录)

5.7,查看表结构信息

mydb=# \d frm_users

资料表 "public.frm_users"

栏位 | 型别 | 修饰词

------+-----------------------+--------

id | integer | 非空

name | character varying(20) |

索引:

"frm_users_pkey" PRIMARY KEY, btree (id)

5.8,查看所有schema

postgres=# \dn

架构模式列表

名称 | 拥有者

--------------------+----------

information_schema | postgres

pg_catalog | postgres

pg_toast | postgres

pg_toast_temp_1 | postgres

public | postgres

(5 行记录)

5.9,查看所有角色和用户

postgres=# \dg

角色列表

角色名称 | 属性 | 成员属于

----------------------+----------+--------------------------------------------------------------

pg_monitor | 无法登录 |

pg_read_all_settings | 无法登录 | {}

pg_read_all_stats | 无法登录 | {}

pg_signal_backend | 无法登录 | {}

pg_stat_scan_tables | 无法登录 | {}

postgres | 超级用户 | {}

: 建立角色

: 建立 DB

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180305G0RIE900?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券