• Home
  • Linux
  • Docker
  • Windows
    • PS
    • C#
    • Exchange Server
  • Other
    • Perl
    • IPV6
    • MacOS
  • DB
    • MSSQL
    • MariaDB
    • PG

auth.db sql dump

Details
Written by: po3dno
Category: MariaDB
Created: 15 October 2026
Hits: 39
-- phpMyAdmin SQL Dump
-- version 5.2.3
-- https://www.phpmyadmin.net/
--
-- Host: vm-ws-stat-db02:3306
-- Generation Time: Oct 15, 2026 at 10:15 AM
-- Server version: 10.6.17-MariaDB
-- PHP Version: 8.3.4

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `auth`
--

DELIMITER $$
--
-- Procedures
--
CREATE DEFINER=`s.barkov`@`%` PROCEDURE `create_new_partitions` (IN `p_schema` VARCHAR(64), IN `p_table` VARCHAR(64), IN `p_days_to_add` INT)  SQL SECURITY INVOKER BEGIN  
   DECLARE done INT DEFAULT FALSE;
   DECLARE current_partition_name varchar(64);
   DECLARE current_partition_ts int;
   
   -- We'll use this cursor later to check
   -- whether a particular already exists.
   -- @partition_name_to_add will be
   -- set later.
   DECLARE cur1 CURSOR FOR 
   SELECT partition_name 
   FROM information_schema.partitions 
   WHERE TABLE_SCHEMA = p_schema 
   AND TABLE_NAME = p_table 
   AND PARTITION_NAME != 'p_first'
   AND PARTITION_NAME != 'p_future'
   AND PARTITION_NAME = @partition_name_to_add;
   
   -- We'll also use this cursor later 
   -- to query our temporary table.
   DECLARE cur2 CURSOR FOR 
   SELECT partition_name, partition_range_ts 
   FROM partitions_to_add;
   
   DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
   
   DROP TEMPORARY TABLE IF EXISTS partitions_to_add;
   
   CREATE TEMPORARY TABLE partitions_to_add (
      partition_name varchar(64),
      partition_range_ts int
   );
   
   SET @partitions_added = FALSE;
   SET @days_ahead = 0;
   
   -- Let's go through a loop and add each day individually between
   -- the current day and the day p_day_to_add in the future.
   WHILE @days_ahead <= p_days_to_add DO
      -- We figure out what the correct month is by adding the
      -- number of months to the current date
      SET @date = CURDATE();
      SET @q = 'SELECT DATE_ADD(?, INTERVAL ? DAY) INTO @day_to_add';
      PREPARE st FROM @q;
      EXECUTE st USING @date, @days_ahead;
      DEALLOCATE PREPARE st;
      SET @days_ahead = @days_ahead + 1;
      
      -- Then we format the month in the same format used
      -- in our partition names.
      SET @q = 'SELECT DATE_FORMAT(@day_to_add, ''%Y%m%d'') INTO @formatted_day_to_add';
      PREPARE st FROM @q;
      EXECUTE st;
      DEALLOCATE PREPARE st;
      
      -- And then we use the formatted date to build the name of the
      -- partition that we want to add. This partition name is
      -- assigned to @partition_name_to_add, which is used in
      -- the cursor declared at the start of the procedure.
      SET @q = 'SELECT CONCAT(''p'', @formatted_day_to_add) INTO @partition_name_to_add';
      PREPARE st FROM @q;
      EXECUTE st;
      DEALLOCATE PREPARE st;
     
      SET done = FALSE; 
      SET @first = TRUE;
     
      -- And then we loop through the results returned by the cursor,
      -- and if a row already exists for the current partition, 
      -- then we do not need to create the partition.
      OPEN cur1;

      read_loop: LOOP
         FETCH cur1 INTO current_partition_name;
      
         -- The cursor returned 0 rows, so we can create the partition.
         IF done AND @first THEN
            SELECT CONCAT('Creating partition: ', @partition_name_to_add);

            -- Now we need to get the end date of the new partition.
            -- Note that the date is for the non-inclusive end range,
            -- so we actually need the date of the first day of the *next* month.

            -- First, let's get a date variable for the first of the partition month
            SET @q = 'SELECT DATE_FORMAT(@day_to_add, ''%Y-%m-%d 00:00:00'') INTO @day_to_add';
            PREPARE st FROM @q;
            EXECUTE st;
            DEALLOCATE PREPARE st; 

            -- Then, let's add 1 month
            SET @q = 'SELECT DATE_ADD(?, INTERVAL 1 DAY) INTO @partition_end_date';
            PREPARE st FROM @q;
            EXECUTE st USING @day_to_add;
            DEALLOCATE PREPARE st;

            -- We need the date in UNIX timestamp format.  
            SELECT UNIX_TIMESTAMP(@partition_end_date) INTO @partition_end_ts;
         
            -- Now insert the information into our temporary table
            INSERT INTO partitions_to_add VALUES (@partition_name_to_add, @partition_end_ts);
            SET @partitions_added = TRUE;
         END IF;
        
         -- Since we had at least one row returned, we know the
         -- partition already exists.
         IF ! @first THEN
            LEAVE read_loop;
         END IF;
        
         SET @first = FALSE;
      END LOOP;
     
     CLOSE cur1;
   END WHILE;
   
   -- Let's actually add the partitions now.
   IF @partitions_added THEN
      -- First we need to build the actual ALTER TABLE query.
      SET @schema = p_schema;
      SET @table = p_table;
      SET @q = 'SELECT CONCAT(''ALTER TABLE '', @schema, ''.'', @table, '' REORGANIZE PARTITION p_future INTO ( '') INTO @query';
      PREPARE st FROM @q;
      EXECUTE st;
      DEALLOCATE PREPARE st;
     
      SET done = FALSE;
      SET @first = TRUE;
     
      OPEN cur2;

      read_loop: LOOP
         FETCH cur2 INTO current_partition_name, current_partition_ts;
       
        IF done THEN
            LEAVE read_loop;
         END IF;
      
         -- If it is not the first partition, 
         -- then we need to add a comma
         IF ! @first THEN
            SET @q = 'SELECT CONCAT(@query, '', '') INTO @query';
            PREPARE st FROM @q;
            EXECUTE st;
            DEALLOCATE PREPARE st;
         END IF;

         -- Add the current partition
         SET @partition_name =  current_partition_name;
         SET @partition_ts =  current_partition_ts;         
         SET @q = 'SELECT CONCAT(@query, ''PARTITION '', @partition_name, '' VALUES LESS THAN ('', @partition_ts, '')'') INTO @query';
         PREPARE st FROM @q;
         EXECUTE st;
         DEALLOCATE PREPARE st;
       
         SET @first = FALSE;
      END LOOP;
     
      CLOSE cur2;
     
      -- We also need to include the p_future partition
      SET @q = 'SELECT CONCAT(@query, '', PARTITION p_future VALUES LESS THAN (MAXVALUE))'') INTO @query';
      PREPARE st FROM @q;
      EXECUTE st;
      DEALLOCATE PREPARE st;
     
      -- And then we prepare and execute the ALTER TABLE query.
      PREPARE st FROM @query;
      EXECUTE st;
      DEALLOCATE PREPARE st;  
   END IF;
   
   DROP TEMPORARY TABLE partitions_to_add;
