




























































































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 process is responsible for writing the write‑ahead log (WAL) to disk? A) postmaster B) walwriter C) autovacuum launcher D) checkpointer Answer: B Explanation: The walwriter process continuously flushes WAL buffers to the WAL files, ensuring durability. Question 2. In PostgreSQL, what does the term “cluster” refer to? A) A group of tables that share the same primary key B) The entire collection of databases managed by a single server instance C) A set of indexes built on a table D) A replication group of standby servers Answer: B Explanation: A PostgreSQL cluster is the directory containing data for all databases managed by one server instance. Question 3. Which command initializes a new PostgreSQL data directory with UTF‑8 encoding and German locale? A) createdb – E UTF8 – l de_DE B) initdb – encoding=UTF8 – locale=de_DE.UTF- 8
C) pg_ctl init – E UTF8 – locale=de_DE D) psql – initdb – E UTF8 – locale=de_DE Answer: B Explanation: initdb creates the data directory; the –encoding and –locale options set character encoding and locale. Question 4. What is the default isolation level in PostgreSQL? A) READ UNCOMMITTED B) READ COMMITTED C) REPEATABLE READ D) SERIALIZABLE Answer: B Explanation: PostgreSQL’s default transaction isolation level is READ COMMITTED, which provides a fresh snapshot at each statement. Question 5. Which of the following best describes MVCC in PostgreSQL? A) It locks entire tables for every write operation. B) It stores multiple versions of a row to allow concurrent reads. C) It uses row‑level exclusive locks for all transactions. D) It disables transaction rollbacks. Answer: B
A) CREATE SCHEMA sales AUTHORIZATION manager; B) CREATE SCHEMA manager.sales; C) CREATE SCHEMA sales OWNER manager; D) ALTER SCHEMA sales OWNER TO manager; Answer: A Explanation: CREATE SCHEMA … AUTHORIZATION sets the owner of the new schema. Question 9. Which data type should be used to store a universally unique identifier (UUID) in PostgreSQL? A) TEXT B) UUID C) VARCHAR(36) D) BYTEA Answer: B Explanation: PostgreSQL provides a native uuid type that stores 128‑bit identifiers efficiently. Question 10. What does the “SERIAL” pseudo‑type actually create? A) A BIGINT column with a default value of 0 B) An integer column with a CHECK constraint ensuring uniqueness C) An integer column with a sequence and a NOT NULL default
D) A text column that automatically increments Answer: C Explanation: SERIAL defines an integer column, creates a sequence, and sets the column’s default to nextval of that sequence. Question 11. Which constraint ensures that a column cannot contain duplicate values across rows? A) PRIMARY KEY B) NOT NULL C) UNIQUE D) CHECK Answer: C Explanation: The UNIQUE constraint enforces distinct values for the specified column(s). Question 12. If a foreign key is defined with “ON DELETE SET NULL”, what happens when the referenced row is deleted? A) The delete is rejected. B) All referencing rows are also deleted. C) The referencing column values become NULL. D) The foreign key column is set to its default value. Answer: C
Question 15. Which join type returns all rows from the left table and matching rows from the right table, inserting NULLs when there is no match? A) INNER JOIN B) LEFT OUTER JOIN C) RIGHT OUTER JOIN D) FULL OUTER JOIN Answer: B Explanation: A LEFT OUTER JOIN preserves all rows from the left side, filling NULLs for non‑matching right‑side rows. Question 16. What does the PostgreSQL function array_agg(column) do? A) Returns the sum of numeric values in the column. B) Concatenates all values into a single string. C) Aggregates column values into an array. D) Counts the number of distinct values. Answer: C Explanation: array_agg collects input values into a PostgreSQL array, preserving order when used with ORDER BY. Question 17. Which system catalog view provides information about currently running backend processes? A) pg_stat_user_tables B) pg_locks
C) pg_stat_activity D) pg_database Answer: C Explanation: pg_stat_activity shows one row per backend, including query text, state, and connection details. Question 18. The command pg_dump - Fc mydb > mydb.dump creates a backup in which format? A) Plain SQL script B) Custom format (compressed) C) Directory format D) Tar archive Answer: B Explanation: The -Fc flag tells pg_dump to produce a custom, non‑plain format that is compressed and suitable for selective restores. Question 19. Which PostgreSQL configuration parameter controls the maximum number of concurrent connections? A) max_connections B) max_clients C) connection_limit D) max_sessions Answer: A
Question 22. How can you make a role inherit the privileges of another role without granting them explicitly? A) CREATE ROLE child INHERIT parent; B) GRANT parent TO child; C) ALTER ROLE child SET ROLE parent; D) REVOKE ALL FROM child; Answer: B Explanation: GRANT role_name TO other_role adds the granted role to the member’s role list, and with INHERIT (default) the privileges are automatically available. Question 23. Which clause must be placed after GROUP BY to filter aggregated results? A) WHERE B) HAVING C) FILTER D) QUALIFY Answer: B Explanation: HAVING evaluates conditions on aggregated values after the GROUP BY step. Question 24. What does the REINDEX command do? A) Rewrites a table to remove dead tuples.
B) Recreates an index to eliminate corruption or bloat. C) Updates statistics for the query planner. D) Changes the index type from B‑Tree to GIN. Answer: B Explanation: REINDEX drops and rebuilds the specified index, useful when an index becomes corrupted or excessively bloated. Question 25. Which PostgreSQL data type is best suited for storing semi‑structured JSON documents with indexing support? A) JSON B) TEXT C) JSONB D) XML Answer: C Explanation: jsonb stores JSON in a binary format that allows indexing (GIN, BTREE) and efficient query operations. Question 26. In a CREATE TABLE statement, which clause defines a column that automatically increments for each new row? A) GENERATED ALWAYS AS IDENTITY B) AUTO_INCREMENT C) SERIAL PRIMARY KEY D) SEQUENCE DEFAULT NEXTVAL
Question 29. Which system function returns the current transaction ID? A) txid_current() B) pg_current_xact_id() C) current_transaction() D) xid_current() Answer: A Explanation: txid_current() returns the 64‑bit transaction identifier of the current transaction. Question 30. How can you create a materialized view that is refreshed automatically every hour? A) CREATE MATERIALIZED VIEW mymv AS SELECT … WITH REFRESH EVERY 1 HOUR; B) CREATE MATERIALIZED VIEW mymv AS SELECT …; CREATE EVENT mymv_refresh ON SCHEDULE EVERY 1 HOUR; C) CREATE MATERIALIZED VIEW mymv AS SELECT …; CREATE EXTENSION pg_cron; SELECT cron.schedule('hourly', 'REFRESH MATERIALIZED VIEW mymv'); D) Materialized views cannot be refreshed automatically. Answer: C Explanation: PostgreSQL does not have built‑in periodic refresh; you can use extensions like pg_cron to schedule REFRESH MATERIALIZED VIEW. Question 31. Which of the following is NOT a valid PostgreSQL index type?
A) B‑Tree B) GIN C) R‑Tree D) Hash Answer: C Explanation: PostgreSQL supports B‑Tree, GIN, GiST, SP‑GiST, BRIN, and Hash, but not an R‑Tree index type. Question 32. What does the pg_stat_user_indexes view report? A) Size of each index on disk. B) Number of index scans and tuples fetched per index. C) List of indexes that are currently locked. D) Execution time of each index creation. Answer: B Explanation: pg_stat_user_indexes provides per‑index statistics such as idx_scan, idx_tup_read, and idx_tup_fetch. Question 33. Which statement correctly adds a CHECK constraint to ensure column “age” is non‑negative? A) ALTER TABLE persons ADD CONSTRAINT age_nonneg CHECK (age >= 0); B) ALTER TABLE persons MODIFY age CHECK (age >= 0); C) ALTER TABLE persons ADD CHECK (age >= 0) CONSTRAINT age_nonneg;
Question 36. Which command creates a logical replication slot named “slot1”? A) SELECT * FROM pg_create_logical_replication_slot('slot1', 'pgoutput'); B) CREATE REPLICATION SLOT slot1 LOGICAL pgoutput; C) SELECT pg_create_logical_replication_slot('slot1', 'pgoutput'); D) ALTER SYSTEM SET replication_slot = 'slot1'; Answer: C Explanation: The function pg_create_logical_replication_slot(name, output_plugin) creates a logical slot. Question 37. How does PostgreSQL prevent transaction ID wraparound? A) By resetting XIDs to zero every day. B) By using 128‑bit transaction IDs. C) By forcing a vacuum of all databases before XID exhaustion. D) By automatically converting XIDs to UUIDs. Answer: C Explanation: Autovacuum performs “anti‑wraparound” vacuums to freeze old XIDs, avoiding wraparound. Question 38. Which clause in CREATE TABLE defines a table‑level constraint that enforces uniqueness across two columns? A) UNIQUE (col1, col2)
B) PRIMARY KEY (col1, col2) C) CHECK (col1 <> col2) D) EXCLUDE USING gist (col1 WITH =, col2 WITH =) Answer: A Explanation: A table‑level UNIQUE (col1, col2) ensures the combination of the two columns is unique. Question 39. What does the \timing meta‑command in psql do? A) Shows the current server time. B) Enables display of execution time for each query. C) Sets the client time zone. D) Measures network latency to the server. Answer: B Explanation: \timing toggles the display of how long each query takes to execute. Question 40. Which of the following statements about the pg_dumpall utility is true? A) It dumps only the schema, not the data. B) It creates a binary backup of the entire cluster. C) It can dump global objects like roles and tablespaces. D) It requires a running server with superuser privileges to restore. Answer: C
A) 0 (log all statements) B) - 1 (disable logging) C) 1000 (log statements >1s) D) 500 (log statements >0.5s) Answer: B Explanation: The default -1 disables logging of statement durations. Question 44. Which of the following best describes a “partial index”? A) An index that only stores a subset of columns. B) An index built on a table partition. C) An index that includes rows satisfying a WHERE clause. D) An index that is created automatically for primary keys. Answer: C Explanation: A partial index includes only rows that meet the specified predicate, reducing size and maintenance cost. Question 45. In PostgreSQL, which function returns the current database name? A) current_db() B) pg_database_name() C) current_database() D) db_name()
Answer: C Explanation: current_database() returns the name of the database the session is connected to. Question 46. Which clause is required to use a column alias in the ORDER BY clause of the same SELECT? A) ORDER BY 1 B) ORDER BY column_alias C) ORDER BY (SELECT column_alias) D) No special clause; alias can be used directly. Answer: D Explanation: In PostgreSQL, column aliases defined in the SELECT list are visible to ORDER BY and can be referenced directly. Question 47. What does the pg_stat_activity column “state_change” indicate? A) Time when the backend process started. B) Timestamp of the last state transition for the backend. C) Duration of the current query execution. D) Size of the result set returned. Answer: B Explanation: state_change records the time of the most recent change in the backend’s state (e.g., from idle to active).