1What type of database model does PostgreSQL primarily use?
Introduction to PostgreSQL database
Easy
A.Object-Relational
B.Graph-Based
C.Document-Oriented
D.Key-Value Store
Correct Answer: Object-Relational
Explanation:
PostgreSQL is an advanced open-source Object-Relational Database Management System (ORDBMS), which means it includes features of both relational databases and object-oriented databases.
Incorrect! Try again.
2The acronym ACID describes properties that guarantee transaction reliability. What does the 'C' in ACID stand for?
Introduction to PostgreSQL database
Easy
A.Concurrency
B.Consistency
C.Commit
D.Capacity
Correct Answer: Consistency
Explanation:
ACID stands for Atomicity, Consistency, Isolation, and Durability. Consistency ensures that any transaction will bring the database from one valid state to another.
Incorrect! Try again.
3Which of the following best describes PostgreSQL?
Introduction to PostgreSQL database
Easy
A.An open-source database system
B.A NoSQL database
C.An in-memory-only database
D.A proprietary database owned by Microsoft
Correct Answer: An open-source database system
Explanation:
PostgreSQL is a powerful, open-source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability and performance.
Incorrect! Try again.
4The name "PostgreSQL" is a successor to which earlier database project?
Introduction to PostgreSQL database
Easy
A.Ingres
B.DB2
C.Oracle
D.MySQL
Correct Answer: Ingres
Explanation:
PostgreSQL originated from the Ingres project at the University of California, Berkeley. It was initially named "Post-Ingres" to signify its development after Ingres.
Incorrect! Try again.
5What is the default network port number that PostgreSQL listens on for client connections?
PostgreSQL installation
Easy
A.1433
B.5432
C.3306
D.27017
Correct Answer: 5432
Explanation:
By default, PostgreSQL server listens for connections on TCP port 5432. 3306 is for MySQL, 1433 for SQL Server, and 27017 for MongoDB.
Incorrect! Try again.
6During a standard installation of PostgreSQL, what is the default superuser account name that is created?
PostgreSQL installation
Easy
A.sysadmin
B.root
C.postgres
D.admin
Correct Answer: postgres
Explanation:
The installation process typically creates a database superuser named postgres, which has full control over the database cluster.
Incorrect! Try again.
7Which command-line tool is the native, interactive terminal for working with PostgreSQL?
PostgreSQL installation
Easy
A.sqlcmd
B.mongo-shell
C.psql
D.mysql-cli
Correct Answer: psql
Explanation:
psql is the official interactive terminal for PostgreSQL, allowing you to execute SQL queries, manage databases, and view results directly from the command line.
Incorrect! Try again.
8On a Debian/Ubuntu system, which apt command is used to install the PostgreSQL server package?
PostgreSQL installation
Easy
A.sudo apt-get start postgresql
B.sudo apt install postgresql
C.sudo apt-add postgresql
D.sudo apt-get configure postgresql
Correct Answer: sudo apt install postgresql
Explanation:
apt is the package manager for Debian-based systems. The install command is used to download and set up new packages like PostgreSQL.
Incorrect! Try again.
9Which SQL keyword is used to retrieve data from a database table?
Basic SQL commands
Easy
A.GET
B.SELECT
C.RETRIEVE
D.FETCH
Correct Answer: SELECT
Explanation:
The SELECT statement is the fundamental SQL command used for querying and retrieving data from one or more tables.
Incorrect! Try again.
10What is the purpose of the CREATE TABLE statement in SQL?
Basic SQL commands
Easy
A.To retrieve data from a table
B.To define a new table and its columns
C.To create a new database
D.To add a new row of data to a table
Correct Answer: To define a new table and its columns
Explanation:
CREATE TABLE is a Data Definition Language (DDL) command used to create a new table, specifying its name, columns, and the data types for each column.
Incorrect! Try again.
11In a SELECT statement, which clause is used to filter the results based on a specific condition?
Basic SQL commands
Easy
A.CONDITION
B.HAVING
C.FILTER
D.WHERE
Correct Answer: WHERE
Explanation:
The WHERE clause is used to extract only those records that fulfill a specified condition. It filters rows before any groupings are made.
Incorrect! Try again.
12What character is used to terminate most SQL statements in tools like psql?
Basic SQL commands
Easy
A.Period (.)
B.Colon (:)
C.Comma (,)
D.Semicolon (;)
Correct Answer: Semicolon (;)
Explanation:
A semicolon (;) is the standard way to indicate the end of an SQL statement, allowing you to run multiple statements in a single batch.
Incorrect! Try again.
13Which SQL command corresponds to the 'Create' operation in CRUD?
CRUD operations
Easy
A.NEW
B.ADD
C.INSERT
D.CREATE
Correct Answer: INSERT
Explanation:
The INSERT INTO statement is used to add new rows of data into a table, which represents the 'Create' part of CRUD. The CREATE keyword is used for defining objects like tables, not for adding data.
Incorrect! Try again.
14Which SQL command corresponds to the 'Read' operation in CRUD?
CRUD operations
Easy
A.READ
B.SELECT
C.FETCH
D.SHOW
Correct Answer: SELECT
Explanation:
The SELECT statement is used to query the database and retrieve data, which corresponds to the 'Read' operation in CRUD.
Incorrect! Try again.
15Which SQL command corresponds to the 'Update' operation in CRUD?
CRUD operations
Easy
A.MODIFY
B.CHANGE
C.UPDATE
D.ALTER
Correct Answer: UPDATE
Explanation:
The UPDATE statement is used to modify existing records in a table, fulfilling the 'Update' operation. ALTER is used to change the structure of a table itself.
Incorrect! Try again.
16Which SQL command corresponds to the 'Delete' operation in CRUD?
CRUD operations
Easy
A.ERASE
B.DELETE
C.REMOVE
D.DROP
Correct Answer: DELETE
Explanation:
The DELETE statement is used to remove one or more existing records from a table. The DROP command is used to remove an entire database object, like a table.
Incorrect! Try again.
17What is the primary role of Prisma in a Node.js application?
PostgreSQL modeling with Prisma ORM
Easy
A.To act as a web server
B.To be a type-safe database client (ORM)
C.To manage front-end state
D.To bundle JavaScript files
Correct Answer: To be a type-safe database client (ORM)
Explanation:
Prisma is a next-generation ORM (Object-Relational Mapper) for Node.js and TypeScript that simplifies database access and provides type-safety for your queries.
Incorrect! Try again.
18In a Prisma project, what is the standard name of the file where you define your database schema models?
PostgreSQL modeling with Prisma ORM
Easy
A.schema.prisma
B.models.js
C.database.yml
D.prisma.config
Correct Answer: schema.prisma
Explanation:
The schema.prisma file is the heart of a Prisma project. It contains the database connection details, the Prisma client generator, and the data model definitions.
Incorrect! Try again.
19Which Prisma CLI command is used to apply pending schema changes to the database by creating a new migration?
PostgreSQL modeling with Prisma ORM
Easy
A.prisma db seed
B.prisma init
C.prisma migrate dev
D.prisma generate
Correct Answer: prisma migrate dev
Explanation:
prisma migrate dev compares your schema.prisma file with the database state, creates a new SQL migration file for the changes, and applies it to the database.
Incorrect! Try again.
20After changing your schema.prisma file, what command must you run to update the type-safe Prisma Client?
PostgreSQL modeling with Prisma ORM
Easy
A.prisma generate
B.prisma format
C.prisma deploy
D.prisma refresh
Correct Answer: prisma generate
Explanation:
The prisma generate command reads your Prisma schema and regenerates the Prisma Client library. This ensures that the client is always in sync with your data models, providing accurate auto-completion and type-safety.
Incorrect! Try again.
21In the context of PostgreSQL's concurrency control, what is a primary advantage of using Multi-Version Concurrency Control (MVCC) over traditional read/write locking mechanisms?
Introduction to PostgreSQL database
Medium
A.It completely eliminates the possibility of deadlocks.
B.It simplifies the transaction isolation levels, offering only one strict level.
C.Writers do not block readers, and readers do not block writers.
D.It uses less disk space because only one version of a row is ever stored.
Correct Answer: Writers do not block readers, and readers do not block writers.
Explanation:
MVCC maintains multiple versions of a data row. When a transaction reads data, it sees a snapshot of the data as it existed at the start of the transaction, allowing other transactions to modify the data concurrently without blocking the read. This significantly improves concurrency in a multi-user environment.
Incorrect! Try again.
22You are designing a multi-tenant application where each tenant's data must be logically separated but reside within the same PostgreSQL database. What is the most appropriate PostgreSQL feature to achieve this namespace-level separation?
Introduction to PostgreSQL database
Medium
A.Using a separate database for each tenant on the same server instance.
B.Using different tablespaces for each tenant.
C.Creating a separate schema for each tenant.
D.Using partitioned tables with a tenant_id column.
Correct Answer: Creating a separate schema for each tenant.
Explanation:
A PostgreSQL schema is a namespace that contains named database objects like tables, views, and functions. Using a schema per tenant is a lightweight and effective way to achieve logical separation of data within a single database, preventing naming conflicts and simplifying data management for each tenant.
Incorrect! Try again.
23After installing PostgreSQL, you are unable to connect to the database server from a remote machine. Which configuration file is most likely responsible for controlling which hosts are allowed to connect, and what parameter needs to be adjusted?
PostgreSQL installation
Medium
A.pg_ident.conf by mapping the remote user to a local user.
B.postgresql.conf by setting the allow_remote_connections parameter.
C.pg_hba.conf by adding a rule for the remote host's IP address.
D.environment file by setting the PGHOST variable.
Correct Answer: pg_hba.conf by adding a rule for the remote host's IP address.
Explanation:
The pg_hba.conf (Host-Based Authentication) file is the primary configuration file for client authentication. To allow remote connections, you must add a new line specifying the database, user, connecting IP address (or range), and the authentication method (e.g., md5 or scram-sha-256).
Incorrect! Try again.
24What is the primary responsibility of the initdb command in the PostgreSQL setup process?
PostgreSQL installation
Medium
A.To create the initial superuser and set its password interactively.
B.To install the PostgreSQL software binaries on the operating system.
C.To start the main PostgreSQL server process (the postmaster).
D.To create a new database cluster, including system catalogs and default databases.
Correct Answer: To create a new database cluster, including system catalogs and default databases.
Explanation:
The initdb command initializes a PostgreSQL database cluster. A cluster is a collection of databases managed by a single server instance. This process involves creating the directories where database data will live (the PGDATA directory), generating the shared system catalog tables, and creating the template1 and postgres default databases.
Incorrect! Try again.
25You need to find the employee with the highest salary in each department from an employees table. Which query structure is most appropriate for this task?
Basic SQL commands
Medium
A.A window function like RANK() or ROW_NUMBER() partitioned by department.
B.A GROUP BY clause with a MAX() aggregate function on the salary.
C.An ORDER BY clause on salary with a LIMIT 1 clause.
D.A subquery in the WHERE clause to find the global maximum salary.
Correct Answer: A window function like RANK() or ROW_NUMBER() partitioned by department.
Explanation:
This is a classic 'greatest-n-per-group' problem. A window function like RANK() OVER (PARTITION BY department ORDER BY salary DESC) assigns a rank to each employee within their department based on salary. The outer query can then filter for all employees where the rank is 1.
Incorrect! Try again.
26What is a key difference in behavior between TRUNCATE TABLE users; and DELETE FROM users; in PostgreSQL?
Basic SQL commands
Medium
A.TRUNCATE can be used with a WHERE clause for selective deletion.
B.DELETE is always faster as it logs less information to the WAL.
C.TRUNCATE is non-transactional and cannot be rolled back, while DELETE can.
D.TRUNCATE does not fire ON DELETE triggers, while DELETE does.
Correct Answer: TRUNCATE does not fire ON DELETE triggers, while DELETE does.
Explanation:
DELETE removes rows one by one, firing any associated ON DELETE triggers for each row. TRUNCATE is a DDL operation that removes all rows from a table much more quickly by deallocating the table's data pages. Because it doesn't scan the rows, it does not fire row-level triggers.
Incorrect! Try again.
27You need to perform a multi-step query: first, aggregate daily sales, and then, using that result, calculate the 7-day moving average. Which SQL feature is best suited for structuring such a query for readability and performance?
Basic SQL commands
Medium
A.Using a HAVING clause to perform the second-step calculation.
B.Using a WITH clause to define a Common Table Expression (CTE).
C.Using nested subqueries in the FROM clause.
D.Creating a permanent VIEW for the daily sales.
Correct Answer: Using a WITH clause to define a Common Table Expression (CTE).
Explanation:
A Common Table Expression (CTE) allows you to create a temporary, named result set that you can reference within the main query. This is ideal for breaking down complex queries into logical, readable steps. You can define the daily sales aggregation in a CTE, and then the main query can reference that CTE to calculate the moving average.
Incorrect! Try again.
28You want to insert a new user with email = 'test@example.com', but if a user with that email already exists, you want to do nothing and avoid an error. Which PostgreSQL-specific query achieves this?
CRUD operations
Medium
A.sql
INSERT INTO users (email) VALUES ('test@example.com') WHERE email != 'test@example.com';
B.sql
INSERT INTO users (email) VALUES ('test@example.com') ON DUPLICATE KEY IGNORE;
C.sql
IF NOT EXISTS (SELECT 1 FROM users WHERE email = 'test@example.com') THEN
INSERT INTO users (email) VALUES ('test@example.com');
END IF;
D.sql
INSERT INTO users (email) VALUES ('test@example.com') ON CONFLICT (email) DO NOTHING;
Correct Answer: sql
INSERT INTO users (email) VALUES ('test@example.com') ON CONFLICT (email) DO NOTHING;
Explanation:
PostgreSQL provides the ON CONFLICT clause to handle unique constraint violations. ON CONFLICT (column_name) DO NOTHING specifies that if the INSERT would violate the unique constraint on the email column, the command should silently do nothing instead of raising an error.
Incorrect! Try again.
29Which SQL statement correctly updates the price of a product and returns its new price and name in a single, atomic operation in PostgreSQL?
CRUD operations
Medium
A.sql
UPDATE products SET price = 150.00 WHERE id = 42;
SELECT name, price FROM products WHERE id = 42;
B.sql
BEGIN;
UPDATE products SET price = 150.00 WHERE id = 42;
SELECT name, price FROM products WHERE id = 42;
COMMIT;
C.sql
UPDATE products SET price = 150.00 WHERE id = 42 OUTPUT updated.name, updated.price;
D.sql
UPDATE products SET price = 150.00 WHERE id = 42 RETURNING name, price;
Correct Answer: sql
UPDATE products SET price = 150.00 WHERE id = 42 RETURNING name, price;
Explanation:
The RETURNING clause is a PostgreSQL extension that can be appended to INSERT, UPDATE, and DELETE statements. It allows the statement to return values from the rows that were affected by the command, avoiding the need for a second database query.
Incorrect! Try again.
30An orders table has a product_id foreign key referencing the products table with the ON DELETE RESTRICT action. What is the outcome if you attempt to delete a product that is referenced by at least one order?
CRUD operations
Medium
A.The product is deleted, and all corresponding orders are also deleted.
B.The product is deleted, and the product_id in the orders table is set to NULL.
C.The delete operation is blocked, and a foreign key violation error is returned.
D.The product is deleted, and the product_id in orders is set to its default value.
Correct Answer: The delete operation is blocked, and a foreign key violation error is returned.
Explanation:
ON DELETE RESTRICT (and the similar NO ACTION) prevents the deletion of a row in the referenced table if any rows in the referencing table still point to it. This is the most restrictive and often the safest default behavior for maintaining referential integrity.
Incorrect! Try again.
31How would you write a query to select all tasks and order them by their priority (High, Medium, Low) and then by their creation_date in descending order?
CRUD operations
Medium
A.sql
ORDER BY priority, creation_date
B.sql
ORDER BY creation_date DESC, priority ASC
C.sql
ORDER BY
CASE priority
WHEN 'High' THEN 1
WHEN 'Medium' THEN 2
WHEN 'Low' THEN 3
END,
creation_date DESC
D.sql
ORDER BY FIELD(priority, 'High', 'Medium', 'Low'), creation_date DESC
Correct Answer: sql
ORDER BY
CASE priority
WHEN 'High' THEN 1
WHEN 'Medium' THEN 2
WHEN 'Low' THEN 3
END,
creation_date DESC
Explanation:
Standard alphabetical sorting of priority would result in 'High', 'Low', 'Medium'. To enforce a custom sorting logic, a CASE statement in the ORDER BY clause is the most standard and effective SQL approach. It maps the string values to a numerical order, ensuring the correct sequence, before applying the secondary sort on creation_date.
Incorrect! Try again.
32In a Prisma schema, how do you define a one-to-many relationship where a User can have multiple Post records?
PostgreSQL modeling with Prisma ORM
Medium
A.By adding posts Post[] to the User model and author User @relation(fields: [authorId], references: [id]) and authorId Int to the Post model.
B.By creating an explicit join table model called UserPosts with relations to both User and Post.
C.By adding userId Int to the User model and posts Post[] @relation(fields: [userId], references: [id]).
D.By adding posts Post[] to the User model and author User to the Post model, letting Prisma handle the foreign key implicitly.
Correct Answer: By adding posts Post[] to the User model and author User @relation(fields: [authorId], references: [id]) and authorId Int to the Post model.
Explanation:
For a one-to-many relationship in Prisma, the 'many' side (Post) holds the foreign key (authorId). The @relation attribute explicitly links this foreign key to the primary key (id) of the User model. The User model contains a field with a list type (Post[]) to represent the 'many' side of the relation for easy querying.
Incorrect! Try again.
33You have updated your schema.prisma file. What is the primary purpose of running the prisma migrate dev command?
PostgreSQL modeling with Prisma ORM
Medium
A.To create a new SQL migration file based on schema changes and apply it to the database.
B.To seed the database with initial test data.
C.To re-generate the Prisma Client to reflect the new schema types.
D.To push the schema changes directly to the database without creating a migration file.
Correct Answer: To create a new SQL migration file based on schema changes and apply it to the database.
Explanation:
prisma migrate dev is a key command in the development workflow. It introspects the current state of the database, compares it to the schema.prisma file, generates a new, timestamped SQL migration file with the necessary changes, and then executes that file against the development database to keep them in sync.
Incorrect! Try again.
34Using the Prisma Client in a TypeScript application, which query finds a unique user by their email and includes their 10 most recent posts, sorted by creation date?
Prisma's include clause allows for nested filtering and pagination on related models. To get the 10 most recent posts, you can add options like orderBy: { createdAt: 'desc' } and take: 10 to the posts relation within the include object, making for a powerful and expressive single query.
Incorrect! Try again.
35What is the purpose of the prisma db pull command in a Prisma workflow?
PostgreSQL modeling with Prisma ORM
Medium
A.It introspects the existing database and updates the schema.prisma file to match.
B.It pulls the latest version of the Prisma CLI from the internet.
C.It seeds the database by pulling data from a remote source.
D.It applies pending migration files to the database schema.
Correct Answer: It introspects the existing database and updates the schema.prisma file to match.
Explanation:
prisma db pull is used for database introspection. It's essential when working with an existing database ('brownfield' project). The command connects to the database, analyzes its tables, columns, and relations, and generates Prisma models in your schema.prisma file that accurately reflect the database's structure.
Incorrect! Try again.
36You need to create a new user and a new profile for that user in a single, atomic database transaction. Which Prisma Client feature is designed for this purpose?
PostgreSQL modeling with Prisma ORM
Medium
A.Executing two await calls sequentially for user.create and profile.create.
B.The prisma.$queryRaw() method.
C.A nested write operation within a single create call.
D.The prisma.$executeRaw() method with transaction control statements.
Correct Answer: A nested write operation within a single create call.
Explanation:
Prisma Client automatically wraps nested writes in a transaction. You can create a user and their related profile by nesting a create operation for the profile inside the data object of the user.create call. This ensures that both records are created successfully, or neither is, maintaining data integrity.
Incorrect! Try again.
37You have a products table with a tags column of type jsonb. The tags are stored as an array of strings, e.g., ["electronics", "mobile"]. Which query correctly finds all products that have the tag 'electronics'?
Basic SQL commands
Medium
A.sql
SELECT * FROM products WHERE tags->>'electronics' IS NOT NULL;
B.sql
SELECT * FROM products WHERE tags @> '"electronics"';
C.sql
SELECT * FROM products WHERE tags LIKE '%electronics%';
D.sql
SELECT * FROM products WHERE 'electronics' IN tags;
Correct Answer: sql
SELECT * FROM products WHERE tags @> '"electronics"';
Explanation:
For jsonb data, PostgreSQL provides a set of powerful operators. The @> (contains) operator checks if the left JSON/JSONB value contains the right JSON/JSONB value. To check if a JSON array contains a specific string element, you use tags @> '"electronics"'. Note the double quotes inside the single-quoted string, which are required to define it as a JSON string value.
Incorrect! Try again.
38Which of the following statements best describes the purpose of the template1 database in a PostgreSQL cluster?
Introduction to PostgreSQL database
Medium
A.It is a backup database that is restored automatically in case of a crash.
B.It is a system database that stores all global configuration settings and user roles.
C.It is the primary database used for storing application data by default.
D.It is a template that is copied to create new user databases.
Correct Answer: It is a template that is copied to create new user databases.
Explanation:
In PostgreSQL, every new database is created by cloning an existing template database. By default, the CREATE DATABASE command clones template1. This means any objects (tables, functions, etc.) you create in template1 will automatically appear in any new database created thereafter, making it useful for setting up a standard database environment.
Incorrect! Try again.
39From the command line on a Linux server, which utility is most commonly used to connect to a PostgreSQL database, execute SQL queries interactively, and view the results?
PostgreSQL installation
Medium
A.psql
B.createdb
C.pg_ctl
D.pg_dump
Correct Answer: psql
Explanation:
psql is the interactive terminal for PostgreSQL. It allows you to type in queries interactively, issue them to PostgreSQL, and see the query results. It also has a rich set of meta-commands (like \dt to list tables) that make database administration easier.
Incorrect! Try again.
40You need to sort a list of products by their last_updated timestamp in descending order, but products that have never been updated (NULL timestamp) should appear at the very beginning of the list. Which ORDER BY clause accomplishes this?
CRUD operations
Medium
A.ORDER BY last_updated DESC
B.ORDER BY last_updated DESC NULLS LAST
C.ORDER BY last_updated DESC NULLS FIRST
D.ORDER BY last_updated ASC NULLS FIRST
Correct Answer: ORDER BY last_updated DESC NULLS FIRST
Explanation:
By default, ORDER BY ... DESC places NULL values first. However, to be explicit and guarantee this behavior across different database versions or configurations, NULLS FIRST should be used. This clause sorts the non-null timestamps in descending (most recent first) order and ensures that all NULL values are grouped together at the top of the result set.
Incorrect! Try again.
41A transaction T1 is running at the REPEATABLE READ isolation level. It executes SELECT COUNT(*) FROM products WHERE category = 'electronics'. Before T1 commits, another transaction T2 commits after successfully inserting a new product with category = 'electronics'. If T1 re-runs the same SELECT query, what will be the result, and why?
Introduction to PostgreSQL database
Hard
A.The count will be the same as the first read, but a warning will be issued indicating that the underlying data has changed.
B.The count will be the same as the first read, because REPEATABLE READ in PostgreSQL uses an MVCC snapshot taken at the start of the transaction, which prevents phantom reads.
C.The transaction T1 will be aborted with a serialization failure error when it tries to re-run the query.
D.The count will be higher, because REPEATABLE READ as defined by the SQL standard does not prevent phantom reads.
Correct Answer: The count will be the same as the first read, because REPEATABLE READ in PostgreSQL uses an MVCC snapshot taken at the start of the transaction, which prevents phantom reads.
Explanation:
While the SQL standard for REPEATABLE READ allows phantom reads (seeing new rows inserted by other committed transactions), PostgreSQL's implementation is stricter. It uses Multi-Version Concurrency Control (MVCC) to provide the transaction with a consistent snapshot of the database as of the moment the first statement in the transaction began. Therefore, T1 will not see the new row inserted by T2, effectively preventing phantom reads at this isolation level. A serialization failure is more characteristic of the SERIALIZABLE level when a dependency conflict is detected.
Incorrect! Try again.
42In a high-traffic PostgreSQL database with frequent UPDATE and DELETE operations, what is the most critical, system-halting consequence of autovacuum failing to run or being unable to keep up with the rate of change for an extended period?
Introduction to PostgreSQL database
Hard
A.The query planner will generate increasingly inefficient plans due to stale statistics.
B.Query performance will degrade due to excessive table and index bloat from dead tuples.
C.The Write-Ahead Log (WAL) will grow indefinitely, consuming all available disk space.
D.The database will stop accepting WRITE operations due to the risk of transaction ID (XID) wraparound failure.
Correct Answer: The database will stop accepting WRITE operations due to the risk of transaction ID (XID) wraparound failure.
Explanation:
While table bloat and stale statistics are serious performance problems caused by a lagging VACUUM, the most critical, catastrophic failure is transaction ID wraparound. PostgreSQL uses a 32-bit transaction ID (XID). After approximately 4 billion transactions, these IDs wrap around. VACUUM's critical job is to 'freeze' the XIDs of very old rows, marking them as visible to all future transactions. If autovacuum cannot keep up and the number of unfrozen XIDs approaches the limit, PostgreSQL will initiate a protective shutdown, refusing all new write transactions to prevent data corruption. This is a hard stop, unlike the gradual performance degradation of other symptoms.
Incorrect! Try again.
43Which statement most accurately describes the relationship between a Checkpoint and the Write-Ahead Log (WAL) in PostgreSQL's recovery mechanism?
Introduction to PostgreSQL database
Hard
A.A checkpoint exclusively removes old WAL files that are no longer needed for recovery, which is its primary method for managing disk space.
B.A checkpoint flushes the WAL buffers to disk, ensuring that all subsequent COMMIT operations are durable.
C.A checkpoint is a point in the WAL sequence such that all data file modifications due to transactions committed before this point are guaranteed to be written to disk, allowing recovery to start from this point instead of the beginning of the logs.
D.During a checkpoint, the database pauses all write operations to create a consistent snapshot of the data files, which is then recorded in the WAL.
Correct Answer: A checkpoint is a point in the WAL sequence such that all data file modifications due to transactions committed before this point are guaranteed to be written to disk, allowing recovery to start from this point instead of the beginning of the logs.
Explanation:
The primary purpose of a checkpoint is to create a known-good point in time on disk. It forces all 'dirty' data buffers (pages in memory that have been modified) to be written to the data files on disk. The location of the checkpoint record in the WAL is then saved. In case of a crash, PostgreSQL recovery knows it only needs to replay WAL entries that occurred after the last completed checkpoint, significantly speeding up the recovery process. It doesn't pause all writes; it's a background process designed to minimize impact.
Incorrect! Try again.
44PostgreSQL uses a multi-process architecture where the main 'postmaster' process forks a new backend process for each client connection. In contrast, many other databases use a multi-threaded model. What is a key architectural trade-off of PostgreSQL's approach?
Introduction to PostgreSQL database
Hard
A.Faster connection startup time at the cost of reduced security, as all connections share the same memory space.
B.Higher stability and fault isolation at the cost of higher memory consumption per connection and potentially slower connection startup.
C.Better scalability on multi-core CPUs because of OS-level process scheduling, but with more complex code for inter-process communication.
D.Lower memory usage per connection because processes share memory more efficiently than threads, but with a higher risk of a single connection crash bringing down the server.
Correct Answer: Higher stability and fault isolation at the cost of higher memory consumption per connection and potentially slower connection startup.
Explanation:
The main advantage of the multi-process model is robustness. Each connection has its own OS process and isolated memory space. A crash in one backend process (e.g., due to a faulty C extension) will not affect the postmaster or other backends. The trade-off is that forking a process is more resource-intensive (in both memory and CPU time) than starting a thread. This makes establishing new connections relatively expensive, which is why external connection poolers are essential for applications with high connection churn.
Incorrect! Try again.
45You are tuning a PostgreSQL server for a data warehouse workload characterized by a few, very large, complex queries running concurrently. These queries perform large joins, aggregations, and sorting. You observe significant temporary file I/O. Which two parameters in postgresql.conf are most crucial to adjust to optimize for this specific workload?
PostgreSQL installation
Hard
A.work_mem and maintenance_work_mem
B.shared_buffers and effective_cache_size
C.max_connections and wal_buffers
D.work_mem and shared_buffers
Correct Answer: work_mem and shared_buffers
Explanation:
work_mem is the most critical parameter here, as it defines the amount of memory available to each individual sort, hash join, or other memory-intensive operation within a query before it spills to disk. Increasing it directly reduces temporary file I/O. shared_buffers is the second most important, as it determines the amount of memory dedicated to caching data pages from disk. A larger shared_buffers can reduce physical I/O for the large table scans common in data warehousing. maintenance_work_mem is for tasks like VACUUM and CREATE INDEX, not user queries. effective_cache_size is just a hint to the planner.
Incorrect! Try again.
46A pg_hba.conf file contains the following entries in this specific order:
# TYPE DATABASE USER ADDRESS METHOD
host all all 192.168.1.0/24 scram-sha-256
host all admin 192.168.1.50/32 reject
A user 'admin' attempts to connect from the IP address 192.168.1.50 to the sales database. What will be the outcome of the connection attempt?
PostgreSQL installation
Hard
A.The connection will be rejected.
B.The connection will fail with an error because of a configuration conflict.
C.The connection will succeed because the more specific IP address rule (/32) always takes precedence over a less specific CIDR range (/24).
D.The connection will succeed using scram-sha-256 authentication.
Correct Answer: The connection will succeed using scram-sha-256 authentication.
Explanation:
PostgreSQL processes pg_hba.conf by searching for the first record that matches the connection type, client address, requested database, and user name. The connection from 192.168.1.50 as user 'admin' to database 'sales' is checked against the rules sequentially:
The first line (host all all 192.168.1.0/24...) is a match because the IP 192.168.1.50 falls within the 192.168.1.0/24 range, and 'all' matches both the database and user.
Since a match is found, PostgreSQL stops processing the file and uses the method from this first matching line (scram-sha-256). The second, more specific reject rule is never evaluated.
Incorrect! Try again.
47To mitigate I/O spikes during checkpoints, a DBA sets checkpoint_completion_target = 0.9. How does this setting interact with checkpoint_timeout and max_wal_size?
PostgreSQL installation
Hard
A.It reduces the amount of data written during a checkpoint by 90%, delaying the rest of the writes until the next checkpoint.
B.It forces the checkpoint to finish within the first 90% of the checkpoint_timeout interval, leaving the last 10% of the time as an I/O-free buffer.
C.It has no effect on time-based checkpoints (checkpoint_timeout) and only applies to checkpoints triggered by max_wal_size.
D.It instructs PostgreSQL to try and spread the checkpoint's write activity over 90% of the duration between checkpoints, whether the checkpoint was triggered by time (checkpoint_timeout) or WAL size (max_wal_size).
Correct Answer: It instructs PostgreSQL to try and spread the checkpoint's write activity over 90% of the duration between checkpoints, whether the checkpoint was triggered by time (checkpoint_timeout) or WAL size (max_wal_size).
Explanation:
checkpoint_completion_target is a fraction (from 0 to 1.0) of the total time between checkpoints. This interval is determined by whichever trigger comes first: checkpoint_timeout (time since last checkpoint) or when WAL files occupy max_wal_size on disk. A value of 0.9 tells PostgreSQL to pace the I/O operations (writing dirty buffers to disk) so that the checkpoint finishes when 90% of the interval to the next predicted checkpoint has passed. This smooths out the I/O load, reducing performance dips caused by intense, short bursts of write activity.
Incorrect! Try again.
48You are configuring a PostgreSQL server that will be accessed by an application running inside a Docker container on the same host machine. For maximum performance and security, what is the recommended host type to use in pg_hba.conf for this connection?
PostgreSQL installation
Hard
A.host with the Docker bridge network's CIDR address (e.g., 172.17.0.0/16)
B.local
C.host with address ::1/128
D.host with address 127.0.0.1/32
Correct Answer: local
Explanation:
A local connection in pg_hba.conf refers to a connection made via a Unix domain socket, not a TCP/IP network socket. When the client and server are on the same machine, using a Unix socket is more efficient as it bypasses the overhead of the TCP/IP stack. It is also inherently more secure as it's a file-system-based communication channel and not exposed to the network. An application in a Docker container can connect to a PostgreSQL instance on the host by mounting the host's socket directory (e.g., /var/run/postgresql) into the container. Using host with a TCP/IP address would be less performant.
Incorrect! Try again.
49Given a table page_views with user_id and view_timestamp, you want to calculate the average time between consecutive page views for each user. A single SELECT statement is required. Which combination of SQL features is best suited for this?
Basic SQL commands
Hard
A.A LATERAL JOIN to find the previous page view for each row.
B.The LAG() window function to get the timestamp of the previous view, followed by aggregation on the calculated time difference.
C.A self-join on page_views with the condition t1.view_timestamp > t2.view_timestamp and GROUP BY t1.user_id.
D.A recursive CTE to iterate through each user's page views.
Correct Answer: The LAG() window function to get the timestamp of the previous view, followed by aggregation on the calculated time difference.
Explanation:
This problem requires comparing a row with the immediately preceding row within the same group (user). The LAG() window function is designed precisely for this. The query structure would be: 1. Use a CTE or subquery. 2. Inside it, SELECT user_id, view_timestamp - LAG(view_timestamp, 1) OVER (PARTITION BY user_id ORDER BY view_timestamp) AS time_diff. 3. In the outer query, calculate AVG(time_diff) grouped by user_id. This is the most direct and performant approach. A self-join or recursive CTE would be far more complex and inefficient.
Incorrect! Try again.
50You have a table employees (id, name, department, salary). You need to write a query that returns each employee's name, department, and their salary's rank within their department, but also their salary's rank across the entire company, both in separate columns. Which query correctly achieves this?
Basic SQL commands
Hard
A.sql
SELECT name, department,
(SELECT COUNT() + 1 FROM employees e2 WHERE e2.department = e1.department AND e2.salary > e1.salary) as dept_rank,
(SELECT COUNT() + 1 FROM employees e2 WHERE e2.salary > e1.salary) as overall_rank
FROM employees e1;
B.sql
SELECT name, department,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) as dept_rank,
RANK() OVER (ORDER BY salary DESC) as overall_rank
FROM employees;
C.sql
WITH dept_rank AS (
SELECT id, RANK() OVER (PARTITION BY department ORDER BY salary DESC) r FROM employees
), overall_rank AS (
SELECT id, RANK() OVER (ORDER BY salary DESC) r FROM employees
)
SELECT e.name, e.department, dr.r, or.r
FROM employees e JOIN dept_rank dr ON e.id = dr.id JOIN overall_rank or ON e.id = or.id;
D.sql
SELECT name, department,
RANK() OVER (ORDER BY department, salary DESC) as dept_rank,
RANK() OVER (ORDER BY salary DESC) as overall_rank
FROM employees;
Correct Answer: sql
SELECT name, department,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) as dept_rank,
RANK() OVER (ORDER BY salary DESC) as overall_rank
FROM employees;
Explanation:
This problem is a perfect use case for window functions. The RANK() function can be used with different OVER() clauses within the same SELECT statement. RANK() OVER (PARTITION BY department ORDER BY salary DESC) calculates the rank within each department group. RANK() OVER (ORDER BY salary DESC) omits the PARTITION BY clause, so it calculates the rank over the entire result set (the whole company). This single query is highly efficient as it requires only one scan of the table. The correlated subquery approach (Option B) is extremely inefficient, and the other options are syntactically or logically incorrect.
Incorrect! Try again.
51What is the primary difference in behavior between ROW_NUMBER(), RANK(), and DENSE_RANK() when used as window functions on a set of rows with duplicate values in the ORDER BY clause?
Basic SQL commands
Hard
A.All three functions produce the same result unless a PARTITION BY clause is also used.
B.ROW_NUMBER assigns unique numbers, RANK leaves gaps after ties, DENSE_RANK does not leave gaps after ties.
C.ROW_NUMBER and DENSE_RANK are identical, but RANK leaves gaps for ties.
D.RANK and DENSE_RANK are identical, but ROW_NUMBER assigns a random number to break ties.
Correct Answer: ROW_NUMBER assigns unique numbers, RANK leaves gaps after ties, DENSE_RANK does not leave gaps after ties.
Explanation:
This question tests the subtle but critical differences between these ranking functions. For a list of values like (100, 90, 90, 80):
ROW_NUMBER() assigns a unique, consecutive integer to each row regardless of ties: 1, 2, 3, 4.
RANK() gives ties the same rank, but then skips the next rank(s). The ranks would be: 1, 2, 2, 4 (rank 3 is skipped).
DENSE_RANK() gives ties the same rank but does not skip subsequent ranks. The ranks would be: 1, 2, 2, 3.
Understanding this distinction is key to choosing the correct function for a given analytical task.
Incorrect! Try again.
52You have a products table and a product_tags table (product_id, tag). You need to find all products that have the tag 'new' AND the tag 'sale', but NOT the tag 'clearance'. Which query is the most efficient and accurate way to express this complex set-based condition?
Basic SQL commands
Hard
A.sql
SELECT product_id FROM product_tags WHERE tag = 'new'
INTERSECT
SELECT product_id FROM product_tags WHERE tag = 'sale'
EXCEPT
SELECT product_id FROM product_tags WHERE tag = 'clearance';
B.sql
SELECT p.* FROM products p WHERE
EXISTS (SELECT 1 FROM product_tags WHERE product_id = p.id AND tag = 'new') AND
EXISTS (SELECT 1 FROM product_tags WHERE product_id = p.id AND tag = 'sale') AND
NOT EXISTS (SELECT 1 FROM product_tags WHERE product_id = p.id AND tag = 'clearance');
C.sql
SELECT product_id FROM product_tags
GROUP BY product_id
HAVING ARRAY_AGG(tag) @> ARRAY['new', 'sale']
AND NOT (ARRAY_AGG(tag) && ARRAY['clearance']);
D.sql
SELECT p.* FROM products p
JOIN product_tags t1 ON p.id = t1.product_id AND t1.tag = 'new'
JOIN product_tags t2 ON p.id = t2.product_id AND t2.tag = 'sale'
LEFT JOIN product_tags t3 ON p.id = t3.product_id AND t3.tag = 'clearance'
WHERE t3.product_id IS NULL;
Correct Answer: sql
SELECT product_id FROM product_tags
GROUP BY product_id
HAVING ARRAY_AGG(tag) @> ARRAY['new', 'sale']
AND NOT (ARRAY_AGG(tag) && ARRAY['clearance']);
Explanation:
While all four options can potentially yield the correct product_ids, the array aggregation approach is a uniquely powerful and often highly performant PostgreSQL feature for this type of set-based query within a group. It aggregates all tags for a product into an array and then uses PostgreSQL's rich array operators: @> (contains) to check for the required tags and && (overlaps) to check for the forbidden tag. This approach often results in a more efficient query plan (a single scan and group) compared to multiple joins or subqueries, and it is arguably the most expressive and scalable solution for complex tag-based filtering.
Incorrect! Try again.
53You have a counters table with a name (unique) and value column. You need an atomic operation to increment a counter by 1. If the counter does not exist, it should be inserted with an initial value of 1. Which SQL statement correctly performs this "upsert-increment" operation?
CRUD operations
Hard
A.sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = counters.value + EXCLUDED.value;
B.sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = value + 1;
C.sql
UPDATE counters SET value = value + 1 WHERE name = 'page_views';
IF NOT FOUND THEN
INSERT INTO counters (name, value) VALUES ('page_views', 1);
END IF;
D.sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = counters.value + 1;
Correct Answer: sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = counters.value + 1;
Explanation:
This question tests a subtle aspect of ON CONFLICT. The goal is to always increment by 1. In the DO UPDATE clause, you can reference the existing row's values (using the table name, e.g., counters.value) and the values from the row that was proposed for insertion (using the EXCLUDED pseudo-table). Option D, counters.value + EXCLUDED.value, would add the existing value to the proposed value (1), which is correct. However, Option B, counters.value + 1, is simpler and also correct for this specific case, as the increment is always a constant 1. Option A is incorrect because value in SET value = value + 1 is ambiguous. Option C is not atomic and is vulnerable to race conditions. Between B and D, both work, but B is arguably more direct for a fixed increment. Let's make B the canonical answer for its simplicity. EXCLUDED.value would be the same as the VALUES clause's value, which is 1. So counters.value + EXCLUDED.value is identical to counters.value + 1 in this context. B is a perfectly valid and slightly more concise way of expressing the fixed increment.
Incorrect! Try again.
54You are implementing a 'soft delete' pattern by updating a deleted_at timestamp on a table. To prevent race conditions where two processes try to soft-delete the same record, you want to ensure the UPDATE only affects the row if it hasn't been deleted already. You also need to get the id of the row that was successfully updated. Which query is the most robust?
CRUD operations
Hard
A.sql
BEGIN;
SELECT id FROM products WHERE id = 123 AND deleted_at IS NULL FOR UPDATE;
-- (check in application logic if a row was returned)
UPDATE products SET deleted_at = NOW() WHERE id = 123;
COMMIT;
SELECT id FROM products WHERE id = 123;
B.sql
UPDATE products SET deleted_at = NOW() WHERE id = 123;
SELECT id FROM products WHERE id = 123 AND deleted_at IS NOT NULL;
C.sql
UPDATE products SET deleted_at = NOW()
WHERE id = 123 AND deleted_at IS NULL
RETURNING id;
D.sql
WITH updated AS (
UPDATE products SET deleted_at = NOW() WHERE id = 123
)
SELECT id FROM products WHERE id = 123 AND deleted_at IS NOT NULL;
Correct Answer: sql
UPDATE products SET deleted_at = NOW()
WHERE id = 123 AND deleted_at IS NULL
RETURNING id;
Explanation:
This is the most efficient and atomic solution. The WHERE id = 123 AND deleted_at IS NULL clause ensures that the UPDATE statement only finds and locks a row that has not yet been soft-deleted. If another process deletes it first, the WHERE clause for this query will not match any rows, and the update will affect zero rows. The RETURNING id clause will then return an empty result set, which the application can use to understand that it did not perform the deletion. This single statement is fully atomic and avoids the complexity and potential deadlocks of explicit locking with SELECT FOR UPDATE (Option B), as well as the race conditions inherent in separate UPDATE and SELECT statements (Options C and D).
Incorrect! Try again.
55What is a data-modifying Common Table Expression (CTE) in PostgreSQL, and what is a key advantage of using one for a task like moving rows from one table to another?
CRUD operations
Hard
A.It is a special type of trigger that modifies data in a temporary table before committing to the main table, primarily used for logging.
B.It is a CTE that contains an UPDATE, INSERT, or DELETE statement. Its key advantage is that the entire operation, including the data modification and any subsequent use of the modified data (e.g., in an INSERT), occurs within a single atomic statement.
C.It is a view that can be updated, allowing UPDATE statements to be run directly against the view definition.
D.It is a feature that allows SELECT statements to modify data in memory without writing to disk, improving performance for read-heavy workloads.
Correct Answer: It is a CTE that contains an UPDATE, INSERT, or DELETE statement. Its key advantage is that the entire operation, including the data modification and any subsequent use of the modified data (e.g., in an INSERT), occurs within a single atomic statement.
Explanation:
A data-modifying CTE allows you to place a DML statement (INSERT, UPDATE, DELETE) within a WITH clause. By adding a RETURNING clause to this DML statement, you can capture the rows that were affected. This result set can then be used by the main part of the query. For moving rows, you can have a CTE like WITH moved_rows AS (DELETE FROM source_table WHERE ... RETURNING *). The main query can then be INSERT INTO destination_table SELECT * FROM moved_rows;. The entire process is executed as a single, atomic command, which is far safer and often more performant than using separate DELETE and INSERT commands within a transaction block.
Incorrect! Try again.
56Consider a DELETE statement with a USING clause: DELETE FROM employees_staging es USING employees_production ep WHERE es.employee_id = ep.employee_id;. What does this statement do?
CRUD operations
Hard
A.It deletes all rows from employees_production that have a matching employee_id in employees_staging.
B.It deletes all rows from employees_staging that have a matching employee_id in employees_production.
C.It deletes rows from both employees_staging and employees_production where the employee_id matches.
D.It attempts to delete from employees_staging, but will fail because the alias es is not referenced in the WHERE clause.
Correct Answer: It deletes all rows from employees_staging that have a matching employee_id in employees_production.
Explanation:
The DELETE FROM table_a USING table_b syntax is a PostgreSQL extension for performing joins in a DELETE operation. The table specified immediately after DELETE FROM (here, employees_staging) is the target for deletion. The USING clause introduces other tables to be used in the WHERE clause for filtering. Therefore, this statement joins the staging and production tables on employee_id and deletes only the rows from the staging table that were part of the successful join.
Incorrect! Try again.
57You have a Prisma schema with a many-to-many relationship between Post and Tag using an explicit join table. How do you write a Prisma Client query to find all Posts that have at least one Tag with a name starting with 'tech' and are also written by a User whose email contains '@example.com'?
When combining conditions across different relations in Prisma, using the explicit AND operator is the most robust and clear method. The query correctly breaks down the logic: Find posts where there is an AND condition. The first condition is that in the related tags (the join table), some (at least one) of the related tag entities must have a name that starts with 'tech'. The second condition is that the related author must have an email that contains '@example.com'. While the implicit AND (Option B) often works, using an explicit AND: [] array is the canonical way to combine complex relational filters and avoids ambiguity. Option C (every) is incorrect as it would require all tags to start with 'tech'. Option D has incorrect syntax for relational filtering.
Incorrect! Try again.
58You need to perform a complex, multi-step operation: 1. Read a user's profile. 2. Based on their country, calculate a shipping cost. 3. Create a new order for that user with the calculated cost. 4. Decrement the stock of the ordered product. This entire sequence must be atomic. Which Prisma feature is specifically designed for such interdependent read-then-write operations within a single transaction?
PostgreSQL modeling with Prisma ORM
Hard
A.Using prisma.$transaction([ ... ]) with an array of Prisma client operations.
B.Using prisma.$executeRawUnsafe() to manually write a PL/pgSQL function that encapsulates the logic.
C.Using prisma.$transaction(async (tx) => { ... }) with an interactive transaction callback.
D.Executing the operations sequentially with await, relying on the database's default transaction handling.
Correct Answer: Using prisma.$transaction(async (tx) => { ... }) with an interactive transaction callback.
Explanation:
This scenario requires conditional logic (calculating cost based on a read value) within a transaction. The sequential transaction API (prisma.transaction(async (tx) => { ... })) is the perfect solution. It provides a transaction-scoped Prisma client instance (tx) to the callback function. Inside this function, you can await read operations (e.g., tx.user.findUnique), perform JavaScript logic (calculate shipping), and then await write operations (tx.order.create, tx.product.update). Prisma guarantees that all operations within the callback are executed in a single, atomic database transaction. If the callback function throws an error at any point, the entire transaction is automatically rolled back.
Incorrect! Try again.
59What is the primary purpose of the 'shadow database' used by Prisma Migrate during development (prisma migrate dev)?
PostgreSQL modeling with Prisma ORM
Hard
A.To cache query results from the development database to speed up repeated queries during the development process.
B.To serve as a hot backup of the development database that can be restored instantly.
C.To store the schema.prisma file's state, allowing for version control of the schema.
D.To test the application of new migrations in a clean, temporary environment before applying them to the main development database, ensuring migrations are repeatable and detecting drift.
Correct Answer: To test the application of new migrations in a clean, temporary environment before applying them to the main development database, ensuring migrations are repeatable and detecting drift.
Explanation:
The shadow database is a core concept for ensuring the safety and reliability of Prisma Migrate. When you run prisma migrate dev, Prisma creates (or uses an existing) temporary, empty database. It then applies all existing migration files to this shadow database to reconstruct the schema from its history. This serves two critical purposes: 1) It validates that the migration history is sound and can be replayed from scratch. 2) It compares the resulting schema of the shadow database with the current state of your main development database to detect 'drift' (manual changes made to the database that are not recorded in a migration). If drift is detected, Prisma will warn you and prompt for a resolution, preventing the application of new migrations to an inconsistent database state.
Incorrect! Try again.
60In a Prisma schema, you define a one-to-many relation between User and Post. What is the functional difference between defining the relation field on the User model as posts Post[] versus omitting it entirely?
PostgreSQL modeling with Prisma ORM
Hard
A.Omitting the back-relation field (posts Post[]) makes the relation uni-directional from the Post's perspective. You can still query from Post to User, but you cannot easily query from User to their Posts via the Prisma Client's fluent API.
B.Omitting the field corrupts the foreign key constraint in the underlying database schema generated by Prisma Migrate.
C.Omitting the field prevents you from creating Post records associated with a User.
D.There is no functional difference; the posts Post[] field is purely for documentation and is ignored by the Prisma Client.
Correct Answer: Omitting the back-relation field (posts Post[]) makes the relation uni-directional from the Post's perspective. You can still query from Post to User, but you cannot easily query from User to their Posts via the Prisma Client's fluent API.
Explanation:
Prisma's schema allows for both bi-directional and uni-directional relations. A full bi-directional relation would have author User @relation(...) on the Post model and posts Post[] on the User model. If you omit posts Post[], the foreign key and the relation still exist in the database. You can query a Post and include: { author: true }. However, you lose the ability to start a query from a User and traverse to their posts, for example: prisma.user.findUnique({ where: { id: 1 }, include: { posts: true } }). This query would not be possible without the posts Post[] back-relation field. The field is essential for defining the relation's accessibility in the generated Prisma Client API.