小编ali*_*ice的帖子

选择下一行和上一行

我有下表:

CREATE TABLE post (
  id            bigint primary key,
  thread_id     bigint,
  is_notice     boolean,
  title         text,
  content       text
)
Run Code Online (Sandbox Code Playgroud)

我使用以下查询显示列表:

SELECT * FROM post ORDER BY is_notice desc, thread_id desc, id
Run Code Online (Sandbox Code Playgroud)

然后,给定由 id(ie SELECT * FROM post where id=3)选择的帖子,我如何检索下一个和上一个帖子?

postgresql select

14
推荐指数
1
解决办法
2万
查看次数

可重复读取不一致

http://www.postgresql.org/docs/9.2/static/transaction-iso.html

可重复读取模式提供了严格的保证,每个事务都可以看到完全稳定的数据库视图。但是,此视图不一定总是与同一级别的并发事务的某些串行(一次一个)执行一致。例如,即使是此级别的只读事务也可能会看到更新的控制记录以显示批次已完成,但看不到逻辑上属于批次的详细记录之一,因为它读取了控制记录的较早版本. 如果不小心使用显式锁来阻止冲突的事务,那么尝试通过在此隔离级别运行的事务来强制执行业务规则是不可能正常工作的。

这不是幻读,在可重复读取模式下是不可能的吗?

文档说可重复读取事务中的查询看到事务开始时的快照,那么查询怎么可能读取不一致的数据?

postgresql concurrency

12
推荐指数
2
解决办法
1120
查看次数

PostgreSQL 中的 TPS 太高

我创建了一个表:

CREATE TABLE foo (
    id integer primary key,
    bar integer NOT NULL
);
Run Code Online (Sandbox Code Playgroud)

并插入一行:

INSERT INTO foo (id, bar) VALUES (1, 1);
Run Code Online (Sandbox Code Playgroud)

并运行以下简单更新语句的 pgbench。

脚本.txt:

update foo set bar=bar+1 where id=1
Run Code Online (Sandbox Code Playgroud)

pgbench 结果:

C:\my-temp>"c:\Program Files\PostgreSQL\9.3\bin\pgbench.exe" -U postgres -c 1 -t 10000 -n -f script.txt testdb
Password:
transaction type: Custom query
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
number of transactions per client: 10000
number of transactions actually processed: 10000/10000
tps = 2052.384567 …
Run Code Online (Sandbox Code Playgroud)

postgresql performance

5
推荐指数
1
解决办法
3082
查看次数

标签 统计

postgresql ×3

concurrency ×1

performance ×1

select ×1