AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

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

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题

全部问题(dba)

Martin Hope
Fajela Tajkiya
Asked: 2023-09-23 23:24:18 +0800 CST

了解 SQL Server 中的完整备份过程:所有分配的盘区都会得到备份吗?

  • 5

我一直在阅读Paul Randal 撰写的关于 SQL Server 备份过程的博客文章,其中概述了完整备份的主要阶段。他提到的一点是,在完整备份期间,进程会读取“所有分配的盘区,无论该盘区中的所有 8 个页面是否都在使用中”。

完整备份有以下主要阶段:

  • 执行检查点。
  • 从数据文件中读取所有正在使用的数据(从技术上讲,读取所有分配的盘区,无论盘区中的所有 8 个页面是否都在使用)。
  • 读取从初始检查点最旧的未提交事务开始到第 2 阶段完成的时间的所有事务日志。这是必要的,以便数据库可以在恢复过程中恢复到一致的时间点(有关更多详细信息,请参阅这篇文章)。
  • (可选地测试所有页面校验和,可选地执行备份压缩,并且可选地执行备份加密)。

这个说法让我想知道到底备份了什么内容。具体来说,备份过程是否包括所有分配的扩展区,即使这些扩展区中的所有页面并未都在使用中?

如果您对此主题有任何见解或澄清,我将不胜感激。预先感谢您的帮助!

sql-server
  • 1 个回答
  • 28 Views
Martin Hope
Shiro
Asked: 2023-09-23 08:50:56 +0800 CST

MariaDB 11.1.2 用于为行号创建自定义列

  • 5

下面两个 sql 在 MariaDB 10.5.8 和 MySQL 5.7 上运行良好

SET @curRow=0;
select @curRow := @curRow + 1 AS row_number, `users`.`name` from `users`

或者

select ROW_NUMBER() OVER (ORDER BY users.id) AS row_number, `users`.`name` from `users`

但是当我在 MariaDB 11.1.2 中运行时,它会抛出错误:查询 1 错误:您的 SQL 语法中有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解在 'row_number, 附近使用的正确语法users。name从users第 1 行开始

我检查了 ChatGPT 3.5 它建议我

SELECT row_number FROM (
SELECT @curRow := @curRow + 1 AS row_number, name
        FROM users, (SELECT @curRow := 0) r
) AS subquery_alias

您遇到的错误是因为您无法使用用户定义的变量直接在 SELECT 子句中生成行号,然后在 MariaDB 中的同一 SELECT 子句中引用它。相反,您应该使用子查询或公用表表达式 (CTE) 来实现此目的。以下是如何使用子查询重写查询。

但它不起作用。那么在 MariaDB 11 中该怎么做呢?

mariadb
  • 1 个回答
  • 15 Views
Martin Hope
Ben Holness
Asked: 2023-09-23 02:53:34 +0800 CST

我如何在Mysql中按“发布”排序,例如10.10在10.9之后,前后都有非数字条目?

  • 6

如果我有一个按照https://www.db-fiddle.com/f/arPEdUty3U6AJEQfqYEyRc/1的表格,其中包含版本列表:

INSERT INTO `releases` (`ReleaseID`, `ReleaseNumber`) VALUES
(1, '10.6'),
(2, '10.8'),
(3, '_TBD'),
(4, '10.9'),
(5, 'Future'),
(6, '10.10'),
(7, '10.11');

我如何对其进行排序,以便_首先出现以开头的内容,然后是数字,顺序为10.6, 10.8, 10.9, 10.10, 10.11, 然后是其他内容?

