top of page

PostgreSQL Database Administrator – Interview Questions

Writer's picture: rupakcharanv2020rupakcharanv2020

What is the architecture of PostgreSQL?

Question: Can you explain the architecture of PostgreSQL?

Answer: PostgreSQL has a client-server architecture that includes:

  • Postmaster: The main server process managing connections.

  • Shared Buffers: Stores frequently accessed data for faster operations.

  • Background Processes: Includes processes like WAL writer, autovacuum, and stats collector.

  • Storage Layer: Manages data files and WAL logs for durability.

  • Libpq: The communication interface between the client and the server.


How do you optimize slow queries in PostgreSQL?

Question: How do you identify and optimize slow queries?

Answer:

  1. Analyze with EXPLAIN/EXPLAIN ANALYZE: Shows the query execution plan.

  2. Indexing: Add indexes to columns frequently used in WHERE, JOIN, or GROUP BY.

  3. Vacuum and Analyze: Regularly optimize table statistics.

  4. Rewrite Queries: Simplify complex queries or break them into smaller ones.

  5. Partitioning: Use table partitioning for large datasets.


What are the differences between physical and logical replication?

Question: Can you explain the differences between physical and logical replication?

Answer:

  • Physical Replication:

    • Copies the entire database cluster.

    • Used for standby servers.

    • Operates at the WAL level.

  • Logical Replication:

    • Replicates individual tables.

    • Supports selective replication.

    • Uses a plugin-based system for decoding.


How do you troubleshoot a PostgreSQL database crash?

Question: What steps do you take to investigate and recover from a database crash?

Answer:

  1. Check Logs: Review postgresql.log for error details.

  2. Verify Disk Space: Ensure enough space for data and WAL logs.

  3. Restart Service: Use pg_ctl or systemctl.

  4. WAL Recovery: Ensure WAL files are intact for recovery.

  5. Inspect Configuration: Check for misconfigurations in postgresql.conf.

  6. Hardware Check: Look for disk or memory failures.


What is the role of pg_hba.conf?

Question: What is pg_hba.conf, and how does it work?

Answer: pg_hba.conf (host-based authentication) controls access to the PostgreSQL database. It specifies:

  • Host: IP addresses allowed to connect.

  • Database: Databases that can be accessed.

  • User: Specific users with access permissions.

  • Method: Authentication methods like MD5, SCRAM-SHA-256, or trust.


How do you implement connection pooling in PostgreSQL?

Question: How do you set up connection pooling for PostgreSQL?

Answer: Connection pooling reduces the overhead of creating new connections. You can use tools like:

  • PgBouncer: A lightweight connection pooler for PostgreSQL.

  • Pgpool-II: Provides connection pooling along with load balancing and replication.

  • Configuration: Set parameters like max_connections and idle_in_transaction_session_timeout.


What is auto vacuum, and why is it important?

Question: What is the purpose of auto vacuum in PostgreSQL?

Answer: Auto vacuum automatically reclaims storage occupied by dead tuples, updates table statistics, and prevents transaction ID wraparound. It ensures optimal database performance without manual intervention.


How do you upgrade a PostgreSQL cluster?

Question: What methods can you use to upgrade PostgreSQL?

Answer:

  1. In-Place Upgrade (pg_upgrade): Migrates data to the new version with minimal downtime.

  2. Dump and Restore: Uses pg_dump for exporting and importing data.

  3. Logical Replication: Replicates data to a new server running the upgraded version.


What are the common challenges in PostgreSQL replication?

Question: What issues can arise during PostgreSQL replication?

Answer:

  • Lag in Streaming Replication: Caused by network latency or high transaction volume.

  • WAL File Retention: Missing or deleted WAL files can break replication.

  • Configuration Errors: Misconfigured primary_conninfo or recovery.conf.

  • Disk Space Issues: Insufficient space for WAL files or replication slots.


What are PostgreSQL partitioning and sharding?

Question: What are the differences between partitioning and sharding?

Answer:

  • Partitioning: Splits a table into smaller, manageable pieces within the same database. Useful for performance optimization.

  • Sharding: Distributes data across multiple databases or servers. Used for scalability in large systems.

If you're looking to gain expertise in PostgreSQL, check out PostgreSQL DBA training in Bangalore | Online Training | Vtuit.com PostgreSQL course for in-depth training on installation, configuration, tuning, and more.


5 views0 comments

Related Posts

See All

Comments


bottom of page