AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-27325

Nir's questions

Martin Hope
Nir
Asked: 2023-06-01 18:01:11 +0800 CST

无法解释的空表计数缓慢

  • 5

我的增量物化视图刷新开始变得越来越慢。每天都有数百万条新记录。所以mv日志表上有很多删除。经过调查,我发现一个特定的 sql 花费了大量时间,这可能会导致根本原因。以下是作为 mv 刷新的一部分运行的 SQL 之一:

SQL> select dmltype$$, max(snaptime$$) from "S"."MLOG$_TABLE_202210" group by dmltype$$;

no rows selected

Elapsed: 00:00:12.68

Statistics
----------------------------------------------------------
      7  recursive calls
      0  db block gets
     678822  consistent gets
     678789  physical reads
      0  redo size
    438  bytes sent via SQL*Net to client
     41  bytes received via SQL*Net from client
      1  SQL*Net roundtrips to/from client
      0  sorts (memory)
      0  sorts (disk)
      0  rows processed

正如您所看到的,对这个空 mv 日志表的计数花费了 12 秒!(我们有很多这样的)。原因是物理读取量较高。统计数据的目的是锁定的(就预言机推荐而言)

SQL> select NUM_ROWS,BLOCKS,EMPTY_BLOCKS,AVG_SPACE_FREELIST_BLOCKS,LAST_ANALYZED,STATTYPE_LOCKED,STALE_STATS 
     from dba_tab_statistics 
     where table_name='MLOG$_TABLE_202210';
  NUM_ROWS     BLOCKS EMPTY_BLOCKS AVG_SPACE_FREELIST_BLOCKS LAST_ANAL STATT STALE_S
---------- ---------- ------------ ------------------------- --------- ----- -------
         0          0            0                         0 14-NOV-22 ALL   YES


SQL> SELECT EXTENTS, blocks, bytes
FROM dba_segments
WHERE SEGMENT_NAME = 'MLOG$_TABLE_202210';

  EXTENTS    BLOCKS     BYTES
---------- ---------- ---------- 
        18      384    3145728

因此,如果表不在 SGA 中,它会遍历所有由于多次删除而导致 HWM 较高的块。因为这都是 mv 刷新 - 如果我运行 truncate 它会破坏 MV。

我将不胜感激一些其他建议。

oracle
  • 1 个回答
  • 102 Views
Martin Hope
Nir
Asked: 2023-03-25 17:16:57 +0800 CST

如何使 login.sql 输出静音

  • 5
[nir@dba etl]$ cat login.sql
col TAB# new_value TAB NOPRINT
select chr(9) TAB# from dual;
set markup csv on delimiter "&TAB" quote off
set heading off termout off echo off feedback off verify off numformat 99999999999.9999999999999 null '\N'
[nir@dba etl]$ cat a.sh
#!/bin/bash

export ORACLE_PATH="/home/nir/etl"

echo "select * from dms_u.test_etl_source;" | sqlplus -s ${USER}/${PASS}@${TNS}

[nir@dba etl]$ ./a.sh




aa  \N  aa
\N  aa  aa
aa  aa  \N
\N  \N  aa
\N  aa  \N
aa  \N  \N
\N  \N  \N
aa  aa  aa

我正在使用 将输出login.sql设为sqlplustsv。我想要的是在没有任何输出的情况下运行login.sql。如果我将其放入glogin.sql会-s起作用。但我需要 tsv 登录仅在特定情况下发生(因此ORACLE_PATH)。

所以我想a.sh返回:

[nir@dba etl]$ ./a.sh
aa  \N  aa
\N  aa  aa
aa  aa  \N
\N  \N  aa
\N  aa  \N
aa  \N  \N
\N  \N  \N
aa  aa  aa
oracle
  • 1 个回答
  • 13 Views
Martin Hope
Nir
Asked: 2023-03-15 15:15:47 +0800 CST

如何在 sqlplus 标记中将制表符设置为分隔符

  • 5