END$$

CREATE DEFINER=`s.barkov`@`%` PROCEDURE `drop_old_partitions` (`p_schema` VARCHAR(64), `p_table` VARCHAR(64), `p_months_to_keep` INT, `p_seconds_to_sleep` INT)  SQL SECURITY INVOKER BEGIN  
   DECLARE done INT DEFAULT FALSE;
   DECLARE current_partition_name varchar(64);
   
   -- We'll use this cursor later to get
   -- the list of partitions to drop.
   -- @last_partition_name_to_keep will be
   -- set later.
   DECLARE cur1 CURSOR FOR 
   SELECT partition_name 
   FROM information_schema.partitions 
   WHERE TABLE_SCHEMA = p_schema 
   AND TABLE_NAME = p_table 
   AND PARTITION_NAME != 'p_first'
   AND PARTITION_NAME != 'p_future'
   AND PARTITION_NAME < @last_partition_name_to_keep;
   
   DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
   
   -- Now we get the last month of data that we want to keep
   -- by subtracting p_months_to_keep from the current date.
   -- Note that it will actually keep p_months_to_keep+1 partitions,
   -- since the current month is not complete.
   SET @date = CURDATE();
   SET @months_to_keep = p_months_to_keep;   
   SET @q = 'SELECT DATE_SUB(?, INTERVAL ? MONTH) INTO @last_month_to_keep';
   PREPARE st FROM @q;
   EXECUTE st USING @date, @months_to_keep;
   DEALLOCATE PREPARE st;
   
   -- Then we format the last month in the same format used
   -- in our partition names.
   SET @q = 'SELECT DATE_FORMAT(@last_month_to_keep, ''%Y%m'') INTO @formatted_last_month_to_keep';
   PREPARE st FROM @q;
   EXECUTE st;
   DEALLOCATE PREPARE st;
   
   -- And then we use the formatted date to build the name of the
   -- last partition that we want to keep. This partition name is
   -- assigned to @last_partition_name_to_keep, which is used in
   -- the cursor declared at the start of the procedure.
   SET @q = 'SELECT CONCAT(''p'', @formatted_last_month_to_keep) INTO @last_partition_name_to_keep';
   PREPARE st FROM @q;
   EXECUTE st;
   DEALLOCATE PREPARE st;
   
   SELECT CONCAT('Dropping all partitions before: ', @last_partition_name_to_keep);
   
   SET @first = TRUE;
   
   -- And then we loop through all partitions returned by the cursor,
   -- and those partitions are dropped.
   OPEN cur1;

   read_loop: LOOP
      FETCH cur1 INTO current_partition_name;
   
      IF done THEN
         LEAVE read_loop;
      END IF;
     
      IF ! @first AND p_seconds_to_sleep > 0 THEN
         SELECT CONCAT('Sleeping for ', p_seconds_to_sleep, ' seconds');
         SELECT SLEEP(p_seconds_to_sleep);
      END IF;

      SELECT CONCAT('Dropping partition: ', current_partition_name);
   
      -- First we build the ALTER TABLE query.
      SET @schema = p_schema;
      SET @table = p_table;
      SET @partition = current_partition_name;
      SET @q = 'SELECT CONCAT(''ALTER TABLE '', @schema, ''.'', @table, '' DROP PARTITION '', @partition) INTO @query';
      PREPARE st FROM @q;
      EXECUTE st;
      DEALLOCATE PREPARE st;
      
      -- And then we prepare and execute the ALTER TABLE query.
      PREPARE st FROM @query;
      EXECUTE st;
      DEALLOCATE PREPARE st;
     
      SET @first = FALSE;
   END LOOP;
   
   CLOSE cur1;
   
   -- If no partitions were dropped, then we can also skip this.
   IF ! @first THEN
      -- Then we need to get the date of the new first partition.
      -- We need the date in UNIX timestamp format.
      SET @q = 'SELECT DATE_FORMAT(@last_month_to_keep, ''%Y-%m-01 00:00:00'') INTO @new_first_partition_date';
      PREPARE st FROM @q;
      EXECUTE st;
      DEALLOCATE PREPARE st;     
      SELECT UNIX_TIMESTAMP(@new_first_partition_date) INTO @new_first_partition_ts;
     
      -- We also need to get the date of the second partition
      -- since the second partition is also needed for REORGANIZE PARTITION.
      SET @q = 'SELECT DATE_ADD(@new_first_partition_date, INTERVAL 1 MONTH) INTO @second_partition_date';
      PREPARE st FROM @q;
      EXECUTE st;
      DEALLOCATE PREPARE st;
      SELECT UNIX_TIMESTAMP(@second_partition_date) INTO @second_partition_ts;
  
      SELECT CONCAT('Reorganizing first and second partitions. first partition date = ', @new_first_partition_date, ', second partition date = ', @second_partition_date);
   
      -- Then we build the ALTER TABLE query.
      SET @schema = p_schema;
      SET @table = p_table;
      SET @q = 'SELECT CONCAT(''ALTER TABLE '', @schema, ''.'', @table, '' REORGANIZE PARTITION p_first, '', @last_partition_name_to_keep, '' INTO ( PARTITION p_first VALUES LESS THAN ( '', @new_first_partition_ts, '' ), PARTITION '', @last_partition_name_to_keep, '' VALUES LESS THAN ( '', @second_partition_ts, '' ) ) '') INTO @query';
      PREPARE st FROM @q;
      EXECUTE st;
      DEALLOCATE PREPARE st;
     
      -- And then we prepare and execute the ALTER TABLE query.
      PREPARE st FROM @query;
      EXECUTE st;
      DEALLOCATE PREPARE st;
   END IF;
END$$

CREATE DEFINER=`s.barkov`@`%` PROCEDURE `perform_partition_maintenance` (`p_schema` VARCHAR(64), `p_table` VARCHAR(64), `p_months_to_add` INT, `p_months_to_keep` INT, `p_seconds_to_sleep` INT)  SQL SECURITY INVOKER BEGIN 
   CALL auth.drop_old_partitions(p_schema, p_table, p_months_to_keep, p_seconds_to_sleep);
   CALL auth.create_new_partitions(p_schema, p_table, p_months_to_add);
END$$

DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `ecode`
--

CREATE TABLE `ecode` (
  `id` int(11) NOT NULL,
  `eventid` int(11) NOT NULL,
  `status` varchar(10) DEFAULT NULL,
  `kerberos` tinytext DEFAULT NULL,
  `text` tinytext DEFAULT NULL,
  `comment` varchar(20) DEFAULT NULL,
  `showlog` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

--
-- Dumping data for table `ecode`
--

INSERT INTO `ecode` (`id`, `eventid`, `status`, `kerberos`, `text`, `comment`, `showlog`) VALUES
(1, 4769, '0x12', 'Clients credentials have been revoked', 'Account disabled, expired, locked out, logon hours.', NULL, 0),
(2, 4771, '0x18', 'Pre-authentication information was invalid', 'Usually means bad password', 'Возможная причина', 1),
(3, 4768, '0x12', 'Clients credentials have been revoked', 'Account disabled, expired, locked out, logon hours.', NULL, 0),
(4, 4768, '0x6', 'Client not found in Kerberos database', 'Bad user name, or new computer/user account has not replicated to DC yet', NULL, 0),
(5, 4625, '0xc000006e', 'An account failed to log on', 'Unknown user name or bad password.', 'Причина', 1),
(6, 4776, '0xc0000072', 'The domain controller attempted to validate the credentials for an account', 'account is currently disabled', '', 0),
(7, 4625, '0xc0000234', 'An account failed to log on', 'user is currently locked out', 'Попытка входа', 0),
(9, 4625, '0xc000006d', 'An account failed to log on', 'This is either due to a bad username or authentication information', 'Причина', 1),
(10, 4776, '0xc000006a', 'The domain controller attempted to validate the credentials for an account', 'user name is correct but the password is wrong', 'Возможная причина', 1),
(11, 4776, '0xc0000234', 'The domain controller attempted to validate the credentials for an account', 'user is currently locked out', 'Следствие', 0),
(12, 4625, '0xc0000070', 'User logon from unauthorized workstation', 'User logon from unauthorized workstation', 'Попытка входа', 0),
(13, 4625, '0xc0000071', 'User logon with expired password', 'User logon with expired password', 'Попытка входа', 0),
(14, 4625, '0xc0000133', 'Clocks between DC and other computer too far out of sync', 'Clocks between DC and other computer too far out of sync', 'Попытка входа', 0),
(15, 4740, NULL, 'A user account was locked out', 'The indicated user account was locked out after repeated logon failures due to a bad password. See event ID 4767 for account unlocked.', 'Блокировка УЗ', 1),
(16, 4767, NULL, 'A user account was unlocked', 'The user identified by Subject: unlocked the user identified by Target Account:', 'Разблокировка УЗ', 1),
(17, 4723, NULL, 'An attempt was made to change an account\'s password', 'The user attempted to change his/her own password.  Subject and Target should always match. ', 'Смена пароля', 1),
(18, 4724, NULL, 'An attempt was made to reset an accounts password', 'The Subject attempted to reset the password of the Target: ', 'Смена пароля', 1),
(19, 4625, '0xc000018b', 'STATUS_NO_TRUST_SAM_ACCOUNT', 'The SAM database on the Windows Server does not have a computer account for this workstation trust relationship.', '', 1),
(20, 4768, '0x17', 'Password has expired', 'The user’s password has expired.', 'Попытка входа', 0),
(21, 4769, '0x1b', 'Server principal valid for user2user only', 'This error occurs because the service is missing an SPN.\r\n', 'Попытка входа', 0),
(22, 4776, '0xc0000064', 'The domain controller attempted to validate the credentials for an account', 'user name does not exist', 'Следствие', 0),
(23, 4776, '0xc0000071', 'The domain controller attempted to validate the credentials for an account', 'expired password', '', 0),
(24, 4776, '0xc0000173', 'The domain controller attempted to validate the credentials for an account', 'account expiration', '', 0),
(25, 4776, '0xc0000371', 'The domain controller attempted to validate the credentials for an account', 'The local account store does not contain secret material for the specified account.', '', 0),
(26, 4776, '0xc0000199', 'STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT', 'The account used is a computer account. Use your global user account or local user account to access this server.', '', 0),
(27, 4776, '0xc000019a', 'STATUS_NOLOGON_SERVER_TRUST_ACCOUNT', 'The account used is a server trust account. Use your global user account or local user account to access this server.', '', 0),
(28, 4771, '0x12', 'KDC_ERR_CLIENT_REVOKED', 'KDC_ERR_CLIENT_REVOKED', '', 1),
(29, 4771, '0x3c', 'Kerberos pre-authentication failed', 'Generic error (description in e-text)', NULL, 1);

-- --------------------------------------------------------

--
-- Table structure for table `ejson`
--

CREATE TABLE `ejson` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `dt` datetime NOT NULL DEFAULT current_timestamp(),
  `data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`data`)),
  `EventID` int(11) GENERATED ALWAYS AS (json_value(`data`,'$.System.EventID')) VIRTUAL,
  `Computer` varchar(30) GENERATED ALWAYS AS (json_value(`data`,'$.System.Computer')) VIRTUAL,
  `SubjectUserName` varchar(50) GENERATED ALWAYS AS (json_value(`data`,'$.EventData.SubjectUserName')) VIRTUAL,
  `TargetUserName` varchar(50) GENERATED ALWAYS AS (json_value(`data`,'$.EventData.TargetUserName')) VIRTUAL,
  `TargetDomainName` varchar(50) GENERATED ALWAYS AS (json_value(`data`,'$.EventData.TargetDomainName')) VIRTUAL,
  `ServiceName` varchar(50) GENERATED ALWAYS AS (json_value(`data`,'$.EventData.ServiceName')) VIRTUAL,
  `IpAddress` varchar(50) GENERATED ALWAYS AS (json_value(`data`,'$.EventData.IpAddress')) VIRTUAL,
  `Status` varchar(12) GENERATED ALWAYS AS (json_value(`data`,'$.EventData.Status')) VIRTUAL,
  `SystemTime` varchar(30) GENERATED ALWAYS AS (json_value(`data`,'$.System.TimeCreated."@SystemTime"')) VIRTUAL,
  `Workstation` varchar(30) GENERATED ALWAYS AS (json_value(`data`,'$.EventData.Workstation')) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
PARTITION BY RANGE (to_days(`dt`))
(
PARTITION p_first VALUES LESS THAN (0) ENGINE=InnoDB,
PARTITION p_20261012 VALUES LESS THAN (740267) ENGINE=InnoDB,
PARTITION p_20261013 VALUES LESS THAN (740268) ENGINE=InnoDB,
PARTITION p_20261014 VALUES LESS THAN (740269) ENGINE=InnoDB,
PARTITION p_20261015 VALUES LESS THAN (740270) ENGINE=InnoDB,
PARTITION p_20261016 VALUES LESS THAN (740271) ENGINE=InnoDB,
PARTITION p_future VALUES LESS THAN MAXVALUE ENGINE=InnoDB
);

-- --------------------------------------------------------

--
-- Table structure for table `stat`
--

CREATE TABLE `stat` (
  `id` int(11) NOT NULL,
  `login` varchar(50) NOT NULL,
  `count` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `ecode`
--
ALTER TABLE `ecode`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `ejson`
--
ALTER TABLE `ejson`
  ADD PRIMARY KEY (`id`,`dt`),
  ADD KEY `EventID` (`EventID`),
  ADD KEY `Computer` (`Computer`),
  ADD KEY `TargetUserName` (`TargetUserName`),
  ADD KEY `TargetDomainName` (`TargetDomainName`),
  ADD KEY `ServiceName` (`ServiceName`),
  ADD KEY `IpAddress` (`IpAddress`),
  ADD KEY `Status` (`Status`),
  ADD KEY `SystemTime` (`SystemTime`),
  ADD KEY `Workstation` (`Workstation`),
  ADD KEY `SubjectUserName` (`SubjectUserName`);

--
-- Indexes for table `stat`
--
ALTER TABLE `stat`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `ecode`
--
ALTER TABLE `ecode`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=30;

--
-- AUTO_INCREMENT for table `ejson`
--
ALTER TABLE `ejson`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16434762509;

--
-- AUTO_INCREMENT for table `stat`
--
ALTER TABLE `stat`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

DELIMITER $$
--
-- Events
--
CREATE DEFINER=`s.barkov`@`%` EVENT `create_partition_ejson` ON SCHEDULE EVERY 1 MONTH STARTS '2021-02-01 00:00:00' ON COMPLETION PRESERVE DISABLE DO CALL auth.create_new_partitions('auth', 'ejson', 1)$$

CREATE DEFINER=`s.barkov`@`%` EVENT `create_partition_ejson_day` ON SCHEDULE EVERY 1 DAY STARTS '2021-02-10 00:05:00' ON COMPLETION PRESERVE ENABLE DO BEGIN
SELECT CONCAT('ALTER TABLE ejson REORGANIZE PARTITION p_future INTO (PARTITION ', concat('p_', DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 DAY), '%Y%m%d')), ' VALUES LESS THAN (TO_DAYS(''', DATE_ADD(CURDATE(), INTERVAL 2 DAY), ''')), PARTITION p_future  VALUES LESS THAN (MAXVALUE))') INTO @q;
PREPARE st FROM @q;
EXECUTE st;
DEALLOCATE PREPARE st;

SELECT CONCAT('ALTER TABLE `ejson` DROP PARTITION ', concat('p_', DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL - 4 DAY), '%Y%m%d'))) into @q2;
PREPARE st2 FROM @q2;
EXECUTE st2;
DEALLOCATE PREPARE st2;
END$$

DELIMITER ;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

partition 1

Details
Written by: po3dno
Category: MariaDB
Created: 07 October 2021
Hits: 1166

ALTER TABLE e_5136_copy
REORGANIZE PARTITION p_future INTO (
PARTITION p_202201 VALUES LESS THAN (TO_DAYS('2022-02-01 00:00:00')),
PARTITION p_future VALUES LESS THAN MAXVALUE);


ALTER TABLE e_5136
REORGANIZE PARTITION p_future INTO (
PARTITION p_202201 VALUES LESS THAN (TO_DAYS('2022-02-01 00:00:00')),
PARTITION p_202202 VALUES LESS THAN (TO_DAYS('2022-03-01 00:00:00')),
PARTITION p_202203 VALUES LESS THAN (TO_DAYS('2022-04-01 00:00:00')),
PARTITION p_202204 VALUES LESS THAN (TO_DAYS('2022-05-01 00:00:00')),
PARTITION p_202205 VALUES LESS THAN (TO_DAYS('2022-06-01 00:00:00')),
PARTITION p_202206 VALUES LESS THAN (TO_DAYS('2022-07-01 00:00:00')),
PARTITION p_202207 VALUES LESS THAN (TO_DAYS('2022-08-01 00:00:00')),
PARTITION p_202208 VALUES LESS THAN (TO_DAYS('2022-09-01 00:00:00')),
PARTITION p_202209 VALUES LESS THAN (TO_DAYS('2022-10-01 00:00:00')),
PARTITION p_202210 VALUES LESS THAN (TO_DAYS('2022-11-01 00:00:00')),
PARTITION p_202211 VALUES LESS THAN (TO_DAYS('2022-12-01 00:00:00')),
PARTITION p_202212 VALUES LESS THAN (TO_DAYS('2023-01-01 00:00:00')),
PARTITION p_future VALUES LESS THAN MAXVALUE);

MariaDB partition

Details
Written by: po3dno
Category: MariaDB
Created: 09 February 2021
Hits: 1321
alter table app_log_Test drop PRIMARY KEY, add primary key (`id`, `dateCreated`);

Next, I can re-run my alter table to add the partitions I care about.

ALTER TABLE app_log_Test
PARTITION BY RANGE (TO_DAYS(dateCreated))
    (PARTITION p_invalid_date VALUES LESS THAN (0) ENGINE = TokuDB,
    PARTITION p_201809 VALUES LESS THAN (TO_DAYS('2018-09-01 00:00:00')),
    PARTITION p_201810 VALUES LESS THAN (TO_DAYS('2018-10-01 00:00:00')),
    PARTITION p_max_future_dates VALUES LESS THAN MAXVALUE);

If I need to add more partitions after that. I don't have to specify the partition scheme again I can just add the partition and its constraints.

ALTER TABLE app_log_Test
    REORGANIZE PARTITION p_max_future_dates INTO (
        PARTITION p_201811 VALUES LESS THAN (TO_DAYS('2018-11-01 00:00:00')),
        PARTITION p_201812 VALUES LESS THAN (TO_DAYS('2018-12-01 00:00:00')),
        PARTITION p_max_future_dates  VALUES LESS THAN MAXVALUE);  

My table now looks like this.

show create table app_log_Test;
Create Table: CREATE TABLE `app_log_Test` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `dateCreated` datetime NOT NULL,
  `host` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `label` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `event` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `level` varchar(8) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `message` text COLLATE utf8mb4_unicode_ci,
  `version` bigint(20) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`,`dateCreated`),
  KEY `app_log_dateCreated` (`dateCreated`),
  KEY `app_log_label` (`label`),
  KEY `app_log_event` (`event`),
  KEY `app_log_level` (`level`)
) ENGINE=TokuDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `COMPRESSION`=tokudb_zlib

Automatic Partition Maintenance in MariaDB

Details
Written by: po3dno
Category: MariaDB
Created: 05 February 2021
Hits: 1322

A MariaDB Support customer recently asked how they could automatically drop old partitions after 6 months. MariaDB does not have a mechanism to do this automatically out-of-the-box, but it is not too difficult to create a custom stored procedure and an event to call the procedure on the desired schedule. In fact, it is also possible to go even further and create a stored procedure that can also automatically add new partitions. In this blog post, I will show how to write stored procedures that perform these tasks.

PARTITIONED TABLE DEFINITION

For this demonstration, I’ll use a table definition based on one from MySQL’s documentation on range partitioning, with some minor changes:

DROP TABLE IF EXISTS db1.quarterly_report_status;

CREATE TABLE db1.quarterly_report_status (
   report_id INT NOT NULL,
   report_status VARCHAR(20) NOT NULL,
   report_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB
PARTITION BY RANGE ( UNIX_TIMESTAMP(report_updated) ) (
   PARTITION p_first VALUES LESS THAN ( UNIX_TIMESTAMP('2016-10-01 00:00:00')),
   PARTITION p201610 VALUES LESS THAN ( UNIX_TIMESTAMP('2016-11-01 00:00:00')),
   PARTITION p201611 VALUES LESS THAN ( UNIX_TIMESTAMP('2016-12-01 00:00:00')),
   PARTITION p201612 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-01-01 00:00:00')),
   PARTITION p201701 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-02-01 00:00:00')),
   PARTITION p201702 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-03-01 00:00:00')),
   PARTITION p201703 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-04-01 00:00:00')),
   PARTITION p201704 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-05-01 00:00:00')),
   PARTITION p201705 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-06-01 00:00:00')),
   PARTITION p201706 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-07-01 00:00:00')),
   PARTITION p201707 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-08-01 00:00:00')),
   PARTITION p201708 VALUES LESS THAN ( UNIX_TIMESTAMP('2017-09-01 00:00:00')),
   PARTITION p_future VALUES LESS THAN (MAXVALUE)
);

Read more …

Login Form

  • Forgot your password?
  • Forgot your username?

Statistics

  • Users 3
  • Articles 179
  • Articles View Hits 179511