MCQs on Partitioning and Sharding | PostgreSQL Database

Dive into PostgreSQL Partitioning and Sharding to understand declarative partitioning, inheritance-based partitioning, sharding setup with FDWs, and techniques for partition maintenance and optimizing performance in large-scale databases.


Declarative Partitioning in PostgreSQL

  1. What is declarative partitioning in PostgreSQL?
    • A) A way to manually partition tables using indexes
    • B) A method of splitting tables into sub-tables based on specific rules
    • C) A technique for distributing data across multiple servers
    • D) A process for setting up foreign keys
  2. Which of the following statements is true about declarative partitioning?
    • A) It allows you to define partitions based on columns with specific ranges.
    • B) It is only available in PostgreSQL versions 9.4 and earlier.
    • C) It requires the creation of multiple schemas.
    • D) Partitioning is not supported in PostgreSQL.
  3. How do you create a partitioned table in PostgreSQL?
    • A) Use the CREATE TABLE command with the PARTITION BY clause
    • B) Use the CREATE PARTITION command
    • C) Use the CREATE SCHEMA command
    • D) Use the ALTER TABLE command
  4. Which of the following is a valid partitioning strategy in PostgreSQL?
    • A) Partition by hash
    • B) Partition by random number
    • C) Partition by range
    • D) Partition by text length
  5. What happens when a partitioned table is queried in PostgreSQL?
    • A) All partitions are scanned.
    • B) Only relevant partitions are queried, improving performance.
    • C) No indexing is used.
    • D) The query is ignored.
  6. Which of the following is a limitation of declarative partitioning in PostgreSQL?
    • A) It cannot handle large data volumes.
    • B) It only supports range partitioning.
    • C) Foreign keys cannot reference partitioned tables.
    • D) It does not allow indexes on partitions.
  7. In which scenario would you use declarative partitioning in PostgreSQL?
    • A) When data can be split into separate ranges or lists
    • B) When multiple servers are required
    • C) When tables need to be stored in different schemas
    • D) When performance tuning is not a priority
  8. What does the PARTITION BY RANGE clause in PostgreSQL define?
    • A) The data type of the partition
    • B) The method of indexing partitions
    • C) The method for dividing data into ranges based on a column
    • D) The storage location for partitioned tables

Inheritance-Based Partitioning

  1. What is inheritance-based partitioning in PostgreSQL?
    • A) A method of table partitioning that uses child tables
    • B) A way of partitioning tables based on inheritance hierarchy
    • C) A feature to enable database inheritance with parent-child relationships
    • D) A method of dividing data using inheritance patterns
  2. In inheritance-based partitioning, what role does the parent table serve?
    • A) It holds actual data
    • B) It is a template for the child tables
    • C) It is only used for indexing
    • D) It is the only table that is queried
  3. Which command is used to create a child table in inheritance-based partitioning?
    • A) CREATE CHILD TABLE
    • B) CREATE TABLE INHERITS
    • C) CREATE PARTITION
    • D) CREATE TABLE AS
  4. Which PostgreSQL version introduced inheritance-based partitioning?
    • A) PostgreSQL 8.0
    • B) PostgreSQL 9.0
    • C) PostgreSQL 9.4
    • D) PostgreSQL 10.0
  5. How do you enforce constraints across all child tables in inheritance-based partitioning?
    • A) Use triggers on each child table
    • B) Use the CHECK constraint on the parent table
    • C) Constraints cannot be used in inheritance-based partitioning
    • D) Use foreign keys only
  6. How does inheritance-based partitioning differ from declarative partitioning?
    • A) It uses foreign keys in partitions
    • B) It is based on inheritance instead of partitioning rules
    • C) It automatically creates indexes on child tables
    • D) It does not require partitioning keys
  7. Which is a disadvantage of inheritance-based partitioning?
    • A) It does not allow child tables to have different structures
    • B) It does not support joins across child tables
    • C) It requires all partitions to be in the same database schema
    • D) It can be slower due to lack of partition pruning
  8. In inheritance-based partitioning, how are queries handled across parent and child tables?
    • A) Queries access only the parent table.
    • B) Queries can automatically include child tables.
    • C) Child tables must be queried separately.
    • D) Parent tables cannot be queried directly.

