Homeย ย Postgress ย ย Top 10 inte ...

top 10 interview questions and answers of postgress SQL

๐Ÿ”น 1. What are the key differences between PostgreSQL and other RDBMS like MySQL or Oracle?

Answer: PostgreSQL is an object-relational database (ORDBMS), while MySQL is a relational database. Key differences include:


๐Ÿ”น 2. How do you perform backup and recovery in PostgreSQL?

Answer: There are two main backup types:

  1. Logical Backup:

    • pg_dump โ†’ exports single databases
    • pg_dumpall โ†’ exports all databases
    • Advantage: Portable, easy to restore on different versions.
    • Disadvantage: Slow for large datasets.
  2. Physical Backup:

    • pg_basebackup โ†’ copies data directory and WAL files.
    • Can be used to set up streaming replication.
    • Useful for large databases.
  3. Point-in-Time Recovery (PITR):

    • Use continuous WAL archiving.
    • Restore backup + replay WAL logs up to a specific time.

Best practice: Automate backups, test recovery regularly, and combine logical + physical strategies.


๐Ÿ”น 3. Explain MVCC (Multi-Version Concurrency Control) in PostgreSQL.

Answer: MVCC allows concurrent reads and writes without blocking.

This ensures:


๐Ÿ”น 4. What are VACUUM, ANALYZE, REINDEX, and CLUSTER used for?

Answer:


๐Ÿ”น 5. How do you set up replication in PostgreSQL?

Answer:

Replication types:

  1. Streaming Replication (Physical):

    • Primary sends WAL changes to Standby.

    • Standby replays WALs to stay in sync.

    • Setup:

      • Enable wal_level = replica
      • Configure replication slots (pg_create_physical_replication_slot)
      • Use pg_basebackup to copy data directory
      • Configure primary_conninfo in standbyโ€™s recovery.conf
  2. Logical Replication:

    • Replicates at table/data level (not entire cluster).
    • Useful for version upgrades and partial replication.
    • Setup: Create publication on primary โ†’ subscription on standby.

๐Ÿ”น 6. How do you optimize query performance in PostgreSQL?

Answer:


๐Ÿ”น 7. What is WAL (Write Ahead Logging), and why is it important?

Answer:


๐Ÿ”น 8. How do you secure a PostgreSQL database?

Answer:


๐Ÿ”น 9. Whatโ€™s the difference between a Tablespace, Schema, and Database in PostgreSQL?

Answer:

Example:


๐Ÿ”น 10. How do you monitor a PostgreSQL database in production?

Answer:

  1. Built-in Views:

    • pg_stat_activity โ†’ active queries
    • pg_stat_database โ†’ database-level stats
    • pg_stat_replication โ†’ replication lag
    • pg_locks โ†’ lock monitoring
  2. Extensions:

    • pg_stat_statements โ†’ track query performance
    • auto_explain โ†’ log slow queries
  3. External Tools:

    • pgAdmin for admin tasks
    • Prometheus + Grafana for metrics visualization
    • pganalyze / EDB tools for deep insights
  4. Alerts:

    • Monitor replication lag, long-running queries, disk space, and connection count.
Published on: Sep 30, 2025, 07:10 AM ย 
ย 

Comments

Add your comment