小编kri*_*nan的帖子

测量 postgresql 中的复制延迟

我试图测量我的系统中的复制时间滞后。(postgresql 10.1)

pg_last_xact_timestamp()我在查询中使用,pg_last_receive_lsn()和函数的组合pg_last_replay_lsn()来检查滞后。

(以如何从此链接进行测量为例)

postgres=# SELECT now(), pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn(), EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INT;
               now                | pg_last_wal_receive_lsn | pg_last_wal_replay_lsn | date_part 
----------------------------------+-------------------------+------------------------+-----------
 2018-08-06 07:00:36.540959+05:30 | 4/99B84030              | 4/99B84030             |       223
Run Code Online (Sandbox Code Playgroud)

从第2列和第3列可以看出,最后的接收LSN和重放LSN是相同的,这意味着系统是同步的。但我无法理解到底是什么pg_last_xact_replay_timestamp()。它如何找出以秒为单位的复制延迟。我是否使用错误的方法来测量延迟(以秒为单位)?

postgresql database-replication postgresql-10

7
推荐指数
1
解决办法
4199
查看次数

转换为char *后写入std :: atomic

对不起,如果我的怀疑太幼稚。但我有一个类型转换难度std::atomicchar*类型。是强制转换std::atomic to char有效吗?

我可以写这样的类型转换变量。我确信当线程试图将变量写入变量时不会有多线程读/写操作(我知道,当该变量没有并发访问时,就不需要使用原子)。

std::atomic<uint8_t>* data_;
char *data = reinterpret_cast<char*>(data_);
*data |= mask;
Run Code Online (Sandbox Code Playgroud)

安全吗?

编辑:我不确定是否值得一提。在我的代码中

char *raw;
// variable raw is allocated
std::atomic<uint8_t>* data_ = reinterpret_cast<std::atomic<uint8_t>*>(raw);
Run Code Online (Sandbox Code Playgroud)

上面是std::atomic< uint8_t>创建方法的方式(作为char和type强制转换为std :: atomic类型)。

谢谢 :)

c++ memory-layout reinterpret-cast stdatomic

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