




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which PostgreSQL background process is responsible for writing dirty buffers from shared memory to the data files? A) WAL Writer B) Checkpointer C) Background Writer D) Autovacuum Worker Answer: C Explanation: The Background Writer periodically flushes dirty shared buffers to disk, reducing the workload of the Checkpointer. Question 2. In PostgreSQL, what is the purpose of the pg_wal directory? A) Stores user tablespaces B) Holds configuration files C) Contains Write‑Ahead Log files D) Keeps temporary files for sorting Answer: C Explanation: pg_wal (formerly pg_xlog) stores WAL segment files that record every change for crash recovery and replication. Question 3. Which configuration parameter controls the maximum number of simultaneous client connections? A) max_worker_processes B) max_connections
C) shared_buffers D) work_mem Answer: B Explanation: max_connections sets the limit on concurrent client connections to the server. Question 4. What does the “listen_addresses” parameter define in postgresql.conf? A) The port number the server listens on B) The IP addresses on which the server accepts connections C) The authentication method for clients D) The directory for log files Answer: B Explanation: listen_addresses lists the network interfaces (IP addresses or hostnames) that the PostgreSQL server will listen to. Question 5. Which scope requires a full server restart to take effect? A) log_line_prefix B) shared_buffers C) work_mem D) default_transaction_isolation Answer: B
Question 8. After initializing a cluster, which command starts the PostgreSQL server using pg_ctl? A) pg_ctl start - D /var/lib/pgsql/data B) pg_ctl init - D /var/lib/pgsql/data C) pg_ctl reload - D /var/lib/pgsql/data D) pg_ctl stop - D /var/lib/pgsql/data Answer: A Explanation: pg_ctl start launches the postmaster process for the data directory specified with - D. Question 9. Which SQL statement creates a new schema named “sales”? A) CREATE DATABASE sales; B) CREATE SCHEMA sales; C) ALTER DATABASE sales SET SCHEMA; D) CREATE TABLE sales_schema; Answer: B Explanation: CREATE SCHEMA defines a logical namespace for database objects. Question 10. What is the effect of the command “DROP DATABASE testdb;” when executed in psql? A) Removes all tables inside testdb but keeps the database itself B) Deletes the physical data directory of testdb
C) Deletes the database and all its objects permanently D) Renames testdb to testdb_old Answer: C Explanation: DROP DATABASE permanently removes the database and all contained objects; it cannot be undone. Question 11. Which psql meta‑command lists all tables in the current database? A) \d B) \dt C) \l D) \c Answer: B Explanation: \dt displays relations of type “table” in the current search_path. Question 12. In psql, what does the “\q” command do? A) Quits the current transaction B) Exits the psql session C) Shows the query plan for the last command D) Queues a command for later execution Answer: B Explanation: \q terminates the interactive psql client.
A) ALTER TABLE users ALTER COLUMN email SET NOT NULL; B) ALTER TABLE users MODIFY email NOT NULL; C) ALTER TABLE users CHANGE email NOT NULL; D) ALTER TABLE users ADD CONSTRAINT email_notnull NOT NULL; Answer: A Explanation: ALTER COLUMN … SET NOT NULL adds the constraint to an existing column. Question 16. What is a temporary table in PostgreSQL? A) A table that persists after the session ends B) A table stored in pg_temp schema and automatically dropped at session end C) A table that lives only on disk, not in memory D) A table that replicates data to standby servers automatically Answer: B Explanation: Temporary tables are scoped to the session and are automatically dropped when the session terminates. Question 17. Which constraint ensures that a column “order_id” contains unique values and also creates an index? A) CHECK (order_id IS UNIQUE) B) UNIQUE (order_id) C) PRIMARY KEY (order_id)
D) EXCLUDE USING gist (order_id WITH = ) Answer: B Explanation: The UNIQUE constraint enforces distinct values and automatically creates a B‑tree index. Question 18. A foreign key constraint references which of the following? A) A CHECK expression on the same table B) A primary key or unique constraint on another table C) An index on the same column D) A trigger function Answer: B Explanation: A foreign key must reference a candidate key (primary key or unique) of the referenced table. Question 19. Which index type is the default in PostgreSQL and works well for equality and range queries? A) GIN B) GiST C) B‑tree D) BRIN Answer: C Explanation: B‑tree is the default index type, supporting equality, inequality, and ordering operations.
B) TRUNCATE TABLE orders; C) DROP TABLE orders; D) VACUUM FULL orders; Answer: B Explanation: TRUNCATE quickly removes all rows and records only the truncation in the WAL, not each row delete. Question 23. Which join returns all rows from the left table and matching rows from the right table, filling NULLs when there is no match? A) INNER JOIN B) LEFT OUTER JOIN C) RIGHT OUTER JOIN D) FULL OUTER JOIN Answer: B Explanation: LEFT OUTER JOIN preserves all rows from the left side and pads with NULLs for non‑matching right rows. Question 24. Which aggregate function returns the number of rows for each group? A) SUM() B) AVG() C) COUNT() D) MAX()
Answer: C Explanation: COUNT aggregates the number of input rows (or non‑NULL values) per group. Question 25. In a GROUP BY query, which clause filters groups after aggregation? A) WHERE B) HAVING C) FILTER D) ORDER BY Answer: B Explanation: HAVING applies conditions to the results of GROUP BY, whereas WHERE filters before grouping. Question 26. Which keyword introduces a Common Table Expression (CTE)? A) WITH B) SELECT C) FROM D) SUBQUERY Answer: A Explanation: WITH defines one or more CTEs that can be referenced in the main query.
D) host all all 0.0.0.0/0 trust Answer: A Explanation: “local” applies to Unix‑domain sockets; “peer” checks the OS user name, and specifying “alice” restricts to that user. Question 30. Which utility creates a logical backup of a single PostgreSQL database? A) pg_basebackup B) pg_dump C) pg_restore D) pg_dumpall Answer: B Explanation: pg_dump produces a logical dump (SQL or custom format) of a single database. Question 31. When performing a point‑in‑time recovery, which file contains the timeline history? A) pg_control B) pg_hba.conf C) pg_xlog/recovery.conf D) pg_wal/timeline.history Answer: D Explanation: timeline.history records timeline switches needed for PITR.
Question 32. Which command starts a base backup suitable for physical replication? A) pg_dumpall --base B) pg_basebackup - D /var/lib/pgsql/backup - F tar - P C) pg_start_backup('label') D) pg_start_physical_backup() Answer: B Explanation: pg_basebackup creates a consistent file‑system level copy of the data directory for streaming replication. Question 33. What is the primary purpose of the autovacuum daemon? A) To create indexes automatically on new tables B) To clean up dead tuples and prevent transaction ID wraparound C) To archive WAL files for PITR D) To monitor query performance in real time Answer: B Explanation: Autovacuum runs VACUUM and ANALYZE automatically, reclaiming space and updating statistics. Question 34. Which command forces a full rebuild of a table, rewriting all rows and reclaiming space? A) VACUUM FULL mytable;
Answer: B Explanation: pg_stat_activity lists each backend’s current query, wait events, and state. Question 37. Which parameter controls how often autovacuum runs a vacuum on a table based on dead tuple count? A) autovacuum_naptime B) autovacuum_vacuum_threshold C) autovacuum_vacuum_scale_factor D) autovacuum_max_workers Answer: C Explanation: autovacuum_vacuum_scale_factor determines the proportion of dead tuples that triggers autovacuum, combined with the threshold. Question 38. In streaming replication, which setting on the primary defines the maximum amount of WAL data that can be sent without acknowledgment? A) wal_level B) max_wal_senders C) wal_keep_segments D) synchronous_commit Answer: B Explanation: max_wal_senders limits the number of concurrent WAL sender processes, affecting how much data can be streamed.
Question 39. Which replication mode guarantees that a transaction is not considered committed until the standby has written the WAL record? A) Asynchronous replication B) Synchronous replication C) Logical replication D) Cascading replication Answer: B Explanation: In synchronous replication, the primary waits for acknowledgment from at least one synchronous standby before confirming commit. Question 40. To promote a standby server to become the new primary, which command is used? A) SELECT pg_promote(); B) pg_ctl promote - D /var/lib/pgsql/data C) ALTER STANDBY PROMOTE; D) RESTART SERVER; Answer: B Explanation: pg_ctl promote instructs the standby to stop replaying WAL and become read‑write. Question 41. Which PostgreSQL data type can store an arbitrary precision numeric value?
D) Whether the role can inherit system catalogs Answer: A Explanation: INHERIT determines if a role automatically receives privileges granted to roles it is a member of. Question 44. Which function returns the current transaction ID? A) txid_current() B) transaction_id() C) current_xid() D) pg_xact_id() Answer: A Explanation: txid_current() yields the XID of the current transaction. Question 45. What is the main risk if transaction ID wraparound is not prevented? A) Loss of table definitions B) Corruption of indexes only C) Visibility of old rows becomes incorrect, leading to data loss D) Server will refuse new connections Answer: C Explanation: When XIDs wrap around, old rows may appear invisible, causing data inconsistency or loss.
Question 46. Which parameter sets the level of information written to the server log? A) log_min_error_statement B) log_destination C) log_line_prefix D) logging_collector Answer: A Explanation: log_min_error_statement controls the minimum severity of statements that are logged. Question 47. In pg_dump, which option produces a plain‑text SQL script? A) - Fc B) - Ft C) - Fp D) - Fd Answer: C Explanation: - Fp (or default) creates a plain SQL dump file. Question 48. Which command restores a database from a custom‑format dump created by pg_dump? A) psql - f dump.sql dbname