陈老师:1415968548 郑老师:2735197625 乐老师:354331153
客服热线:
19941464235/19906632509(微信同号)

客服微信

【PostgreSQL PGCE-091题目解析24】PostgreSQL由于多版本的实现,实际读取行数据时,并不会在行上执行任何锁(包括读锁)

作者:炎燚小寶
原创
发布时间:2023-12-22 17:45
浏览量:161

考试科目PGCE-E-091

考试题量:44 道单项选择题、29 道多项选择题(每题 2 分)

通过分数:60%

考试时间:60min

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



PostgreSQL由于多版本的实现,实际读取行数据时,并不会在行上执行任何锁(包括读锁)

A. 正确

B. 错误

参考答案:A



解析

1、查看当前琐的状态

testdb=# select locktype,database,relation::regclass,transactionid,pid,mode from pg_locks;
  locktype  | database | relation | transactionid |  pid  | mode
------------+----------+----------+---------------+-------+-----------------
relation    |    16391 | pg_locks |               | 18405 | AccessShareLock
virtualxid  |          |          |               | 18405 | ExclusiveLock
(2 rows)


2、开启事务1437修改数据

testdb=# begin;
BEGIN
testdb=*# update t1 set id=111 where id=11;
UPDATE 1
testdb=*# select pg_backend_pid();
pg_backend_pid
----------------
18973
(1 row)

testdb=*# select txid_current();
txid_current
--------------
1437
(1 row)


3、开启事务1438查询数据

testdb=# begin;
BEGIN
testdb=*# select * from t1;
id
----
11
(1 row)

testdb=*# select pg_backend_pid();
pg_backend_pid
----------------
18505
(1 row)

testdb=*# select txid_current();
txid_current
--------------
1438
(1 row)


4、查看琐

testdb=# select locktype,database,relation::regclass,transactionid,pid,mode from pg_locks;
locktype | database | relation | transactionid | pid | mode
---------------+----------+----------+---------------+-------+------------------
relation | 16391 | pg_locks | | 18405 | AccessShareLock
virtualxid | | | | 18405 | ExclusiveLock
relation | 16391 | t1 | | 18973 | RowExclusiveLock
virtualxid | | | | 18973 | ExclusiveLock
relation | 16391 | t1 | | 18505 | AccessShareLock
virtualxid | | | | 18505 | ExclusiveLock
transactionid | | | 1437 | 18973 | ExclusiveLock
(7 rows)


5、继续在事务1438执行update

testdb=*# update t1 set id=111 where id=11;
。。。。hang死


6、查看琐

testdb=# select locktype,database,relation::regclass,transactionid,pid,mode from pg_locks;
locktype | database | relation | transactionid | pid | mode
---------------+----------+----------+---------------+-------+------------------
relation | 16391 | pg_locks | | 18405 | AccessShareLock
virtualxid | | | | 18405 | ExclusiveLock
relation | 16391 | t1 | | 18973 | RowExclusiveLock
virtualxid | | | | 18973 | ExclusiveLock
relation | 16391 | t1 | | 18505 | AccessShareLock
virtualxid | | | | 18505 | ExclusiveLock
transactionid | | | 1437 | 18973 | ExclusiveLock
(7 rows)


结论:


查询语句对应的后台进程18505,在对象表t1上申请了AccessShareLock


PostgreSQL PGCE考试为理论考试,需通过两门考试才能拿到“PostgreSQL PGCE证书”。



以下是PostgreSQL官网的考试费,可以添加云贝教育的课程顾问老师微信19941464235或者19906632509,咨询有优惠


PostgreSQL证书如下 合格考生公布:考后不超过 5 个工作日  “开源软件联盟 PostgreSQL 分会”公众号发布  证书寄送:考后统一寄送至培训机构)



云贝教育有专业的PostgreSQL PGCE认证培训课程,想快速通过考试的同学可以扫码联系老师咨询(点击文字转跳至PostgreSQL PGCE纲)