小编Ada*_*ski的帖子

Postgres唯一约束vs索引

据我所知,文档中的以下定义是等效的:

create table foo (
    id serial primary key,
    code integer,
    label text,
    constraint foo_uq unique (code, label));

create table foo (
    id serial primary key,
    code integer,
    label text);
create unique index foo_idx on foo using btree (code, label);    
Run Code Online (Sandbox Code Playgroud)

但是,您可以在注释中阅读:向表中添加唯一约束的首选方法是ALTER TABLE ... ADD CONSTRAINT.使用索引来强制执行唯一约束可以被视为不应直接访问的实现细节.

这只是一个好风格的问题吗?选择其中一种变体(例如性能)的实际后果是什么?

sql postgresql unique

134
推荐指数
7
解决办法
5万
查看次数

如何列出表的所有锁定行?

我的应用程序使用悲观锁定。当用户打开用于更新记录的表单时,应用程序执行此查询(表名是示例性的):

begin;
select * 
from master m
natural join detail d
where m.master_id = 123456
for update nowait;
Run Code Online (Sandbox Code Playgroud)

该查询锁定一个主行和几个(到几十个)明细行。交易一直持续到用户确认或取消更新。

我需要知道哪些行(至少是主行)被锁定。我挖掘了文档和 postgres wiki 没有成功。

是否可以列出所有锁定的行?

postgresql locking

6
推荐指数
2
解决办法
5836
查看次数

标签 统计

postgresql ×2

locking ×1

sql ×1

unique ×1