我想将sqlplus输出返回为 tsv。为此,我使用set markup csv. 但它不接受制表符作为分隔符,而不是\t实际制表符。

错误是

SP2-1660: Invalid option. Only a single character be specified.

在以下任一方面:

sqlplus -M "CSV on delimiter '\t' QUOTE OFF" -s user/pass@host
sqlplus -M "CSV on delimiter '    ' QUOTE OFF" -s user/pass@host

sqlplus版本是21.0。解决方案必须是sqlplus参数或set命令。

oracle
  • 2 个回答
  • 43 Views
Martin Hope
Nir
Asked: 2022-09-20 01:08:39 +0800 CST

设置为多行[重复]

  • 0
这个问题在这里已经有了答案:
将 IN 子句的长列表转换为临时表 2 个答案
29 天前关闭。

我有以下数据

SQL> SELECT id, relatedIdInASet from tab;

+----+------------------+
| id | relatedIdInASet  |
+----+------------------+
| 1  | [12,34,56]       |
| 2  | [11,12,22,34]    |
+----+------------------+

relatedIdInASet最多text输入 1024 个字符,每行可以包含不同数量的 ID。我们可以在find_in_set上面使用函数,但我们不能索引它......我想规范化数据。我想使用 SQL 创建一个表来解耦集合,因此它将产生:

+----+------------+
| id | relatedId  |
|---+-------------+
| 1  | 12         |
| 1  | 34         |
| 1  | 56         |
| 2  | 11         |
| 2  | 12         |
| 2  | 22         |
| 2  | 34         |
+----+------------+
mysql mysql-5.7
  • 1 个回答
  • 28 Views
Martin Hope
Nir
Asked: 2022-07-25 07:51:05 +0800 CST

psql 转义反斜杠

  • 0

我想逃避反斜杠,\b以便以后可以正常处理它。到目前为止,我使用了一个返回制表符分隔结果的命令,该结果也将空值转换\N为(对于 mysql load into):

PGPASSWORD=$PASS psql -qtAX -U $USER -h $HOST -p $PORT -d $DB -AF $'\t' -P 'null=\N'

有任何想法吗?

postgresql psql
  • 1 个回答
  • 60 Views
Martin Hope
Nir
Asked: 2022-02-10 23:39:33 +0800 CST

NVL 的 Postgres 函数

  • 1

我正在尝试NVL在 postgres 中使用。

create or replace function nvl (anyelement, anyelement)
returns anyelement language sql as $$
    select coalesce(cast( $1 as decimal), cast( $2 as decimal))
$$;

但是,对于以下示例,这对我来说失败了:

testdb=> select nvl(1,2);
ERROR:  return type mismatch in function declared to return integer
DETAIL:  Actual return type is numeric.
CONTEXT:  SQL function "nvl" during inlining

testdb=> SELECT nvl( sum(balance), 0 ) as b FROM db.bank WHERE user = 123;
ERROR:  function nvl(numeric, integer) does not exist
LINE 1: SELECT nvl( sum(balance), 0 ) as b FROM db.bank...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

当我将其更改为:

create or replace function nvl (anyelement, anyelement)
returns anyelement language sql as $$
    select case when $1 is null then $2 else $1 END 
$$;

第一个例子有效。但我仍然有失败:

testdb=> SELECT nvl( sum(balance), 0 ) as b FROM db.bank WHERE user = 123;
ERROR:  function nvl(numeric, integer) does not exist
LINE 1: SELECT nvl( sum(balance), 0 ) as b FROM db.bank...
       

希望得到一些帮助来解决这个问题。

postgresql functions
  • 1 个回答
  • 3689 Views
Martin Hope
Nir
Asked: 2021-11-02 05:14:42 +0800 CST

使用 percona 删除列不会缩小表大小

  • -1

