云贝教育 |【PostgreSQL PGCA题目解析6】在PostgresSQL的数据目录结构中,默认表空间的目录是哪个?

news/2024/7/9 20:55:21 标签: postgresql, 数据库, 学习, PostgreSQL

考试科目:PGCA-E-090

考试题数:40 道单项选择题、10 道多项选择题(每题 2 分)

通过分数:60%

考试时间:60min

本文为云贝教育刘峰(微信:yunbee_DBA)原创,请尊重知识产权,转发请注明出处,不接受任何抄袭、演绎和未经注明出处的转载。


在PostgresSQL的数据目录结构中,默认表空间的目录是哪个?

A.base

B.global

C.pg_tblsp

D.pg_log

参考答案:A


解析这个题目前,我们先了解下pg中的表空间

一、super用户创建表空间

testdb=# select user;
   user
----------
 postgres
(1 row)
testdb=# CREATE TABLESPACE fastspace LOCATION '/home/postgres/fastspace';
2023-10-24 10:03:59.323 CST [114668] LOG:  statement: CREATE TABLESPACE fastspace LOCATION '/home/postgres/fastspace';
CREATE TABLESPACE

如果用普通用户创建,则提示:ERROR:  permission denied to create tablespace "fastspace"

testdb=> CREATE TABLESPACE fastspace LOCATION '/home/postgres/fastspace';
ERROR:  permission denied to create tablespace "fastspace"
HINT:  Must be superuser to create a tablespace.


二、在表空间上创建表

1)给用户授权在表空间中创建对象

grant create on tablespace fastspace to test;


查看新建表空间的OID

testdb=# select * from pg_tablespace where spcname='fastspace';
  oid  |  spcname  | spcowner |                spcacl                 | spcoptions
-------+-----------+----------+---------------------------------------+------------
 24599 | fastspace |       10 | {postgres=C/postgres,test=C/postgres} |
(1 row)


2)不授权无法创建表

testdb=> create table s1.t2(id int) tablespace fastspace;
ERROR:  permission denied for tablespace fastspace

3)普通用户创建表

testdb=> create table s1.t2(id int) tablespace fastspace;
CREATE TABLE


三、查看路径对象

testdb=> select pg_relation_filepath('s1.t2');
            pg_relation_filepath
---------------------------------------------
 pg_tblspc/24599/PG_15_202209061/16391/24600


这个路径省略了默认的$PGDATA目录

[postgres@ora19c02 pg_tblspc]$ pwd
/data/pgdata/data/pg_tblspc
[postgres@ora19c02 pg_tblspc]$ ll
total 0
lrwxrwxrwx 1 postgres postgres 21 Oct 18 15:05 16395 -> /home/postgres/tbs_t1
lrwxrwxrwx 1 postgres postgres 24 Oct 24 10:03 24599 -> /home/postgres/fastspace


四、设置默认表空间

SET default_tablespace = fastspace;


创建表

CREATE TABLE s1.foo(i int);


查看对象路径

testdb=> select pg_relation_filepath('s1.foo');

解析

可以通过以下视图查看默认表空间

testdb=# select * from pg_tablespace;
  oid  |  spcname   | spcowner |                spcacl                 | spcoptions
-------+------------+----------+---------------------------------------+------------
  1663 | pg_default |       10 |                                       |
  1664 | pg_global  |       10 |                                       |
 16395 | tbs_t1     |       10 |                                       |
 24599 | fastspace  |       10 | {postgres=C/postgres,test=C/postgres} |
(4 rows)

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

相关文章

关于java agent

关于java agent技术,可以看看这个文章, 聊聊JavaAgent - 知乎

21.Oracle的程序包(Package)

Oracle的程序包Package 一、Package的概述1、什么是Oracle11g的Package2、Package的作用是什么3、常见的系统内置Package 二、创建Package的相关语法1、Package的创建语法2、Package的删除3、具体案例4、Package的使用5、与Package相关的其他语法 三、常见内置程序包的使用1、…

数据结构与算法之二叉树: LeetCode 226. 翻转二叉树 (Typescript版)

翻转二叉树 https://leetcode.cn/problems/invert-binary-tree/ 描述 给你一棵二叉树的根节点 root ,翻转这棵二叉树,并返回其根节点。 示例 1 4 4/ \ / \2 7 >…

基于鱼鹰算法优化概率神经网络PNN的分类预测 - 附代码

基于鱼鹰算法优化概率神经网络PNN的分类预测 - 附代码 文章目录 基于鱼鹰算法优化概率神经网络PNN的分类预测 - 附代码1.PNN网络概述2.变压器故障诊街系统相关背景2.1 模型建立 3.基于鱼鹰优化的PNN网络5.测试结果6.参考文献7.Matlab代码 摘要:针对PNN神经网络的光滑…

实战Flask+BootstrapTable后端传javascript脚本给前端实现多行编辑(ajax方式)

相信看到此文的朋友们一定会感到庆幸,总之我是用了两天死磕,才得到如下结果,且行且珍惜,祝好各位! 话不多说,有图有源码 1.看图 2.前端实现页面 <!DOCTYPE html> {% from "common/_macro.html" import static %} <html> <meta charset"utf-8&…

“消费增值:让每一笔消费创造更多价值“

亲爱的消费者朋友们&#xff0c;你们好&#xff01;今天&#xff0c;我要向你们揭示一种全新的消费理念——消费增值&#xff0c;让你的每一笔消费都变得更有价值&#xff01; 在传统的消费观念中&#xff0c;我们仅仅用金钱来购买物品或享受服务&#xff0c;之后这些物品和服…

flutter开发实战-readmore长文本展开和收缩控件

flutter开发实战-readmore长文本展开和收缩控件 当长文本展开和收缩控件&#xff0c;我们需要使用readmore来处理长文本展开和收缩&#xff0c;方便阅读 一、引入readmore 在工程的pubspec.yaml中引入插件 readmore: ^2.1.0ReadMoreText的属性如下 const ReadMoreText(this.…

融资经理简历模板

这份简历内容&#xff0c;以综合柜员招聘需求为背景&#xff0c;我们制作了1份全面、专业且具有参考价值的简历案例&#xff0c;大家可以灵活借鉴。 融资经理简历在线编辑下载&#xff1a;百度幻主简历 求职意向 求职类型&#xff1a;全职 意向岗位&#xff1a;融资经理 …