Setting Up Sharding with FDWs

  1. What is sharding in PostgreSQL?
    • A) Splitting large tables into smaller tables across different databases
    • B) Storing all data in a single table
    • C) Indexing tables for better query performance
    • D) Creating partitions within the same database
  2. Which feature of PostgreSQL is used for sharding?
    • A) Foreign Data Wrappers (FDWs)
    • B) Table inheritance
    • C) Query parallelism
    • D) Table partitioning
  3. How do Foreign Data Wrappers (FDWs) help in sharding PostgreSQL databases?
    • A) By partitioning data within a single database
    • B) By connecting different PostgreSQL instances for distributing data
    • C) By creating redundant copies of data
    • D) By storing data in cloud-based storage systems
  4. Which FDW is typically used for sharding in PostgreSQL?
    • A) postgres_fdw
    • B) file_fdw
    • C) mysql_fdw
    • D) oracle_fdw
  5. What does the postgres_fdw extension allow you to do in PostgreSQL?
    • A) Connect to other PostgreSQL databases for distributed queries
    • B) Store data in foreign file systems
    • C) Encrypt communication between databases
    • D) Partition a table into multiple databases
  6. How does FDW sharding differ from traditional table partitioning?
    • A) FDWs allow data to be split across multiple servers and databases
    • B) FDWs create partitions based on column values
    • C) FDWs do not require foreign keys
    • D) FDWs only work with remote databases
  7. What is a major challenge of setting up sharding with FDWs?
    • A) The need for manual data partitioning
    • B) Synchronization of data across servers
    • C) Limited support for multi-column partitioning
    • D) Lack of indexing capabilities
  8. How does sharding improve PostgreSQL performance?
    • A) By reducing data redundancy
    • B) By distributing data across multiple servers
    • C) By consolidating all queries in one server
    • D) By simplifying complex query optimization

Partition Maintenance and Performance

  1. Which of the following is crucial for maintaining partition performance?
    • A) Ensuring partitions are balanced in size
    • B) Ensuring partitions are indexed properly
    • C) Reducing the number of partitions
    • D) All of the above
  2. What is partition pruning in PostgreSQL?
    • A) Automatically splitting data into smaller partitions
    • B) Eliminating unnecessary partitions during queries
    • C) Merging smaller partitions into larger ones
    • D) Automatically updating data in partitions
  3. How can the performance of partitioned tables be improved?
    • A) By creating indexes on partitioned columns
    • B) By using a single large partition for all data
    • C) By disabling foreign keys in partitions
    • D) By reducing the number of queries
  4. What is a common strategy for partition maintenance in PostgreSQL?
    • A) Creating new partitions over time and dropping old ones
    • B) Merging all partitions into one
    • C) Regularly defragmenting the database
    • D) Adding more indexes to every partition
  5. Which type of partitioning is most effective for time-series data?
    • A) Range partitioning
    • B) Hash partitioning
    • C) List partitioning
    • D) Composite partitioning
  6. What happens if a partition in PostgreSQL is not properly maintained?
    • A) Query performance degrades significantly
    • B) Data redundancy increases
    • C) Tables become locked
    • D) Foreign keys are lost

Answer Key

QnoAnswer
1B) A method of splitting tables into sub-tables based on specific rules
2A) It allows you to define partitions based on columns with specific ranges.
3A) Use the CREATE TABLE command with the PARTITION BY clause
4C) Partition by range
5B) Only relevant partitions are queried, improving performance.
6C) Foreign keys cannot reference partitioned tables.
7A) When data can be split into separate ranges or lists
8C) The method for dividing data into ranges based on a column
9A) A method of table partitioning that uses child tables
10B) It is a template for the child tables
11B) CREATE TABLE INHERITS
12C) PostgreSQL 9.4
13B) Use the CHECK constraint on the parent table
14B) It is based on inheritance instead of partitioning rules
15D) It can be slower due to lack of partition pruning
16B) Queries can automatically include child tables.
17A) Splitting large tables into smaller tables across different databases
18A) Foreign Data Wrappers (FDWs)
19B) By connecting different PostgreSQL instances for distributing data
20A) postgres_fdw
21A) Connect to other PostgreSQL databases for distributed queries
22A) FDWs allow data to be split across multiple servers and databases
23B) Synchronization of data across servers
24B) By distributing data across multiple servers
25D) All of the above
26B) Eliminating unnecessary partitions during queries
27A) By creating indexes on partitioned columns
28A) Creating new partitions over time and dropping old ones
29A) Range partitioning
30A) Query performance degrades significantly

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top