我当前的铸造尝试(CAST(ReleaseNumber as SIGNED INTEGER)放在Future后面_TBD而不是放在最后。

这个例子的期望输出是

_TBD,,,,,,,, 10.6_ 10.8_ 10.9_ 10.10_ 10.11_Future

mysql
  • 1 个回答
  • 17 Views
Martin Hope
Bart Jonk
Asked: 2023-09-22 16:50:34 +0800 CST

如何更好地使用WITH来参数化日期

  • 6

我喜欢使用 CTE 来创建漂亮且清晰的查询。但是,我很确定我创建的查询效率确实很低。

有没有更好的方法来做到这一点并使事情变得清晰?

with first_date as (
    -- selecting just 1 date 
    --    namely:  1 full year ago
    select (extract(year from current_date - interval '1 year')||'-01-01' )::date as date
    )
, last_date as (
    select date from star.dim_date where current_cal_day='Current'
)
, total_active_customers_ps_day as(
  select
        dd.date
        , dd.is_first_day_in_month
        , dd.is_last_day_in_month   
        , count(dc.id) as total_customers
    from first_date, last_date,
        star.dim_date dd
        -- join with dim_client, using first_subscription_start_date & last_subscription_end_date
        --   to get the ids of just the active clients 
        join star.dim_client dc on dd.date 
            between dc.first_subscription_start_date and coalesce(dc.last_subscription_end_date::date, '3000-01-01') 
            and dc.created <= dd.date
            and dc.first_subscription_start_date >= dc.created::date
    where 
        dd.date >= first_date.date
        and dd.date <= last_date.date
    group by 
        dd.date
        , dd.is_first_day_in_month 
        , dd.is_last_day_in_month   
)
select * from total_active_customers_ps_day ;

我认为我引起了一些笛卡尔连接,因为这个查询效率更高

with total_active_customers_ps_day as(
  select
        dd.date
        , dd.is_first_day_in_month
        , dd.is_last_day_in_month   
        , count(dc.id) as total_customers
    from 
        star.dim_date dd
        -- join with dim_client, using first_subscription_start_date & last_subscription_end_date
        --   to get the ids of just the active clients 
        join star.dim_client dc on dd.date 
            between dc.first_subscription_start_date and coalesce(dc.last_subscription_end_date::date, '3000-01-01') 
            and dc.created <= dd.date
            and dc.first_subscription_start_date >= dc.created::date
    where 
        dd.date >=  (extract(year from current_date - interval '1 year')||'-01-01' )::date
        and dd.date <= (select date from star.dim_date where current_cal_day='Current')
    group by 
        dd.date
        , dd.is_first_day_in_month 
        , dd.is_last_day_in_month   
)
select * from total_active_customers_ps_day ;
 

有什么更好的方法来做到这一点?

postgresql
  • 1 个回答
  • 73 Views
Martin Hope
Vinn
Asked: 2023-09-22 10:26:43 +0800 CST

如何获取所有使用 initdb 构建的 postgres 集群的列表?

  • 5

据我了解,要获取集群列表,pg_lscluster我需要使用pg_createcluster.

但是,我使用initdb和pg_ctl来创建集群。我知道它们正在运行,因为我可以使用 访问每个集群(我有三个集群)psql -p [port]。

如何获取使用这些工具构建的集群的列表?

postgresql
  • 2 个回答
  • 25 Views
Martin Hope
Rubén Noriega Mier
Asked: 2023-09-22 00:13:27 +0800 CST

仅分析 PostgreSQL 中的一个分区

  • 5

我有一个metrics按年份和月份(metrics_y2023m01、metrics_y2023m02等)分区的表。该analyze metrics命令单独更新表和每个分区的统计信息,但绝大多数修改发生在当月的分区中,因此我考虑过及时间隔执行整个表的分析并安排每天另一次分析最繁忙的分区。

  • 在不更新父表统计信息的情况下分析单个分区是否有意义?
  • 我可以分析单个分区和父表而不需要分析其他分区吗?
  • 父表的统计信息相对于查询计划器中的分区统计信息的权重是多少?

谢谢。

postgresql
  • 1 个回答
  • 18 Views
Martin Hope
Vipin
Asked: 2023-09-21 22:05:02 +0800 CST

SQL Server 查询性能:SSMS 中的索引查找但 Java 应用程序中的索引扫描

  • 6

我遇到了 SQL Server 查询性能问题,希望能从大家那里得到一些见解。

问题陈述:

我有一个 SQL 查询,当直接在 SQL Server Management Studio (SSMS) 中执行时,性能良好(约 6 毫秒),在执行计划中显示“索引查找”。但是,当使用 JDBC 从我的 Java 应用程序执行相同的查询时,执行计划显示“索引扫描”,并且查询的执行时间明显更长(约 1 秒)。

我尝试过的:

  1. 确保所涉及的表和索引的统计信息是最新的。
  2. 比较 SSMS 和 Java 应用程序之间的执行上下文设置。
  3. 将 SQL 添加到 Stored prod 中,然后它工作正常,进行索引查找。
  4. 删除了计划 ID,清除了缓存。

问题:

  1. 是什么导致了查询性能的这种差异?
  2. 是否有我可能错过的调试步骤?

计划何时从 Java 执行此操作:https://www.brentozar.com/pastetheplan/ ?id=SkWWezsya

计划何时从 SSMS 执行此操作:https://www.brentozar.com/pastetheplan/ ?id=HJZPefokp

任何见解或建议将不胜感激。

sql-server
  • 3 个回答
  • 84 Views
Martin Hope
Qiu Yangfan
Asked: 2023-09-21 21:33:41 +0800 CST

有什么方法可以在 postgresql 扩展中执行并行操作吗?

  • 5

根据此链接,要在 postgresql 扩展中执行并行操作,多线程不是一个选项。

那么还有其他方法吗?比如一些关于多进程的API和用法?也许让我知道在哪里可以找到示例代码?

或者在 Postgresql 扩展中执行并行操作的期望本身根本不合理?您能提供一些解释吗?

更新:关于我想要并行化的东西,它通常与Postgresql无关,而是计算一堆数据的哈希值

postgresql
  • 1 个回答
  • 21 Views
Martin Hope
Tiago Stapenhorst
Asked: 2023-09-21 14:02:15 +0800 CST

如何在 PostgreSQL 中禁用 FOREIGN KEY 引用完整性触发器而不禁用表中的其他触发器?

  • 5

可以通过执行以下命令禁用 PostgreSQL 中的外键引用完整性:

ALTER TABLE schema.my_table 
DISABLE TRIGGER ALL;

但不幸的是,该命令还将禁用表中存在的所有其他触发器。

我尝试在pg_constraint视图中查找外键的名称,但在以下命令中使用它会返回错误:

ALTER TABLE schema.my_table 
DISABLE TRIGGER id_fkey;

-- Returns
-- SQL Error [42704]: ERROR: trigger "id_fkey" for table "my_table" does not exist

如何在不禁用其他触发器的情况下在 PostgreSQL 中禁用引用完整性?

postgresql
  • 1 个回答
  • 21 Views
Martin Hope
sujeet
Asked: 2023-09-21 12:34:23 +0800 CST

向高流量的大型 PostgreSQL 表添加主键

  • 10

我需要向一个高流量的大型 PostgreSQL 表(大约 2TB)添加主键。这是一项关键操作,我正在寻找有关如何有效地完成该操作的指导。

我已经尝试过以下步骤:

-- Step 1: Add id identity column 
ALTER TABLE users
ADD COLUMN id BIGINT GENERATED ALWAYS as IDENTITY;

-- Step 2: Add unique index on (id, user_id) concurrently
CREATE UNIQUE INDEX CONCURRENTLY users_id_user_id_idx
   ON users (id, user_id);

-- verify that step 2 is completed
-- Step 3: Add primary key
ALTER TABLE users
   ADD CONSTRAINT users_pkey PRIMARY KEY USING INDEX users_id_user_id_idx;

我面临两个问题:

  • 表完全锁定在“步骤 1”本身上。

    我知道这是预料之中的,但如果有任何选择可以避免这种情况,请提出建议。

  • 我收到以下错误,

错误:无法扩展文件“base/16401/90996”:设备上没有剩余空间提示:检查可用磁盘空间。

但600GB我的服务器上还有剩余的存储空间。

由于表将被锁定在“第 1 步”,并且如果没有选项可以避免这种情况,我可以利用停机时间id先添加列,然后运行其他两个脚本。

我不知道这是否可以解决存储错误。

请提供任何建议,以便我能够以尽可能少的停机时间添加 PK。

PostgreSQL v14.6

postgresql
  • 1 个回答
  • 618 Views
下一页

Sidebar

Stats

  • 问题 200806
  • 回答 265436
  • 最佳答案 132718
  • 用户 66935
  • 热门
  • 回答
  • 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