Table of Contents
Beginner-Level Questions
PostgreSQL DBA
PostgreSQL Developer
PostgreSQL Designer
Intermediate-Level Questions
PostgreSQL DBA
PostgreSQL Developer
PostgreSQL Designer
Expert-Level Questions
PostgreSQL DBA
PostgreSQL Developer
PostgreSQL Designer
Conclusion
Beginner-Level Questions
These questions cover foundational concepts, basic SQL, and core PostgreSQL principles for entry-level candidates.
PostgreSQL DBA (Beginner)
What is PostgreSQL, and what are its key components?
Type: Basic Understanding
Expected Answer: PostgreSQL is an open-source RDBMS with components like the server, data files, and pgAdmin.
Example: Data directory stores tablespaces and WAL logs.
What is the difference between a PostgreSQL instance and a database?
Type: Conceptual
Expected Answer: An instance is the running server process, while a database is a collection of schemas within it.
What is the role of the postgresql.conf file?
Type: Conceptual
Expected Answer: The postgresql.conf file configures server settings like memory and connections.
What is a tablespace in PostgreSQL?
Type: Basic Understanding
Expected Answer: A tablespace is a logical storage location for database objects.
Example: CREATE TABLESPACE fast_storage LOCATION '/ssd/pgdata';
What is the purpose of the Write-Ahead Log (WAL)?
Type: Conceptual
Expected Answer: WAL records changes for crash recovery and replication.
What are the main PostgreSQL authentication methods?
Type: Conceptual
Expected Answer: Methods include trust, password, and GSSAPI, defined in pg_hba.conf.
What is a backup, and why is it important in PostgreSQL?
Type: Basic Understanding
Expected Answer: A backup is a copy of a database for recovery from data loss or corruption.
What is the difference between a user and a role in PostgreSQL?
Type: Conceptual
Expected Answer: Roles are entities with privileges; users are roles with login capability.
What is the purpose of the template0 and template1 databases?
Type: Conceptual
Expected Answer: template0 is a pristine template, while template1 is customizable for new databases.
What is a checkpoint in PostgreSQL?
Type: Conceptual
Expected Answer: A checkpoint writes dirty buffers to disk, ensuring data consistency.
PostgreSQL Developer (Beginner)
What is SQL, and how does PostgreSQL use it?
Type: Basic Understanding
Expected Answer: SQL is a query language; PostgreSQL extends it with advanced features like JSONB.
Example:
SELECT CURRENT_DATE;
What is a stored procedure in PostgreSQL?
Type: Conceptual
Expected Answer: A stored procedure is a callable SQL block for reusable logic (PostgreSQL 11+).
What is the difference between a function and a stored procedure?
Type: Conceptual
Expected Answer: Functions return values and are query-friendly, while procedures focus on side effects.
Example:
CREATE FUNCTION get_salary(emp_id INT) RETURNS INT AS $$ DECLARE sal INT; BEGIN SELECT salary INTO sal FROM employees WHERE employee_id = emp_id; RETURN sal; END; $$ LANGUAGE plpgsql;
What is a trigger in PostgreSQL?
Type: Conceptual
Expected Answer: A trigger executes a function on DML/DDL events.
Example:
CREATE TRIGGER log_update AFTER UPDATE ON employees FOR EACH ROW EXECUTE FUNCTION log_update_func();
What is a cursor in PostgreSQL?
Type: Conceptual
Expected Answer: A cursor processes query results row by row in PL/pgSQL.
Example:
DECLARE emp_cursor CURSOR FOR SELECT employee_id FROM employees; OPEN emp_cursor; FETCH emp_cursor INTO v_emp_id;
What is the purpose of the SELECT ... FOR UPDATE statement?
Type: Practical
Expected Answer: It locks rows to prevent concurrent updates.
Example:
SELECT * FROM employees WHERE employee_id = 100 FOR UPDATE;
What is a view in PostgreSQL?
Type: Basic Understanding
Expected Answer: A view is a virtual table based on a query.
Example:
CREATE VIEW emp_view AS SELECT employee_id, first_name FROM employees;
What is the difference between DELETE and TRUNCATE?
Type: Conceptual
Expected Answer: DELETE removes specific rows with logging, while TRUNCATE removes all rows without logging.
What is an index, and why is it used?
Type: Basic Understanding
Expected Answer: An index speeds up query performance by organizing data.
Example:
CREATE INDEX idx_emp_id ON employees(employee_id);
What is the purpose of the EXPLAIN command?
Type: Practical
Expected Answer: EXPLAIN shows the query execution plan for optimization.
Example:
EXPLAIN SELECT * FROM employees WHERE employee_id = 100;
PostgreSQL Designer (Beginner)
What is database normalization, and why is it important?
Type: Basic Understanding
Expected Answer: Normalization reduces redundancy and ensures integrity using normal forms (1NF, 2NF, 3NF).
Example: Splitting orders and customers to avoid duplicate data.
What is a primary key in PostgreSQL?
Type: Conceptual
Expected Answer: A primary key uniquely identifies rows and enforces integrity.
What is a foreign key, and how does it work?
Type: Conceptual
Expected Answer: A foreign key links tables, ensuring referential integrity.
Example:
CREATE TABLE orders ( order_id INT PRIMARY KEY, customer_id INT REFERENCES customers(customer_id) );
What is the difference between a logical and physical data model?
Type: Conceptual
Expected Answer: Logical models define data structure conceptually, while physical models specify storage.
What is an ERD (Entity-Relationship Diagram)?
Type: Basic Understanding
Expected Answer: An ERD visualizes entities, attributes, and relationships.
What is a materialized view in PostgreSQL?
Type: Conceptual
Expected Answer: A materialized view stores query results physically for performance.
Example:
CREATE MATERIALIZED VIEW mv_sales AS SELECT SUM(amount) FROM sales;
What is the purpose of a schema in PostgreSQL?
Type: Conceptual
Expected Answer: A schema organizes database objects for modularity and access control.
What is the role of constraints in PostgreSQL?
Type: Basic Understanding
Expected Answer: Constraints enforce rules like uniqueness or nullability.
Example:
ALTER TABLE employees ADD CONSTRAINT emp_pk PRIMARY KEY (employee_id);
What is data modeling, and why is it important?
Type: Basic Understanding
Expected Answer: Data modeling designs the database structure to meet business needs and ensure efficiency.
What is the difference between 1NF and 2NF?
Type: Conceptual
Expected Answer: 1NF eliminates repeating groups, while 2NF ensures non-key attributes depend on the entire primary key.
Intermediate-Level Questions
These questions target candidates with 2–5 years of experience, focusing on practical scenarios, optimization, and advanced PostgreSQL features.
PostgreSQL DBA (Intermediate)
How do you monitor PostgreSQL performance?
Type: Practical
Expected Answer: Use pg_stat_activity, pg_stat_statements, or tools like pgAdmin.
Example:
SELECT * FROM pg_stat_activity WHERE state = 'active';
What is the purpose of the pg_stat_statements extension?
Type: Conceptual
Expected Answer: Tracks query execution statistics for performance analysis.
How do you handle a PostgreSQL server crash?
Type: Scenario-Based
Expected Answer: Check logs, restore from backups, and replay WAL files.
Example:
pg_restore --dbname=mydatabase backup.dump;
What is PostgreSQL streaming replication?
Type: Conceptual
Expected Answer: Streaming replication copies WAL logs to replicas for high availability.
Example:
SELECT * FROM pg_stat_replication;
How do you configure a PostgreSQL backup?
Type: Practical
Expected Answer: Use pg_dump for logical backups or pg_basebackup for physical backups.
Example:
pg_dump -U postgres mydatabase > backup.sql;
What is the difference between synchronous and asynchronous replication?
Type: Conceptual
Expected Answer: Synchronous replication waits for replica confirmation, while asynchronous does not.
How do you troubleshoot a slow PostgreSQL query?
Type: Scenario-Based
Expected Answer: Use EXPLAIN ANALYZE, check indexes, and optimize query structure.
Example:
EXPLAIN ANALYZE SELECT * FROM employees WHERE salary > 50000;
What is the role of the WAL in PostgreSQL?
Type: Conceptual
Expected Answer: WAL ensures durability and supports replication and recovery.
How do you manage user privileges in PostgreSQL?
Type: Practical
Expected Answer: Use GRANT and REVOKE to manage role-based privileges.
Example:
GRANT SELECT ON employees TO hr_role;
What is the purpose of the pg_catalog schema?
Type: Conceptual
Expected Answer: pg_catalog stores system metadata for database objects.
Example:
SELECT * FROM pg_catalog.pg_tables WHERE schemaname = 'public';
PostgreSQL Developer (Intermediate)
How do you optimize a PostgreSQL query for performance?
Type: Practical
Expected Answer: Use indexes, avoid correlated subqueries, and leverage CTEs.
Example:
SELECT e.employee_id, e.first_name FROM employees e WHERE EXISTS (SELECT 1 FROM orders o WHERE o.employee_id = e.employee_id);
What is a Common Table Expression (CTE) in PostgreSQL?
Type: Conceptual
Expected Answer: A CTE is a temporary result set for query readability.
Example:
WITH emp_cte AS ( SELECT employee_id, first_name FROM employees WHERE salary > 50000 ) SELECT * FROM emp_cte;
How do you handle errors in PL/pgSQL?
Type: Practical
Expected Answer: Use EXCEPTION blocks for error handling.
Example:
DO $$ BEGIN PERFORM 1/0; EXCEPTION WHEN division_by_zero THEN RAISE NOTICE 'Division by zero detected'; END; $$;
What is the difference between UNION and UNION ALL?
Type: Conceptual
Expected Answer: UNION removes duplicates, while UNION ALL is faster and keeps all rows.
How do you implement pagination in a PostgreSQL query?
Type: Coding Challenge
Expected Answer:
SELECT * FROM employees ORDER BY employee_id LIMIT 10 OFFSET 20;
What is a table function in PostgreSQL?
Type: Conceptual
Expected Answer: A table function returns a result set, used in queries.
Example:
CREATE FUNCTION get_employees(dept_id INT) RETURNS TABLE (id INT, name TEXT) AS $$ SELECT employee_id, first_name FROM employees WHERE department_id = dept_id; $$ LANGUAGE SQL;
How do you use dynamic SQL in PostgreSQL?
Type: Practical
Expected Answer: Use EXECUTE in PL/pgSQL for dynamic queries.
Example:
DO $$ BEGIN EXECUTE 'SELECT * FROM employees WHERE salary > $1' USING 50000; END; $$;
What is the purpose of the ON CONFLICT clause?
Type: Conceptual
Expected Answer: ON CONFLICT handles unique key conflicts with updates or skips.
Example:
INSERT INTO employees (employee_id, salary) VALUES (100, 60000) ON CONFLICT (employee_id) DO UPDATE SET salary = 60000;
How do you create a sequence in PostgreSQL?
Type: Practical
Expected Answer:
CREATE SEQUENCE emp_seq START 1 INCREMENT 1;
What is the difference between INNER JOIN and LEFT JOIN?
Type: Conceptual
Expected Answer: INNER JOIN returns matching rows, while LEFT JOIN includes all rows from the left table.
PostgreSQL Designer (Intermediate)
How do you design a database schema for a multi-tenant application?
Type: Scenario-Based
Expected Answer: Use separate schemas, databases, or tenant IDs in tables.
Example:
CREATE SCHEMA tenant1; CREATE TABLE tenant1.employees (employee_id INT, name TEXT);
What is the role of indexing in database design?
Type: Conceptual
Expected Answer: Indexes improve query performance but increase storage and maintenance.
How do you handle denormalization in database design?
Type: Scenario-Based
Expected Answer: Denormalize for read-heavy systems, balancing redundancy and performance.
What is a composite key, and when is it used?
Type: Conceptual
Expected Answer: A composite key uses multiple columns for uniqueness when no single column suffices.
How do you model a many-to-many relationship?
Type: Practical
Expected Answer: Use a junction table with foreign keys.
Example:
CREATE TABLE student_courses ( student_id INT, course_id INT, PRIMARY KEY (student_id, course_id) );
What is the role of table partitioning in PostgreSQL?
Type: Conceptual
Expected Answer: Partitioning splits large tables for performance and manageability.
Example:
CREATE TABLE sales ( sale_id INT, sale_date DATE ) PARTITION BY RANGE (sale_date);
How do you ensure data integrity in a database design?
Type: Practical
Expected Answer: Use constraints, triggers, and foreign keys.
What is the difference between BCNF and 3NF?
Type: Conceptual
Expected Answer: BCNF is stricter, ensuring no non-trivial functional dependencies.
How do you design a database for scalability?
Type: Scenario-Based
Expected Answer: Use partitioning, sharding, and replication.
What is the purpose of the information_schema database?
Type: Conceptual
Expected Answer: information_schema provides metadata about database objects.
Example:
SELECT * FROM information_schema.tables WHERE table_schema = 'public';
Expert-Level Questions
These questions challenge senior professionals with complex scenarios, advanced PostgreSQL features, and critical system design tasks.
PostgreSQL DBA (Expert)
How do you implement PostgreSQL logical replication?
Type: Scenario-Based
Expected Answer: Configure publications and subscriptions for logical replication.
Example:
CREATE PUBLICATION my_pub FOR TABLE employees; CREATE SUBSCRIPTION my_sub CONNECTION 'host=remote dbname=mydb' PUBLICATION my_pub;
What is the role of the shared buffer in PostgreSQL?
Type: Conceptual
Expected Answer: Shared buffers cache data pages in memory for faster access.
How do you recover a PostgreSQL database from a corrupted table?
Type: Scenario-Based
Expected Answer: Restore from a backup or use pg_restore with selective recovery.
Example:
pg_restore --table=employees backup.dump;
What is the role of pg_stat_activity?
Type: Conceptual
Expected Answer: Monitors active sessions and queries.
Example:
SELECT * FROM pg_stat_activity WHERE state = 'active';
How do you optimize PostgreSQL for high-concurrency workloads?
Type: Scenario-Based
Expected Answer: Tune work_mem, max_connections, and use connection pooling.
Example:
ALTER SYSTEM SET work_mem = '16MB';
What is the difference between physical and logical replication?
Type: Conceptual
Expected Answer: Physical replication copies data files, while logical replication copies SQL changes.
How do you implement PostgreSQL hot standby?
Type: Practical
Expected Answer: Configure streaming replication with read-only replicas.
Example:
ALTER SYSTEM SET hot_standby = ON;
What is the role of pg_stat_statements in performance tuning?
Type: Practical
Expected Answer: Tracks query performance metrics for optimization.
Example:
SELECT * FROM pg_stat_statements ORDER BY total_exec_time DESC;
How do you handle a replication lag in PostgreSQL?
Type: Scenario-Based
Expected Answer: Optimize queries, increase WAL sender resources, or use parallel apply.
Example:
ALTER SYSTEM SET max_parallel_replay = 4;
What is the role of the pg_cron extension?
Type: Conceptual
Expected Answer: pg_cron schedules recurring tasks.
Example:
SELECT cron.schedule('daily_cleanup', '0 0 * * *', $$DELETE FROM logs WHERE log_date < NOW() - INTERVAL '30 days'$$);
PostgreSQL Developer (Expert)
How do you implement bulk insert in PostgreSQL?
Type: Coding Challenge
Expected Answer:
COPY employees FROM '/data/employees.csv' DELIMITER ',';
What is the difference between a scalar and table function?
Type: Conceptual
Expected Answer: Scalar functions return a single value, while table functions return result sets.
How do you implement parallel query execution in PostgreSQL?
Type: Practical
Expected Answer: Enable parallel query with max_parallel_workers.
Example:
SET max_parallel_workers_per_gather = 4;
What is the role of the LATERAL join?
Type: Conceptual
Expected Answer: LATERAL allows subqueries to reference outer query columns.
Example:
SELECT e.employee_id, d.dept_name FROM employees e CROSS JOIN LATERAL (SELECT dept_name FROM departments WHERE dept_id = e.dept_id) d;
How do you handle JSONB data in PostgreSQL?
Type: Practical
Expected Answer: Use JSONB operators like -> and ->>.
Example:
SELECT data->'name' FROM json_table;
What is the difference between ROW_NUMBER and RANK?
Type: Conceptual
Expected Answer: ROW_NUMBER assigns unique numbers, while RANK assigns same rank for ties.
How do you implement a recursive CTE in PostgreSQL?
Type: Coding Challenge
Expected Answer:
WITH RECURSIVE org_chart AS ( SELECT employee_id, manager_id, first_name FROM employees WHERE manager_id IS NULL UNION ALL SELECT e.employee_id, e.manager_id, e.first_name FROM employees e INNER JOIN org_chart o ON e.manager_id = o.employee_id ) SELECT * FROM org_chart;
What is the role of DO blocks in PostgreSQL?
Type: Practical
Expected Answer: DO executes anonymous PL/pgSQL code.
Example:
DO $$ BEGIN RAISE NOTICE 'Hello, PostgreSQL!'; END; $$;
How do you secure PL/pgSQL code?
Type: Practical
Expected Answer: Use SECURITY DEFINER or role-based permissions.
Example:
CREATE FUNCTION my_func() RETURNS VOID SECURITY DEFINER AS $$ BEGIN SELECT * FROM employees; END; $$ LANGUAGE plpgsql;
What is the difference between a correlated and non-correlated subquery?
Type: Conceptual
Expected Answer: Correlated subqueries reference outer queries, executed per row, while non-correlated are independent.
PostgreSQL Designer (Expert)
How do you design a database for high availability?
Type: Scenario-Based
Expected Answer: Use streaming replication and failover mechanisms.
What is the role of table inheritance in PostgreSQL?
Type: Conceptual
Expected Answer: Table inheritance allows child tables to inherit parent table structure.
Example:
CREATE TABLE employees () INHERITS (people);
How do you implement data archiving in PostgreSQL?
Type: Practical
Expected Answer: Use partitioning and automated jobs.
Example:
ALTER TABLE logs DETACH PARTITION logs_old;
What is the difference between a B-tree and GiST index?
Type: Conceptual
Expected Answer: B-tree indexes support equality and range queries, while GiST supports complex data types like geospatial.
How do you design a database for real-time analytics?
Type: Scenario-Based
Expected Answer: Use materialized views and optimized indexes.
Example:
REFRESH MATERIALIZED VIEW mv_sales;
What is the role of PostgreSQL’s logical decoding?
Type: Conceptual
Expected Answer: Logical decoding extracts changes from WAL for replication or CDC.
How do you model a temporal database?
Type: Practical
Expected Answer: Use range types or timestamp columns.
Example:
CREATE TABLE employee_history ( emp_id INT, valid_period TSRANGE );
What is the difference between OLTP and OLAP in database design?
Type: Conceptual
Expected Answer: OLTP handles transactional data, while OLAP supports analytical queries.
How do you handle schema evolution in a production database?
Type: Scenario-Based
Expected Answer: Use online DDL and backward-compatible changes.
Example:
ALTER TABLE employees ADD COLUMN new_col TEXT NULL;
What is the role of PostgreSQL’s FDW (Foreign Data Wrapper)?
Type: Conceptual
Expected Answer: FDW integrates external data sources into PostgreSQL.
Example:
CREATE FOREIGN TABLE remote_employees () SERVER remote_server;
How do you design a database for GDPR compliance?
Type: Scenario-Based
Expected Answer: Implement data masking and encryption.
Example:
CREATE FUNCTION mask_data() RETURNS TRIGGER AS $$ BEGIN NEW.email = '***'; RETURN NEW; END; $$ LANGUAGE plpgsql;
What is the role of PostgreSQL’s pg_stat_replication?
Type: Conceptual
Expected Answer: Monitors replication status and lag.
How do you design a database for audit logging?
Type: Practical
Expected Answer: Use triggers or pgAudit extension.
Example:
CREATE EXTENSION pgaudit;
What is the difference between a clustered and non-clustered index?
Type: Conceptual
Expected Answer: PostgreSQL does not use clustered indexes; B-tree indexes are non-clustered.
How do you optimize a star schema for data warehousing?
Type: Scenario-Based
Expected Answer: Use denormalized tables and BRIN indexes.
What is the role of PostgreSQL’s pg_dump?
Type: Conceptual
Expected Answer: pg_dump creates logical backups of databases.
How do you design a database for global applications?
Type: Scenario-Based
Expected Answer: Use replication and locale-aware collations.
What is the difference between a unique and non-unique index?
Type: Conceptual
Expected Answer: Unique indexes enforce uniqueness, non-unique do not.
How do you implement row-level security in PostgreSQL?
Type: Practical
Expected Answer: Use RLS policies.
Example:
ALTER TABLE employees ENABLE ROW LEVEL SECURITY; CREATE POLICY emp_policy ON employees USING (department_id = current_user::INT);
What is the role of PostgreSQL’s pg_trgm extension?
Type: Conceptual
Expected Answer: pg_trgm supports trigram-based text search.
Example:
CREATE INDEX trgm_idx ON employees USING GIN (first_name gin_trgm_ops);
How do you design a database for high-concurrency applications?
Type: Scenario-Based
Expected Answer: Use MVCC and connection pooling.
What is the role of PostgreSQL’s pg_stat_bgwriter?
Type: Conceptual
Expected Answer: Monitors background writer activity for performance tuning.
How do you handle data migration across PostgreSQL versions?
Type: Scenario-Based
Expected Answer: Use pg_dump and pg_restore.
Example:
pg_dump -U postgres mydatabase > backup.sql;
What is the role of PostgreSQL’s pg_stat_replication_slots?
Type: Conceptual
Expected Answer: Monitors replication slot activity.
How do you design a database for IoT data?
Type: Scenario-Based
Expected Answer: Use time-based partitioning and JSONB.
Example:
CREATE TABLE sensor_data ( sensor_id INT, timestamp TIMESTAMPTZ, data JSONB ) PARTITION BY RANGE (timestamp);
PostgreSQL Developer (Expert, Continued)
How do you implement a PostgreSQL cron job?
Type: Coding Challenge
Expected Answer:
SELECT cron.schedule('daily_cleanup', '0 0 * * *', $$DELETE FROM logs WHERE log_date < NOW() - INTERVAL '30 days'$$);
What is the role of JSONB in PostgreSQL?
Type: Conceptual
Expected Answer: JSONB stores binary JSON for efficient querying.
Example:
SELECT data->>'name' FROM json_table WHERE data @> '{"city": "New York"}';
How do you handle large datasets in PostgreSQL?
Type: Scenario-Based
Expected Answer: Use COPY, partitioning, and indexing.
What is the difference between SERIAL and UUID?
Type: Conceptual
Expected Answer: SERIAL generates sequential integers, while UUID creates unique strings.
How do you implement a PostgreSQL event trigger?
Type: Coding Challenge
Expected Answer:
CREATE EVENT TRIGGER log_ddl ON ddl_command_start EXECUTE FUNCTION log_ddl_func();
What is the role of ANALYZE in PostgreSQL?
Type: Practical
Expected Answer: Updates planner statistics for query optimization.
Example:
ANALYZE employees;
How do you implement error logging in PostgreSQL?
Type: Practical
Expected Answer: Use PL/pgSQL and log tables.
Example:
CREATE FUNCTION log_error(err_msg TEXT) RETURNS VOID AS $$ BEGIN INSERT INTO error_log (message, log_time) VALUES (err_msg, NOW()); END; $$ LANGUAGE plpgsql;
What is the difference between BIGSERIAL and SERIAL?
Type: Conceptual
Expected Answer: BIGSERIAL uses BIGINT, while SERIAL uses INT.
How do you implement a PostgreSQL job chain?
Type: Practical
Expected Answer: Use pg_cron with dependent tasks.
Example:
SELECT cron.schedule('step2', '0 1 * * *', $$CALL proc2()$$);
What is the role of COPY in PostgreSQL?
Type: Conceptual
Expected Answer: COPY imports/exports data efficiently.
Example:
COPY employees TO '/data/employees.csv' DELIMITER ',';
PostgreSQL Designer (Expert, Continued)
How do you design a database for microservices?
Type: Scenario-Based
Expected Answer: Use separate schemas or databases per microservice.
What is the role of PostgreSQL’s BRIN index?
Type: Conceptual
Expected Answer: BRIN indexes are efficient for large, sequentially ordered data.
How do you implement a data warehouse in PostgreSQL?
Type: Scenario-Based
Expected Answer: Use star schemas and materialized views.
What is the difference between a snowflake and star schema?
Type: Conceptual
Expected Answer: Star schemas are denormalized, while snowflake schemas normalize dimension tables.
How do you design a database for time-series data?
Type: Practical
Expected Answer:
CREATE TABLE time_series ( sensor_id INT, timestamp TIMESTAMPTZ, value FLOAT ) PARTITION BY RANGE (timestamp);
What is the role of PostgreSQL’s pglogical extension?
Type: Conceptual
Expected Answer: pglogical enables advanced logical replication.
How do you handle cross-database queries in PostgreSQL?
Type: Practical
Expected Answer: Use dblink or FDW.
Example:
SELECT * FROM dblink('dbname=otherdb', 'SELECT * FROM employees') AS t(id INT, name TEXT);
What is the role of PostgreSQL’s pg_bouncer?
Type: Conceptual
Expected Answer: pg_bouncer manages connection pooling.
How do you design a database for audit compliance?
Type: Scenario-Based
Expected Answer: Use pgAudit and temporal tables.
Example:
CREATE EXTENSION pgaudit;
What is the difference between a GiST and GIN index?
Type: Conceptual
Expected Answer: GiST supports complex data types, while GIN is optimized for full-text search and arrays.
How do you implement data encryption in PostgreSQL?
Type: Practical
Expected Answer: Use pgcrypto or tablespace encryption.
Example:
CREATE EXTENSION pgcrypto; SELECT pgp_sym_encrypt('data', 'key');
What is the role of PostgreSQL’s TimescaleDB extension?
Type: Conceptual
Expected Answer: TimescaleDB optimizes time-series data storage and querying.
How do you design a database for high-frequency trading?
Type: Scenario-Based
Expected Answer: Use TimescaleDB and optimized indexing.
What is the difference between ACID and BASE properties?
Type: Conceptual
Expected Answer: ACID ensures reliability, while BASE prioritizes availability.
How do you implement a data retention policy?
Type: Practical
Expected Answer: Use partitioning and pg_cron.
Example:
SELECT cron.schedule('drop_old', '0 0 1 * *', $$ALTER TABLE logs DETACH PARTITION logs_old$$);
What is the role of PostgreSQL’s pg_stat_statements?
Type: Conceptual
Expected Answer: Tracks query performance metrics.
How do you design a database for global applications?
Type: Scenario-Based
Expected Answer: Use replication and locale-aware collations.
What is the role of PostgreSQL’s PostGIS extension?
Type: Conceptual
Expected Answer: PostGIS supports geospatial data analysis.
Example:
SELECT ST_Distance(geom1, geom2) FROM locations;
How do you handle schema versioning in PostgreSQL?
Type: Practical
Expected Answer: Use migrations and versioning tables.
Example:
CREATE TABLE schema_version ( version INT, applied_at TIMESTAMPTZ );
What is the difference between a heap and index-organized table?
Type: Conceptual
Expected Answer: PostgreSQL uses heap tables; index-organized tables are Oracle-specific.
How do you implement a change data capture (CDC) system?
Type: Practical
Expected Answer: Use logical decoding and tools like Debezium.
Example:
ALTER TABLE employees REPLICA IDENTITY FULL;
What is the role of PostgreSQL’s pg_stat_archiver?
Type: Conceptual
Expected Answer: Monitors WAL archiving status.
How do you design a database for machine learning workloads?
Type: Scenario-Based
Expected Answer: Use JSONB and optimized indexing.
What is the difference between a unique and non-unique index?
Type: Conceptual
Expected Answer: Unique indexes enforce uniqueness, non-unique do not.
How do you implement a failover mechanism in PostgreSQL?
Type: Practical
Expected Answer: Use streaming replication and tools like Patroni.
Example:
SELECT pg_promote();
What is the role of PostgreSQL’s EXPLAIN ANALYZE?
Type: Conceptual
Expected Answer: Provides detailed query execution statistics.
How do you design a database for event-driven architectures?
Type: Scenario-Based
Expected Answer: Use NOTIFY and triggers.
Example:
NOTIFY my_channel, 'event_data';
What is the difference between a full and incremental backup?
Type: Conceptual
Expected Answer: Full backups copy all data, while incremental copy changes.
How do you implement a data masking solution?
Type: Practical
Expected Answer: Use pgcrypto or views for masking.
Example:
CREATE VIEW masked_employees AS SELECT employee_id, '***' AS email FROM employees;
What is the role of PostgreSQL’s Window Functions?
Type: Conceptual
Expected Answer: Window Functions perform calculations across rows.
Example:
SELECT employee_id, salary, RANK() OVER (PARTITION BY department_id ORDER BY salary) AS rank FROM employees;
How do you design a database for reporting?
Type: Scenario-Based
Expected Answer: Use materialized views and star schemas.
What is the role of PostgreSQL’s pg_stat_user_tables?
Type: Conceptual
Expected Answer: Monitors table-level statistics.
How do you handle large-scale data imports?
Type: Practical
Expected Answer: Use COPY or pg_bulkload.
Example:
COPY employees FROM '/data/employees.csv' DELIMITER ',';
What is the difference between a view and a materialized view?
Type: Conceptual
Expected Answer: Views are virtual, while materialized views store data physically.
How do you implement a distributed transaction in PostgreSQL?
Type: Practical
Expected Answer: Use two-phase commit (2PC).
Example:
PREPARE TRANSACTION 'tx1'; COMMIT PREPARED 'tx1';
What is the role of PostgreSQL’s pg_stat_progress_vacuum?
Type: Conceptual
Expected Answer: Monitors VACUUM operation progress.
How do you design a database for high-performance analytics?
Type: Scenario-Based
Expected Answer: Use TimescaleDB and parallel queries.
What is the difference between a physical and logical data model?
Type: Conceptual
Expected Answer: Physical models define storage, logical models focus on business rules.
How do you implement a backup strategy for a 24/7 database?
Type: Scenario-Based
Expected Answer: Use pg_basebackup and PITR.
Example:
pg_basebackup -D /backup --wal-method=stream;
What is the role of PostgreSQL’s pg_stat_statements extension?
Type: Conceptual
Expected Answer: Tracks query performance for optimization.
No comments:
Post a Comment
Thanks for your valuable comment...........
Md. Mominul Islam