我在 Aurora MySQL 5.7 中有一张表。表的分区很少,行数为 800m,权重为 2tb。最近我使用 percona 删除了几列。令人惊讶的是,桌子的大小没有改变(在information_schema.tables.

percona 进行更改的方式是_<table_name>_new在原始表上使用带有触发器的新表。它创建一个具有相同 DDL 的空新表,执行我们希望的更改,并使用触发器将所有内容复制到新表中以使其保持最新。一旦数据同步 - percona 重命名表并删除旧表。所以表是从头开始构建的(没有锁定)。

但是,运行后alter table optimize partition我看到大小缩小到 250gb。任何人都有解释或知道我做错了什么?

pt 命令:

pt-online-schema-change --user $MYSQL_DBA_USER --password $MYSQL_DBA_PASS --host $MYSQL_WRITER D=db,t=table_data --alter "drop column a1, drop column a2"  --execute --max-load Threads_running=18446744073709551606 --critical-load Threads_running=18446744073709551606 --recursion-method=none

优化命令:

MySQL [(db)]> select table_rows,data_length/power(1024,3), index_length/power(1024,3),DATA_FREE/power(1024,3),AVG_ROW_LENGTH  from information_schema.tables where table_name='table_data';
+------------+---------------------------+----------------------------+-------------------------+----------------+
| table_rows | data_length/power(1024,3) | index_length/power(1024,3) | DATA_FREE/power(1024,3) | AVG_ROW_LENGTH |
+------------+---------------------------+----------------------------+-------------------------+----------------+
|  610884663 |        1847.7273712158203 |         202.40484619140625 |            0.0322265625 |           3247 |
+------------+---------------------------+----------------------------+-------------------------+----------------+
1 row in set (0.00 sec)


MySQL [db]> ALTER TABLE table_data OPTIMIZE PARTITION p20210601;
+---------------+----------+----------+---------------------------------------------------------------------------------------------+
| Table         | Op       | Msg_type | Msg_text                                                                                    |
+---------------+----------+----------+---------------------------------------------------------------------------------------------+
| db.table_data | optimize | note     | Table does not support optimize on partitions. All partitions will be rebuilt and analyzed. |
| db.table_data | optimize | status   | OK                                                                                          |
+------------------------+----------+----------+---------------------------------------------------------------------------------------------+
2 rows in set (5 hours 39 min 40.95 sec)

MySQL [db]>
MySQL [db]> select table_rows,data_length/power(1024,3), index_length/power(1024,3),DATA_FREE/power(1024,3),AVG_ROW_LENGTH  from information_schema.tables where table_name='table_data';


+------------+---------------------------+----------------------------+-------------------------+----------------+
| table_rows | data_length/power(1024,3) | index_length/power(1024,3) | DATA_FREE/power(1024,3) | AVG_ROW_LENGTH |
+------------+---------------------------+----------------------------+-------------------------+----------------+
|  736965899 |        104.25639343261719 |         155.98052978515625 |            0.0244140625 |            151 |
+------------+---------------------------+----------------------------+-------------------------+----------------+
mysql mysql-5.7
  • 1 个回答
  • 120 Views
Martin Hope
Nir
Asked: 2021-04-05 23:16:41 +0800 CST

按左(col,x)文本列分组-可以索引吗?

  • 1

我正在寻找以下可能的索引:

select left(name,10), count(*)
from tab
group by left(name,10)

这是表配置:

create table tab(
id int(11),
name text,
primary key(id),
key name(name(10)))

优化器不使用索引进行选择。知道在 MySQL 中是否可行?例如,在 Oracle 中,我可以在函数上创建索引,这在 MySQL 中是不支持的。

mysql mysql-5.7
  • 2 个回答
  • 34 Views
Martin Hope
Nir
Asked: 2020-12-23 08:06:59 +0800 CST

查找具有重复版本的组

  • 0

我想在表中查找具有重复组版本的所有组。一个组可以有多个组版本。每个组版本可以有多个成员。组“版本”由grpid和定义changeDate。如果一个组版本中的所有成员(和)与同一组中的另一个组版本匹配userid,则该组认为重复。pcthobby

https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=84eb81a1a71dcee9ad3d0bd91f56120a

表groups:

ID grpid 改变日期 用户身份 百分比 爱好 团体版*
1 1 2020-01-01 1 1 1 1
2 1 2020-01-02 1 1 2 2
3 1 2020-01-03 1 1 1 3
4 2 2020-01-01 1 0.5 1 4
5 2 2020-01-01 2 0.5 2 4
6 2 2020-01-02 1 0.5 1 5
7 2 2020-01-02 2 0.5 3 5
8 3 2020-01-01 1 0.5 1 6
9 3 2020-01-01 2 0.5 2 6
10 3 2020-01-02 1 0.4 1 7
11 3 2020-01-02 2 0.6 2 7
12 4 2020-01-01 1 0.6 1 8
13 4 2020-01-01 2 0.4 2 8
14 4 2020-01-02 1 0.6 1 9
15 4 2020-01-02 2 0.4 2 9
16 5 2020-01-01 1 0.2 2 10
17 5 2020-01-01 2 0.5 1 10
18 5 2020-01-01 3 0.3 2 10
19 6 2020-01-01 1 0.3 2 11
20 6 2020-01-01 2 0.5 1 11
21 6 2020-01-01 3 0.2 2 11
22 6 2020-02-01 1 0.2 2 12
23 6 2020-02-01 2 0.5 1 12
24 6 2020-02-01 3 0.3 2 12
25 6 2020-03-01 1 0.3 2 13
26 6 2020-03-01 2 0.3 1 13
27 6 2020-03-01 3 0.4 2 13
28 7 2020-01-01 1 0.3 2 14
29 7 2020-01-01 2 0.5 1 14
30 7 2020-01-01 3 0.2 2 14
31 7 2020-02-01 1 0.3 2 15
32 7 2020-02-01 2 0.5 1 15
33 7 2020-02-01 3 0.2 2 15
34 7 2020-03-01 1 0.3 2 16
35 7 2020-03-01 2 0.3 1 16
36 7 2020-03-01 3 0.4 2 16
37 8 2020-02-01 1 0.3 1 17
38 8 2020-03-01 1 0.3 1 18
39 8 2020-03-01 3 0.4 2 18

*唯一组版本号仅用于可视化。

结果应该是:

grpid
1
4
7

解释:

  • grpid 1 - 有 3 个组版本(1 个成员) - 1 和 3 个重复,因为 userid、pct 和 hobby 相等
  • grpid 2 - 有 2 个组版本(2 个成员) - 不重复,因为 5 和 7 之间的爱好不相等
  • grpid 3 - 有 2 个组版本(2 个成员) - 不重复,因为 pct 在所有成员中都不同
  • grpid 4 - 有 2 个组版本(2 个成员) - 所有成员都是重复的,因为 userid、pct 和 userid 相等
  • grpid 5 - 只有一组 3 名成员 - 不重复
  • grpid 6 - 有 3 个组版本(3 个成员) - 不重复 - 版本之间组中每个成员的 pct 更改
  • grpid 7 - 有 3 个组版本(3 个成员) - 重复,因为 userid、pct 和 userid 在 28-30 和 31-33 之间相等
  • grpid 8 - 有 2 个组版本,一个有一个成员,一个有 2 个成员 - 不重复,因为该组中有另一个成员

我正在使用 MySQL 5.7。

mysql select
  • 3 个回答
  • 119 Views
Martin Hope
Nir
Asked: 2020-11-25 07:07:37 +0800 CST

如何在 MySQL 中转义特殊字符

  • 1

当我select * .. | mysql ... > /tmp/file从带有文本的表中进行操作时,有一些有问题的字符会阻止我使用copy(postgres)或load into(mysql)将其加载到不同的数据库中。诸如制表符、换行符之类的字符会自动转换为\nand \t,但一些有问题的字符是 escape ^[、 CR ^M、^U、^Z、^F,^H也许还有其他我以前没见过的字符。

通常我会像 一样替换它echo "select * .." | mysql .. | sed 's/\r/\\r/g',但是那里有太多未知字符。因此,与其在选择后替换它们,我想要一个检索已经转义的文本的函数(我想删除它们也可以)。

我该怎么做?

mysql encoding
  • 1 个回答
  • 567 Views
Martin Hope
Nir
Asked: 2020-11-23 01:36:31 +0800 CST

将文本列加载到 postgres

  • 2

我使用以下内容将数据加载到 postgres

\copy tab FROM /tmp/file DELIMITER E'\t' QUOTE E'\b' NULL AS '\N' CSV

通常我从源数据库中选择数据

echo "select * from tab" | mysql --batch --quick --skip-column-names .... > /tmp/file

它会生成一个带有制表符分隔符字段的文件。它在大多数情况下运作良好。直到我尝试导入多行文本列。错误出现:

ERROR:  unquoted carriage return found in data

任何建议如何克服这个问题?

postgresql copy
  • 1 个回答
  • 238 Views
Martin Hope
Nir
Asked: 2020-08-03 23:57:34 +0800 CST

从日期中减去列值(以天或月为单位)

  • 1

我想从中减去列中的lag_days值current_date。通常我会做current_date - interval '1 day'

我在以下示例中遇到语法错误,按天减去:

dkarchive=> select current_date - interval lag_days day from example_tbl;
ERROR:  syntax error at or near "day"
LINE 1: select current_date - interval lag_days day from example_tb...
   
postgresql datetime
  • 1 个回答
  • 859 Views
Martin Hope
Nir
Asked: 2020-07-03 07:19:30 +0800 CST

错误的索引被偷看

  • 0

我有一个索引可以过滤 99% 的表,即ix_magic_composite(对于那个查询参数)。当我添加另一个or过滤器时,它选择了错误的索引,即fTS即使我创建了一个以该字段开头的索引,它仍然选择了错误的索引。运行时间是 20 秒对 3 秒到更好的索引。ix_magic_compositeindex 为这两个 SQL 返回(初始过滤器)大约 10 行中的数百万行,同时fTS返回数百万行。

有点不知所措。在我看来,统计数据并没有为引擎提供所有这些列组合的正确图片。

我简化了表格,它有更多的列和索引。

带有良好计划的 SQL:

select *
from tblExample
where 1=1
and status = 'okay'
and textCol > ''
and insrBLN = 1
and (magic is NULL or magic = '')
and (itemId is NULL or itemId = '')
and fTS > '2020-01-01'
and fTS > '2020-01-01'
order by fTS
limit 50

+----+-------------+------------+------------+-------------+--------------------------------------------------+---------------------+---------+-------+---------+----------+----------------------------------------------------+
| id | select_type | table      | partitions | type        | possible_keys                                    | key                 | key_len | ref   | rows    | filtered | Extra                                              |
+----+-------------+------------+------------+-------------+--------------------------------------------------+---------------------+---------+-------+---------+----------+----------------------------------------------------+
|  1 | SIMPLE      | tblExample | NULL       | ref_or_null | textCol,status,textCol_4,ix_magic_composite,fTS  | ix_magic_composite  | 53      | const | 5892974 |     0.24 | Using index condition; Using where; Using filesort |
+----+-------------+------------+------------+-------------+--------------------------------------------------+---------------------+---------+-------+---------+----------+----------------------------------------------------+

带有错误计划的 SQL:

select *
from tblExample
where 1=1
and status = 'okay'
and textCol > ''
and insrBLN = 1
and (magic is NULL or magic = '' or magic = 'retry')
and (itemId is NULL or itemId = '' or itemId = 'retry')
and fTS > '2020-01-01'
and fTS > '2020-01-01'
order by fTS
limit 50

+----+-------------+------------+------------+-------+-------------------------------------------------+---------+---------+------+---------+----------+------------------------------------+
| id | select_type | table      | partitions | type  | possible_keys                                   | key     | key_len | ref  | rows    | filtered | Extra                              |
+----+-------------+------------+------------+-------+-------------------------------------------------+---------+---------+------+---------+----------+------------------------------------+
|  1 | SIMPLE      | tblExample | NULL       | range | textCol,status,textCol_4,ix_magic_composite,fTS | fTS     | 5       | NULL | 6271587 |    0.18  | Using index condition; Using where |
+----+-------------+------------+------------+-------+-----------------------------------------    ----+---------+---------+------+---------+----------+------------------------------------+

桌子:

CREATE TABLE `tblExample` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `fTS` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `status` varchar(50) NOT NULL DEFAULT 'new',
  `textCol` varchar(50) DEFAULT NULL,
  `insrBLN` tinyint(4) NOT NULL DEFAULT '0',
  `itemId` varchar(50) DEFAULT NULL ,
  `magic` varchar(50) DEFAULT NULL ,
  PRIMARY KEY (`id`),
  KEY `ix_magic_composite` (`itemId`,`magic`,`fTS`,`insrBLN`),
  KEY `fTS` (`fTS`)
) ENGINE=InnoDB AUTO_INCREMENT=14391289 DEFAULT CHARSET=latin1

编辑

我们重构了代码,所以查询看起来像:

select *
from tblExample
where 1=1
and status = 'okay'
and textCol > ''
and insrBLN = 1
and (retry = '' or (retry='retry' and retryDT < now() - interval 1 day))
and fTS > '2020-01-01'
order by fTS
limit 50

该问题未排序(还尝试了索引中的不同列顺序)。看起来只有当我删除订单时它才会选择正确的索引。

mysql performance
  • 3 个回答
  • 74 Views
Martin Hope
Nir
Asked: 2020-06-29 01:47:42 +0800 CST

MySQL 阅读解释 - 使用 where

  • 0

在 Oracle 中,解释说明中有一个重要说明,它说首先从磁盘中检索filter a.col1=...这个让您知道col1的内容,然后才完成过滤。这条重要的信息让您知道在特定索引中使用的确切列以及哪些列是过滤后的,并且可能是索引的良好候选者。

在 MySQL 解释结果中,我们看到如下内容:

+----+-------------+-------+------------+--------+--------------------+---------+-------+--------+----------+------------------------------------+
| id | select_type | table | partitions | type   | key                | key_len | ref   | rows   | filtered | Extra                              |
+----+-------------+-------+------------+--------+--------------------+---------+-------+--------+----------+------------------------------------+
|  1 | SIMPLE      | SD    | NULL       | range  | ix_store_composite | 64      | NULL  | 252978 |    60.00 | Using index condition; Using where |
+----+-------------+-------+------------+--------+--------------------+---------+-------+--------+----------+------------------------------------+

我想知道哪些列数据来自索引,哪些在(using where)之后被过滤。我找不到任何选项来获取有关说明的更多详细信息

mysql mysql-5.7
  • 1 个回答
  • 220 Views
Martin Hope
Nir
Asked: 2019-03-28 03:45:42 +0800 CST

从 dba_table 中选择除列表之外的所有表

  • 0

我在查询中遗漏了一些东西。我想从 dba_tables 中选择除表列表之外的所有表。

例如,显示除 HR.DEPT、SCHEMA.TAB 之外的所有内容

dba_tables:

OWNER    TABLE_NAME
------   ----------
HR       DEPT
HR       TEST
SCHEMA   TAB
SCHEMA   NAMES
TEM      TBA

查询后结果:

OWNER    TABLE_NAME
------   ----------
HR       TEST
SCHEMA   NAMES
TEM      TBA

我试过的查询:

select owner, table_name from dba_tables
where (owner != 'HR' and table_name != 'DEPT' )  OR (owner != 'SCHEMA' and table_name != 'TAB' )
oracle select
  • 2 个回答
  • 191 Views
Martin Hope
Nir
Asked: 2018-11-06 07:59:17 +0800 CST

使用 sqlplus 绑定变量和 shell 脚本

  • 0

我希望使用带有 shell 脚本的绑定变量来执行 DML。例如,类似:

#!/bin/bash

SH_NUM=10

sqlplus -S test_user/test_pass <<EOD
var a number;
a:=${SH_NUM}
insert into test_table values(a);
commit;
EOD

我不确定这是否可行,我可以在使用 pl/sql 时使用这种方法,但我想知道我是否也可以使用这种方法。

oracle scripting
  • 1 个回答
  • 1716 Views
Martin Hope
Nir
Asked: 2018-07-30 02:51:49 +0800 CST

将 pg_dump 目录输出更改为表名而不是对象编号

  • 1

pg_dump -F d将导致多个<number>.dat.gz文件代表数据库中的对象编号。我希望pg_dump以这种格式创建这些文件,<table name>.dat.gz这样我就可以在表恢复的情况下轻松区分文件/表。

postgresql pg-dump
  • 1 个回答
  • 670 Views
Martin Hope
Nir
Asked: 2018-07-02 04:00:43 +0800 CST

wal位置到wal档案号

  • 0

我想管理归档到远程位置的副本。为此,我想删除我复制的所有档案,除非备用数据库需要它们。

因此,为了运行,pg_archivecleanup $ARCLOC $CHECKPOINT我需要找到可以删除的最新检查点。我不看最近的.backup文件,因为它对我的存档容量来说太旧了。我想看的是replay_location\ replay_lsn(取决于版本)来自pg_stat_replication.

但是,我不知道如何从replay_location值转换为检查点值。即从某事7/2DBCED18到000000020000000700000029。

回答:

功能是:pg_xlogfile_name

postgresql postgresql-9.5
  • 2 个回答
  • 78 Views
Martin Hope
Nir
Asked: 2018-05-11 00:32:40 +0800 CST

Postgres 复制视图

  • 0

我看到 postgres 中关于复制和滞后时间的两种观点之间存在一些差异。

通过此查询,显然复制已启动:

9.5.6.11

postgres=# select client_addr, sent_location, replay_location from pg_stat_replication where application_name = 'walreceiver';
  client_addr   | sent_location | replay_location
----------------+---------------+-----------------
 172.yyy.yyy.213  | 1C/2B5732F8   | 1C/2B5732F8
 10.xxx.xxx.195 | 1C/2B5732F8   | 1C/2B5732F8
 10.xxx.xxx.196 | 1C/2B5732F8   | 1C/2B5732F8

10.1

postgres=# select client_addr, sent_lsn, replay_lsn from pg_stat_replication where application_name = 'walreceiver';
 client_addr  |  sent_lsn  | replay_lsn
--------------+------------+------------
 10.qqq.qqq.44 | 1/8C000140 | 1/8C000140

但是当寻找滞后时间时:

9.5.6.11

postgres-# SELECT pg_last_xlog_receive_location() ,  pg_last_xlog_replay_location() ,  now() ,  pg_last_xact_replay_timestamp();
 pg_last_xlog_receive_location | pg_last_xlog_replay_location |              now              | pg_last_xact_replay_timestamp
-------------------------------+------------------------------+-------------------------------+-------------------------------
                               |                              | 2018-05-10 04:19:38.079161-04 |

10.1

postgres=# SELECT pg_last_wal_receive_lsn() ,  pg_last_wal_replay_lsn() ,  now() ,  pg_last_xact_replay_timestamp();
 pg_last_wal_receive_lsn | pg_last_wal_replay_lsn |              now              | pg_last_xact_replay_timestamp
-------------------------+------------------------+-------------------------------+-------------------------------
                         |                        | 2018-05-10 04:29:21.730089-04 |

没有信息..我错过了什么?

postgresql replication
  • 1 个回答
  • 559 Views
Martin Hope
Nir
Asked: 2015-09-02 07:00:02 +0800 CST

在 DB2 函数中捕获异常

  • -3

我想在 DB2 函数中捕获异常,如果有异常则返回 0。我不知道正确的语法

create function is_decimal(c_data varchar(100))
RETURNS INTEGER
begin
    select cast(c_data as decimal(12,10)) from sysibm.sysdummy1;

    return 1;

    DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING
    return 0;
end
db2 exception
  • 1 个回答
  • 5692 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve