Skip to main content

Welcome to DBA Master – Database Tips, Tricks, and Tutorials

Welcome to DBA Master ! This blog is dedicated to all things related to database administration , SQL optimization , and performance tuning . Whether you're a beginner or a seasoned DBA, you'll find practical guides, troubleshooting tips, and real-world tutorials to help you work smarter with data. What to Expect: SQL performance tuning tips Indexing strategies Backup and recovery best practices High availability and replication techniques Database creation, configuration, and setup Monitoring queries and scripts for proactive performance management Migration guides across different database platforms Security essentials and best practices Recommended tools for DBAs Real-world error fixes and how to solve them Stay tuned — exciting content is coming soon. Feel free to bookmark and share: www.dbamaster.com ! Thanks for visiting!

PostgreSQL Partitions

Partition Types:

1. Range
2. List
3. Hash    -->Support PostgreSQL 11
4. Table Inheritance

partition 10 and 11 difference:

1. Update Moves Rows Across Partitions
2. Create Default Partitions
3. Automatic Index Creation
4. Foreign Key Support
5. Unique Indexes

RANGE PARTITION:

postgres=# create table rparent(id int,name text,doj date) partition by range(doj);
CREATE TABLE
postgres=# create table rc1 partition of rparent for values from ('01-jan-2011') to ('01-jan-2012');
CREATE TABLE
postgres=# create table rc2 partition of rparent for values from ('01-jan-2012') to ('01-jan-2013');
CREATE TABLE
postgres=# create table rc3 partition of rparent for values from ('01-jan-2013') to (maxvalue);
CREATE TABLE
postgres=# insert into rparent values (1,'aaa','21-may-2011');
INSERT 0 1
postgres=# insert into rparent values (2,'bbb','01-jun-2012');
INSERT 0 1
postgres=# insert into rparent values (3,'ccc','01-jun-2020');
INSERT 0 1
postgres=# select * from rparent ;
 id | name |    doj   
----+------+------------
  1 | aaa  | 2011-05-21
  2 | bbb  | 2012-06-01
  3 | ccc  | 2020-06-01
(3 rows)

postgres=# select * from rc1;
 id | name |    doj   
----+------+------------
  1 | aaa  | 2011-05-21
(1 row)

postgres=# select * from rc2;
 id | name |    doj   
----+------+------------
  2 | bbb  | 2012-06-01
(1 row)

postgres=# select * from rc3;
 id | name |    doj   
----+------+------------
  3 | ccc  | 2020-06-01
(1 row)

postgres=# \dt+
                      List of relations
 Schema |  Name   | Type  |  Owner   |  Size   | Description
--------+---------+-------+----------+---------+-------------
 public | rc1     | table | postgres | 16 kB   |
 public | rc2     | table | postgres | 16 kB   |
 public | rc3     | table | postgres | 16 kB   |
 public | rparent | table | postgres | 0 bytes |
 public | t1      | table | postgres | 4360 kB |
 public | t2      | table | postgres | 4360 kB |
(6 rows)

postgres=# drop table rparent ;
DROP TABLE
postgres=# \dt+
                    List of relations
 Schema | Name | Type  |  Owner   |  Size   | Description
--------+------+-------+----------+---------+-------------
 public | t1   | table | postgres | 4360 kB |
 public | t2   | table | postgres | 4360 kB |
(2 rows)


LIST PARTITION:

postgres=# create table lparent(id int,name text,place text)partition by list(place);
CREATE TABLE
postgres=# create table lc1 partition of lparent for values in ('chennai');
CREATE TABLE
postgres=# create table lc2 partition of lparent for values in ('madurai','theni');
CREATE TABLE
postgres=# create table lc3 partition of lparent default;
CREATE TABLE
postgres=# insert into lparent values (1,'aaa','chennai');
INSERT 0 1
postgres=# insert into lparent values (1,'aaa','madurai');
INSERT 0 1
postgres=# insert into lparent values (1,'aaa','theni');
INSERT 0 1
postgres=# insert into lparent values (1,'aaa','covai');
INSERT 0 1
postgres=# insert into lparent values (1,'aaa','thiruchy');
INSERT 0 1
postgres=# select * from lparent ;
 id | name |  place 
----+------+----------
  1 | aaa  | chennai
  1 | aaa  | madurai
  1 | aaa  | theni
  1 | aaa  | covai
  1 | aaa  | thiruchy
(5 rows)

postgres=# select * from lc1 ;
 id | name |  place 
----+------+---------
  1 | aaa  | chennai
(1 row)

postgres=# select * from lc2 ;
 id | name |  place 
----+------+---------
  1 | aaa  | madurai
  1 | aaa  | theni
(2 rows)

postgres=# select * from lc3 ;
 id | name |  place 
----+------+----------
  1 | aaa  | covai
  1 | aaa  | thiruchy
(2 rows)

postgres=# create index in_t on lparent (place);
CREATE INDEX
postgres=# \d+ lparent
                                  Table "public.lparent"
 Column |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
 id     | integer |           |          |         | plain    |              |
 name   | text    |           |          |         | extended |              |
 place  | text    |           |          |         | extended |              |
Partition key: LIST (place)
Indexes:
    "in_t" btree (place)
Partitions: lc1 FOR VALUES IN ('chennai'),
            lc2 FOR VALUES IN ('madurai', 'theni'),
            lc3 DEFAULT

HASH PARTITION:

postgres=# create table hparent (id int,name text) partition by hash(id);
CREATE TABLE
postgres=# create table hc1 partition of hparent for values with (MODULUS 3, REMAINDER 0);
CREATE TABLE
postgres=# create table hc2 partition of hparent for values with (MODULUS 3, REMAINDER 1);
CREATE TABLE
postgres=# create table hc3 partition of hparent for values with (MODULUS 3, REMAINDER 2);
CREATE TABLE
postgres=# INSERT INTO hparent values (generate_series(1,20),'asas');
INSERT 0 20
postgres=# select * from hparent ;
 id | name
----+------
  2 | asas
  4 | asas
  6 | asas
  8 | asas
 15 | asas
 16 | asas
 18 | asas
 19 | asas
 20 | asas
  3 | asas
  7 | asas
 10 | asas
 13 | asas
 14 | asas
  1 | asas
  5 | asas
  9 | asas
 11 | asas
 12 | asas
 17 | asas
(20 rows)

postgres=# select * from hc1 ;
 id | name
----+------
  2 | asas
  4 | asas
  6 | asas
  8 | asas
 15 | asas
 16 | asas
 18 | asas
 19 | asas
 20 | asas
(9 rows)

postgres=# select * from hc2 ;
 id | name
----+------
  3 | asas
  7 | asas
 10 | asas
 13 | asas
 14 | asas
(5 rows)

postgres=# select * from hc3 ;
 id | name
----+------
  1 | asas
  5 | asas
  9 | asas
 11 | asas
 12 | asas
 17 | asas
(6 rows)

postgres=# \dt+
                      List of relations
 Schema |  Name   | Type  |  Owner   |  Size   | Description
--------+---------+-------+----------+---------+-------------
 public | hc1     | table | postgres | 16 kB   |
 public | hc2     | table | postgres | 16 kB   |
 public | hc3     | table | postgres | 16 kB   |
 public | hparent | table | postgres | 0 bytes |
 public | lc1     | table | postgres | 16 kB   |
 public | lc2     | table | postgres | 16 kB   |
 public | lc3     | table | postgres | 16 kB   |
 public | lparent | table | postgres | 0 bytes |
 public | t1      | table | postgres | 4360 kB |
 public | t2      | table | postgres | 4360 kB |
(10 rows)

TABLE INHERITS:

postgres=# create table iparent(id int,name text);
CREATE TABLE
postgres=# create table ic1(id int,name text,age int)inherits(iparent);
NOTICE:  merging column "id" with inherited definition
NOTICE:  merging column "name" with inherited definition
CREATE TABLE
postgres=# create table ic2(id int,name text,dob date)inherits(iparent);
NOTICE:  merging column "id" with inherited definition
NOTICE:  merging column "name" with inherited definition
CREATE TABLE
postgres=# insert into iparent values (1,'sa');
INSERT 0 1
postgres=# insert into ic1 values (1,'sa',12);
INSERT 0 1
postgres=# insert into ic2 values (1,'sa','03-jan-2012');
INSERT 0 1
postgres=# select * from iparent ;
 id | name
----+------
  1 | sa
  1 | sa
  1 | sa
(3 rows)

postgres=# select * from ic1 ;
 id | name | age
----+------+-----
  1 | sa   |  12
(1 row)

postgres=# select * from ic2 ;
 id | name |    dob   
----+------+------------
  1 | sa   | 2012-01-03
(1 row)

Comments

Popular posts from this blog

Oracle Database 19C Performance Tunning - PART 1

Advantages: 1. Improved Query Performance •    Optimized SQL execution plans lead to faster query response times. •    Reduces unnecessary full table scans and improves indexing strategies. •    Parallel execution tuning speeds up large data processing tasks. 2. Better Resource Utilization •    Efficient use of CPU, memory, disk I/O, and network resources. •    Reduces contention on Redo Logs, Undo Tablespaces, and Buffer Cache. •    Helps in load balancing across multiple instances in RAC (Real Application Clusters). 3. Increased System Scalability •    Ensures that the database can handle a growing number of users and transactions. •    Proper tuning allows scaling without degrading performance. •    Optimized parallel processing ensures better performance on multi-core servers. 4. Lower Infrastructure Costs •    Reduces the need for add...

Oracle RMAN Backup And Restore

RMAN: (Oracle 8) RMAN (Recovery Manager) is a utility provided by Oracle Database to perform backup, restore, and recovery operations. It is a command line tool. Features of RMAN in Oracle 19c Comprehensive Backup Capabilities: Full and incremental backups. Block-level backups for efficient data storage. Archived redo log backups. Fast Recovery Area (FRA) integration for centralized backup storage. Efficient Recovery Options: Point-in-time recovery (PITR). Complete and incomplete recovery. Flashback database capabilities for quick undo of changes. Multitenant Database Support: RMAN fully supports container databases (CDBs) and pluggable databases (PDBs). Provides flexibility to back up and recover individual PDBs or entire CDBs. Automatic Space Management: Manages disk space in the FRA. Automatically deletes obsolete backups and archived logs. Data Deduplication and Compression: Backup optimization through block-level deduplication. Built-in compression algorithms to reduce storage req...

Oracle 19c Database Software Installation in OEL8

 Pre-requisites for OS level:            Set the static IP Address     Disable the Firewall (systemctl stop firewalld & systemctl disable firewalld)     set SELINUX=permissive on /etc/selinux/config  ##Need to restart the server use init 6 Oracle Installation Pre-requisites Methods     Automatic Setup     Manual Setup      Automatic requisites Setup: (avoid step 1 to step 5): dnf install -y oracle-database-preinstall-19c Install the dependencies: curl -o oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/getPackage/oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm dnf -y localinstall oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm Manual Setup: step 1: Add the karenl parameters and values vi /etc/sysctl.conf     fs.file-max = 6815744 kernel.sem = 250 32000 100 128 kernel....