postgresql知识大全

news/2024/7/9 21:02:38 标签: postgresql, 数据库

前言

… …

postgresql_4">安装postgresql数据库

centos7.x系统
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql13-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
centos8系统
# Install the repository RPM:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Disable the built-in PostgreSQL module:
sudo dnf -qy module disable postgresql

# Install PostgreSQL:
sudo dnf install -y postgresql13-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13

使用方法

  • 注: 以下为服务器上操作
# 登录postgresql终端
[root@localhost /]# sudo -i -u postgres
[postgres@localhost ~]$

# 登录postgres用户
[postgres@localhost ~]$ psql postgres postgres
psql (13.11)
Type "help" for help.
postgres=# 

# 修改默认用户的密码
postgres=# \password postgres
Enter new password for user "postgres": 
Enter it again:

# 创建数据库
postgres=# CREATE DATABASE department

# 切换数据库
postgres-# \c department
You are now connected to database "department" as user "postgres".

# 创建表department
department-# CREATE TABLE DEPARTMENT(
   ID INT PRIMARY KEY      NOT NULL,
   DEPT           CHAR(50) NOT NULL,
   EMP_ID         INT      NOT NULL
);
CREATE TABLE

# 查看表格是否创建成功
department=# \d
           List of relations
 Schema |    Name    | Type  |  Owner   
--------+------------+-------+----------
 public | department | table | postgres
(1 row)

# 查看表格信息
department=# \d department
                Table "public.department"
 Column |     Type      | Collation | Nullable | Default 
--------+---------------+-----------+----------+---------
 id     | integer       |           | not null | 
 dept   | character(50) |           | not null | 
 emp_id | integer       |           | not null | 
Indexes:
    "department_pkey" PRIMARY KEY, btree (id)

# 插入数据
department=# INSERT INTO DEPARTMENT ( ID , DEPT , EMP_ID ) VALUES ( 1 , 'Paul' , 32 ); 
INSERT 0 1

# 创建只读用户
1. 创建一个用户名为test,密码为devops的用户
department=# CREATE USER test WITH ENCRYPTED PASSWORD 'devops';
CREATE ROLE
2. 修改用户只读事务属性
department=# ALTER USER test SET default_transaction_read_only=on;
ALTER ROLE
3. 设置USAGE权限给到test
department=# GRANT USAGE ON SCHEMA public to test;     
GRANT
4. 在对应的数据库中,授予所有表权限,如select。
GRANT SELECT ON ALL TABLES IN SCHEMA public TO test;
4. 在对应的数据库中,授予单个表权限,如select。
GRANT SELECT ON DEPARTMENT TO test;
GRANT SELECT ON DEPARTMENT.* IN SCHEMA public TO test;

# 查询所有表
sql> select * from pg_tables;
... ...

结语

PostgreSQL Yum Repository Install
PostgreSQL Tutorial


http://www.niftyadmin.cn/n/1007953.html

相关文章

scanf的转换说明符s的简单介绍

s:匹配一串非空白(非\n,\t,空格)字符,然后在末尾添加空字符(也就是\0)。假设相应的实参是指向字符数组的指针。 注意:空格符,制表符,换行符等统称为空白符。 提醒:读入完毕后,在末尾会加\0。提…

【算法系列之贪心算法III】leetcode135. 分发糖果

134. 加油站 力扣题目链接 在一条环路上有 n 个加油站,其中第 i 个加油站有汽油 gas[i] 升。 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。 给定…

【中间件】Ngnix入门

文章目录 下载地址相关概念*反向代理:*负载均衡:轮询权重轮询iphash*动静分离 文件解释/conf/nginx.conf 基本使用双击运行(不建议)使用命令行 常用命令(Linux下) 下载地址 Nginx官网下载页 相关概念 *反…

深入理解 Linux 物理内存分配全链路实现

目录 内核物理内存分配接口 物理内存分配内核源码实现 内存分配的心脏 __alloc_pages prepare_alloc_pages 内存慢速分配入口 alloc_pages_slowpath 总结 内核物理内存分配接口 在物理内存分配成功的情况下, alloc_pages,alloc_page 函数返回的都是指…

短信压力测试系统,支持自定义接口

短信压力测试系统,支持自定义接口 支持卡密充值,短信压力测试系统,解决一切骚扰电话,教程在压缩包里面 可多个服务器挂脚本分担压力,套了cdn导致无法正常执行脚本可以尝试添加白名单 这边建议使用MySQL方式 同服务器下直接配置…

golang实现命令行程序的使用帮助功能

通过flag包我们可以很方便的实现命令行程序的参数标志,接下来我们来看看如何实现命令行程序的使用帮助,通常以参数标志-h或--help的形式来使用。 自动生成使用帮助 我们只需要声明其他参数标志,并执行解析,flag包会帮我们自动生成使用帮助。 //main.g…

从零开始的力扣刷题记录-第七十四天

力扣每日四题 1624. 两个相同字符之间的最长子字符串-简单2269. 找到一个数字的 K 美丽值-简单1143. 最长公共子序列-中等2140. 解决智力问题-中等总结 1624. 两个相同字符之间的最长子字符串-简单 题目描述: 给你一个字符串 s,请你返回 两个相同字符之…

ubuntu 18.04 安装pcl

Ubuntu18.04安装PCL(详细教程)_pcl ubuntu_一盆柠檬的博客-CSDN博客