考试科目: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)
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
外国CTO也感兴趣的开源数据库项目——openHalo
小满未满、
621次阅读
2025-04-21 16:58:09
9.9 分高危漏洞,尽快升级到 pgAdmin 4 v9.2 进行修复
严少安
360次阅读
2025-04-11 10:43:23
3月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
345次阅读
2025-04-15 14:48:05
openHalo问世,全球首款基于PostgreSQL兼容MySQL协议的国产开源数据库
严少安
318次阅读
2025-04-07 12:14:29
转发有奖 | PostgreSQL 16 PGCM高级认证课程直播班招生中!
墨天轮小教习
155次阅读
2025-04-14 15:58:34
墨天轮PostgreSQL认证证书快递已发(2025年3月批)
墨天轮小教习
134次阅读
2025-04-03 11:43:25
SQL 优化之 OR 子句改写
xiongcc
100次阅读
2025-04-21 00:08:06
融合Redis缓存的PostgreSQL高可用架构
梧桐
91次阅读
2025-04-08 06:35:40
PostgreSQL拓展PGQ实现解析
chirpyli
89次阅读
2025-04-07 11:23:17
Mysql/Oracle/Postgresql快速批量生成百万级测试数据sql
hongg
78次阅读
2025-04-07 15:32:54
TA的专栏
PostgreSQL 2023最新题库解析
收录13篇内容
Oracle 19c OCP 1Z0-082 题库解析
收录10篇内容